Skip to content

Comments

Add web chat server and functional tests for HippocampAI#5

Closed
rexdivakar wants to merge 9 commits intomainfrom
upgrade_1.0
Closed

Add web chat server and functional tests for HippocampAI#5
rexdivakar wants to merge 9 commits intomainfrom
upgrade_1.0

Conversation

@rexdivakar
Copy link
Owner

@rexdivakar rexdivakar commented Oct 19, 2025

This pull request introduces several documentation improvements and workflow enhancements to streamline contributor onboarding, clarify project usage, and ensure robust dependency management and testing practices. The most important changes include the addition of a contributor guide, updates to usage instructions to use module-based invocation, and the introduction of an automated dependency health workflow.

Contributor Experience & Documentation:

  • Added a comprehensive CONTRIBUTING.md guide detailing environment setup, coding standards, pull request process, and issue reporting.
  • Updated README.md, docs/CHAT_INTEGRATION.md, docs/CHAT_README.md, and docs/CONFIGURATION.md to consistently use python -m hippocampai.<module> for running CLI and web chat, and to reference code locations within the src/hippocampai package. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24]

Dependency Management & Testing:

  • Added a .github/workflows/dependency-health.yml workflow to automatically audit dependencies for vulnerabilities and license compliance using pip-audit and liccheck, running weekly and on relevant pull requests.
  • Clarified dependency pinning strategy and testing instructions in README.md, including usage of extras for installing optional groups and documenting the CI testing workflow.

Logging & Configuration:

  • Renamed logging_config.yaml to config/logging_config.yaml and updated logger names to use the hippocampai namespace for consistency. Updated documentation references accordingly. [1] [2] [3]

Changelog & Packaging:

  • Updated docs/CHANGELOG.md to reflect the addition of the contributor guide, standardized timestamps, and improved testing documentation.
  • Updated MANIFEST.in to include HTML files in the source distribution.

These changes collectively improve onboarding, documentation clarity, dependency safety, and package organization for the project.- Implemented a Flask web server for a memory-enhanced chat interface with REST API endpoints for sending messages, retrieving history, managing memories, and session control.

  • Created functional test script to validate HippocampAI installation and basic functionality, including memory creation, configuration loading, and module imports.
  • Added legacy functional tests to ensure core functionalities work without a running Qdrant instance.
  • Updated test retrieval to use UTC for datetime handling.

Summary by Sourcery

Provide Flask-based web chat server and comprehensive test suite for HippocampAI; modernize configuration and timestamp handling; tighten dependency pinning; add CI vulnerability and license audits; and enhance documentation and onboarding resources.

New Features:

  • Implement Flask web chat server with REST API and update CLI entry points to module-based invocation
  • Introduce functional and legacy test scripts to validate installation, memory workflows, and configuration

Enhancements:

  • Migrate configuration to Pydantic v2 Settings with explicit environment variable overrides and reorganize module and logger namespaces under hippocampai
  • Standardize timestamp handling to timezone-aware UTC across all components using new time utility functions
  • Revise dependency management by pinning minor versions with upper bounds, updating dependency definitions, and defining optional extras

Build:

  • Include web UI assets in package distribution via MANIFEST.in

CI:

  • Add dependency-health GitHub Actions workflow using pip-audit and liccheck for automated vulnerability and license compliance checks

Documentation:

  • Add CONTRIBUTING.md and update README, CHANGELOG, and project documentation with improved onboarding, usage, testing, and dependency guidelines

Tests:

  • Add scripts/run-tests.sh helper for consistent local pytest execution

- Implemented a Flask web server for a memory-enhanced chat interface with REST API endpoints for sending messages, retrieving history, managing memories, and session control.
- Created functional test script to validate HippocampAI installation and basic functionality, including memory creation, configuration loading, and module imports.
- Added legacy functional tests to ensure core functionalities work without a running Qdrant instance.
- Updated test retrieval to use UTC for datetime handling.
@sourcery-ai
Copy link

sourcery-ai bot commented Oct 19, 2025

Reviewer's Guide

This PR overhauls project structure and developer workflows by introducing a Flask-based web chat server with functional tests, migrating configuration to Pydantic v2 with helper utilities, enforcing timezone-aware UTC handling, tightening dependency pinning and automated health checks, and standardizing module invocation and documentation across the codebase.

Sequence diagram for web chat server REST API interactions

sequenceDiagram
    participant actor User
    participant WebChatServer
    participant MemoryEnhancedChat
    participant MemoryStore
    participant SessionManager
    User->>WebChatServer: POST /api/chat/send (message)
    WebChatServer->>MemoryEnhancedChat: send_message(user_id, message)
    MemoryEnhancedChat->>MemoryStore: store_message(user_id, message)
    MemoryEnhancedChat->>SessionManager: update_session(user_id, message)
    MemoryEnhancedChat-->>WebChatServer: response
    WebChatServer-->>User: chat response
    User->>WebChatServer: GET /api/chat/history
    WebChatServer->>SessionManager: get_session_history(user_id)
    SessionManager-->>WebChatServer: history
    WebChatServer-->>User: history response
Loading

Class diagram for updated Config and Settings models

classDiagram
    class Config {
        +qdrant_url: str
        +collection_facts: str
        +collection_prefs: str
        +hnsw_m: int
        +ef_construction: int
        +ef_search: int
        +embed_model: str
        +embed_quantized: bool
        +embed_batch_size: int
        +embed_dimension: int
        +reranker_model: str
        +rerank_cache_ttl: int
        +bm25_backend: str
        +llm_provider: str
        +llm_model: str
        +llm_base_url: str
        +allow_cloud: bool
        +top_k_qdrant: int
        +top_k_final: int
        +rrf_k: int
        +weight_sim: float
        +weight_rerank: float
        +weight_recency: float
        +weight_importance: float
        +half_life_prefs: int
        +half_life_facts: int
        +half_life_events: int
        +enable_scheduler: bool
        +decay_cron: str
        +consolidate_cron: str
        +snapshot_cron: str
        +get_weights(): Dict[str, float]
        +get_half_lives(): Dict[str, int]
    }
    class Settings {
        +project_root: Path
        +env_file: str
        +config_file: str
        +_load_env_file(env_file)
        +_load_config_file(config_file)
    }
    Config <|-- Settings
Loading

Class diagram for Memory model with UTC-aware timestamps

classDiagram
    class Memory {
        +id: str
        +user_id: str
        +text: str
        +memory_type: MemoryType
        +category: str
        +importance: float
        +confidence: float
        +tags: List[str]
        +created_at: datetime (UTC)
        +updated_at: datetime (UTC)
        +access_count: int
        +metadata: Dict[str, Any]
    }
    class MemoryType {
        <<enum>>
        PREFERENCE
        FACT
        EVENT
    }
    MemoryType <|-- Memory
Loading

File-Level Changes

Change Details Files
Implemented Flask web chat server and added end-to-end functional tests
  • Added web_chat entry point with package-relative templates
  • Created functional and legacy test scripts validating core features without Qdrant
  • Updated example scripts to exercise CLI and web interfaces
src/hippocampai/web_chat.py
examples/*
tests/*
scripts/run-tests.sh
Refactored configuration to use Pydantic v2 with explicit env var helper
  • Introduced env_field helper wrapping AliasChoices
  • Switched BaseSettings to SettingsConfigDict for .env loading
  • Replaced Field(env=…) definitions with env_field calls
src/hippocampai/config.py
Standardized datetime handling to timezone-aware UTC
  • Added utils/time.py with now_utc, isoformat_utc, parse_iso_datetime
  • Replaced datetime.utcnow()/utcfromtimestamp usages across session_manager, memory_updater, importance_scorer, memory_store, retriever, scoring
  • Updated tests to use timezone-aware comparisons
src/hippocampai/utils/time.py
src/hippocampai/session_manager.py
src/hippocampai/memory_updater.py
src/hippocampai/importance_scorer.py
src/hippocampai/memory_store.py
src/hippocampai/memory_retriever.py
src/hippocampai/utils/scoring.py
tests/test_retrieval.py
Enhanced dependency management with strict pinning, extras, and automated audits
  • Rewrote pyproject.toml and requirements.txt with ≥,< version pins and optional extras for core, dev, test, docs
  • Added GitHub workflow for pip-audit and liccheck
  • Provided liccheck.ini and scripts/run-tests.sh for local consistency
pyproject.toml
requirements.txt
.github/workflows/dependency-health.yml
liccheck.ini
scripts/run-tests.sh
Unified documentation and CLI invocation to module-based commands
  • Replaced direct script calls with python -m hippocampai.* across README and docs
  • Updated import paths from src.* to hippocampai.* in examples and docs
  • Consolidated usage instructions and Quickstart to reflect new package layout
README.md
docs/*
examples/*
Relocated and renamed config/logging assets, updated logger namespaces
  • Moved logging_config.yaml into config/logging_config.yaml
  • Adjusted logger name prefixes from src.* to hippocampai.*
  • Updated Settings loader and setup_app to point at config/config.yaml
config/logging_config.yaml
src/hippocampai/logger.py
src/hippocampai/settings.py
docs/CONFIGURATION.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • This PR bundles large refactors, documentation updates, dependency pinning, and a new web server—consider splitting it into smaller focused PRs (e.g. docs/invocation changes, config modernization, web server & tests) to simplify review and tracking.
  • There’s duplication between pyproject.toml and requirements.txt—consider removing the requirements.txt or automating its generation from your pyproject to avoid drift.
  • Rather than relying on a standalone functional script, add automated integration tests for the new Flask web chat endpoints and include them in CI so that API regressions get caught early.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- This PR bundles large refactors, documentation updates, dependency pinning, and a new web server—consider splitting it into smaller focused PRs (e.g. docs/invocation changes, config modernization, web server & tests) to simplify review and tracking.
- There’s duplication between pyproject.toml and requirements.txt—consider removing the requirements.txt or automating its generation from your pyproject to avoid drift.
- Rather than relying on a standalone functional script, add automated integration tests for the new Flask web chat endpoints and include them in CI so that API regressions get caught early.

## Individual Comments

### Comment 1
<location> `src/hippocampai/utils/time.py:12` </location>
<code_context>
+    return datetime.now(UTC)
+
+
+def ensure_utc(dt: datetime) -> datetime:
+    """Coerce a datetime into UTC."""
+    if dt.tzinfo is None:
</code_context>

<issue_to_address>
**issue:** ensure_utc may not handle datetimes with non-UTC tzinfo as expected.

Replacing tzinfo with UTC does not adjust the time value, so if naive datetimes represent local time, this may cause incorrect conversions.
</issue_to_address>

### Comment 2
<location> `src/hippocampai/utils/scoring.py:17` </location>
<code_context>

 def recency_score(created_at: datetime, half_life_days: int) -> float:
     """Exponential decay based on half-life."""
-    age_days = (datetime.utcnow() - created_at).total_seconds() / 86400
</code_context>

<issue_to_address>
**issue (bug_risk):** recency_score now expects aware datetimes; ensure all callers provide them.

Passing naive datetimes will result in ensure_utc assigning UTC tzinfo without adjusting the time, potentially causing incorrect age calculations.
</issue_to_address>

### Comment 3
<location> `tests/test_retrieval.py:29` </location>
<code_context>
 def test_recency_score():
     """Test recency decay."""
-    now = datetime.utcnow()
+    now = datetime.now(UTC)
     old = now - timedelta(days=30)

</code_context>

<issue_to_address>
**suggestion (testing):** Consider adding tests for edge cases in recency_score, such as naive datetimes and future dates.

Please add tests for naive datetimes, future dates, and dates far in the past to verify recency_score handles these cases correctly.
</issue_to_address>

### Comment 4
<location> `src/hippocampai/utils/time.py:14-16` </location>
<code_context>
def ensure_utc(dt: datetime) -> datetime:
    """Coerce a datetime into UTC."""
    if dt.tzinfo is None:
        return dt.replace(tzinfo=UTC)
    return dt.astimezone(UTC)

</code_context>

<issue_to_address>
**suggestion (code-quality):** We've found these issues:

- Lift code into else after jump in control flow ([`reintroduce-else`](https://docs.sourcery.ai/Reference/Default-Rules/refactorings/reintroduce-else/))
- Replace if statement with if expression ([`assign-if-exp`](https://docs.sourcery.ai/Reference/Default-Rules/refactorings/assign-if-exp/))

```suggestion
    return dt.replace(tzinfo=UTC) if dt.tzinfo is None else dt.astimezone(UTC)
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

rexdivakar and others added 8 commits October 19, 2025 10:45
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
… pipeline components, and utility functions

- Implement tests for configuration loading and validation in `test_config.py`
- Create tests for memory models and their functionalities in `test_models.py`
- Add tests for package structure and import integrity in `test_package.py`
- Develop tests for pipeline components including scoring, extraction, and consolidation in `test_pipeline.py`
- Introduce tests for utility functions covering time, scoring, and caching in `test_utils.py`
@rexdivakar rexdivakar closed this Oct 21, 2025
@rexdivakar rexdivakar deleted the upgrade_1.0 branch October 29, 2025 18:06
@rexdivakar rexdivakar restored the upgrade_1.0 branch February 11, 2026 20:19
@rexdivakar rexdivakar deleted the upgrade_1.0 branch February 11, 2026 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant