Commit b978636
feat: add persistent context memory store with write-time dedup (#37)
* feat: add persistent context memory store with write-time dedup
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>
* fix: handle all error returns to satisfy errcheck linter
Co-authored-by: Ona <no-reply@ona.com>
* fix: handle Close() error returns in tests
Co-authored-by: Ona <no-reply@ona.com>
* refactor: address code review findings for memory store
- 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>
* cleanup: address remaining review nits
- 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>
* docs: add context memory section to README
- 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>
---------
Co-authored-by: Ona <no-reply@ona.com>1 parent e6f58f3 commit b978636
13 files changed
Lines changed: 2086 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
204 | 273 | | |
205 | 274 | | |
206 | 275 | | |
207 | 276 | | |
208 | 277 | | |
209 | 278 | | |
| 279 | + | |
210 | 280 | | |
211 | 281 | | |
212 | 282 | | |
| |||
220 | 290 | | |
221 | 291 | | |
222 | 292 | | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
223 | 297 | | |
224 | 298 | | |
225 | 299 | | |
| |||
489 | 563 | | |
490 | 564 | | |
491 | 565 | | |
492 | | - | |
| 566 | + | |
493 | 567 | | |
494 | 568 | | |
495 | | - | |
| 569 | + | |
496 | 570 | | |
497 | 571 | | |
498 | 572 | | |
| |||
527 | 601 | | |
528 | 602 | | |
529 | 603 | | |
530 | | - | |
531 | | - | |
532 | | - | |
533 | | - | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
534 | 608 | | |
535 | 609 | | |
536 | 610 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| |||
177 | 178 | | |
178 | 179 | | |
179 | 180 | | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
180 | 202 | | |
181 | 203 | | |
182 | 204 | | |
| |||
218 | 240 | | |
219 | 241 | | |
220 | 242 | | |
| 243 | + | |
221 | 244 | | |
222 | 245 | | |
223 | 246 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
0 commit comments