feat: add persistent context memory store with write-time dedup#37
Merged
Siddhant-K-code merged 6 commits intomainfrom Feb 23, 2026
Merged
feat: add persistent context memory store with write-time dedup#37Siddhant-K-code merged 6 commits intomainfrom
Siddhant-K-code merged 6 commits intomainfrom
Conversation
Adds pkg/memory with SQLite-backed persistent storage for context that accumulates across agent sessions. Core features: - Write-time dedup via cosine distance on embeddings - Tag-based recall with relevance + recency ranking - Token budget support for recall - Hierarchical decay: full text -> summary -> keywords -> evicted - Background decay worker with configurable age thresholds Integration: - CLI: distill memory store/recall/forget/stats - API: POST /v1/memory/store, /recall, /forget, GET /stats - MCP: store_memory, recall_memory, forget_memory, memory_stats tools Uses modernc.org/sqlite (pure Go, no CGO) for zero-dependency local storage. Closes #29 Co-authored-by: Ona <no-reply@ona.com>
Co-authored-by: Ona <no-reply@ona.com>
Co-authored-by: Ona <no-reply@ona.com>
Owner
Author
Code ReviewCI is green (build + lint). 11 tests pass. Here's a deep review. What's good
Issues to address (in follow-ups)P1 - Bug risk:
P2 - Correctness:
P3 - Performance (acceptable now, track for later):
P4 - Code quality:
SummarySolid first implementation. The core store/recall/forget/decay loop works correctly and the integration across CLI, API, and MCP is complete. The P1 bug and P2 items should be addressed before merging to main; P3/P4 can be tracked as follow-up issues. |
- P1: Make touchMemories synchronous (no goroutine leak risk) - P2: Remove unused MaxMemories from config - P2: Use junction table (memory_tags) for exact tag matching - P3: Make memory store opt-in via --memory flag in api/mcp - P4: Replace local embeddingProvider with retriever.EmbeddingProvider - P4: Reuse pkg/compress extractive scorer in decay extractSummary - Fix scan-then-process pattern to avoid SQLite single-conn deadlocks Co-authored-by: Ona <no-reply@ona.com>
Owner
Author
Updated Review - Post RefactorCI passing (build + lint), all 11 tests pass, 0 lint issues. Previous P1-P4 findings addressed. Verdict: Approve with minor suggestionsNo blocking issues. Architecture is sound, single-connection SQLite pattern is correctly handled, test coverage is good. Remaining Findings
What's Good
|
- Add TODO to findDuplicate noting O(n) full table scan scaling limit - Refactor Stats to scan-then-close each query (consistent with Recall) - Move extractSummary compressor to package-level var (avoid per-call alloc) - Add --memory-db flag to MCP command (was hardcoded) - Move PRAGMA foreign_keys to NewSQLiteStore alongside other PRAGMAs - Move isStopWord map to package-level var (avoid per-call alloc) - Remove trailing blank line in memory.go Co-authored-by: Ona <no-reply@ona.com>
- Add Context Memory section with CLI, API, and MCP usage examples - Add memory endpoints to API Endpoints table - Add memory command to CLI Commands list - Update architecture diagram: Memory Store is shipped, not planned - Update roadmap: mark Context Memory Store as shipped - Update intro blurb to reflect memory is available Co-authored-by: Ona <no-reply@ona.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a persistent context memory store that accumulates knowledge across agent sessions. Memories are deduplicated on write, ranked by relevance + recency on recall, and compressed over time through hierarchical decay.
What it does
Store - Write context with automatic dedup. If a semantically similar memory already exists (cosine distance < threshold), the existing one is updated instead of creating a duplicate.
Recall - Retrieve memories ranked by
(1-w)*similarity + w*recency. Supports tag filtering and token budgets.Forget - Remove memories by ID, tag, or age.
Decay - Background worker compresses aging memories:
New files
pkg/memory/store.gopkg/memory/sqlite.gopkg/memory/decay.gopkg/memory/helpers.gopkg/memory/memory_test.gocmd/memory.godistill memory store/recall/forget/statscmd/api_memory.goPOST /v1/memory/store,/recall,/forget,GET /statscmd/mcp_memory.gostore_memory,recall_memory,forget_memory,memory_statsDependencies
modernc.org/sqlite- Pure Go SQLite (no CGO required)Usage
Closes #29