sqlite-graph-memory 0.3.3__tar.gz → 0.3.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/CHANGELOG.md +43 -0
  2. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/PKG-INFO +98 -22
  3. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/README.md +93 -21
  4. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/bench/README.md +2 -1
  5. sqlite_graph_memory-0.3.6/docs/demo.gif +0 -0
  6. sqlite_graph_memory-0.3.6/docs/demo.sh +33 -0
  7. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/pyproject.toml +11 -1
  8. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/src/sqlite_graph_memory/__init__.py +1 -1
  9. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/src/sqlite_graph_memory/brain_ask.py +66 -3
  10. sqlite_graph_memory-0.3.6/src/sqlite_graph_memory/doctor.py +144 -0
  11. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/src/sqlite_graph_memory/index_notes.py +23 -14
  12. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/src/sqlite_graph_memory/mcp_server.py +10 -2
  13. sqlite_graph_memory-0.3.6/src/sqlite_graph_memory/onnx_backend.py +127 -0
  14. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/src/sqlite_graph_memory/turnstate_show.py +14 -6
  15. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/src/sqlite_graph_memory/vault_stats.py +10 -2
  16. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/tests/test_bench.py +43 -0
  17. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/tests/test_brain_ask.py +4 -0
  18. sqlite_graph_memory-0.3.6/tests/test_changelog_released.py +146 -0
  19. sqlite_graph_memory-0.3.6/tests/test_doctor.py +94 -0
  20. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/tests/test_mcp_server.py +38 -2
  21. sqlite_graph_memory-0.3.6/tests/test_onnx_backend.py +149 -0
  22. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/tests/test_optional_extra.py +2 -0
  23. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/tests/test_star_prompt.py +3 -0
  24. sqlite_graph_memory-0.3.6/tests/test_turnstate_show.py +52 -0
  25. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/tests/test_vault_stats.py +23 -1
  26. sqlite_graph_memory-0.3.6/tests/test_version_consistent.py +75 -0
  27. sqlite_graph_memory-0.3.6/tests/test_version_flag.py +36 -0
  28. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/.gitignore +0 -0
  29. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/CITATION.cff +0 -0
  30. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/LICENSE +0 -0
  31. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/bench/requirements.txt +0 -0
  32. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/docs/RELEASING.md +0 -0
  33. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/docs/bitemporal.md +0 -0
  34. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/eval/build_gold.py +0 -0
  35. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/eval/run_eval.py +0 -0
  36. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/examples/README.md +0 -0
  37. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/examples/claude-code-stop-hook.json +0 -0
  38. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/examples/mcp-config.json +0 -0
  39. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/requirements.txt +0 -0
  40. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/src/sqlite_graph_memory/ppr.py +0 -0
  41. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/src/sqlite_graph_memory/schema.sql +0 -0
  42. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/src/sqlite_graph_memory/turnstate_hook.py +0 -0
  43. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/tests/test_eval.py +0 -0
  44. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/tests/test_feedback_link.py +0 -0
  45. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/tests/test_index_notes.py +0 -0
  46. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/tests/test_index_notes_dotfiles.py +0 -0
  47. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/tests/test_llms_txt.py +0 -0
  48. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/tests/test_mcp_script_mode.py +0 -0
  49. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/tests/test_ppr.py +0 -0
  50. {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.6}/tests/test_turnstate_hook.py +0 -0
@@ -4,6 +4,49 @@ What shipped, in plain words. Entries below v0.1.3 were written on 2026-09-05 fr
4
4
  release notes that already existed — the file itself did not exist until then, so those three are
5
5
  recorded after the fact rather than backdated to look contemporaneous.
6
6
 
7
+ ## Unreleased
8
+
9
+ ## v0.3.6 - 2026-11-03
10
+
11
+ **Light backend: recall without torch.** New extra `[lite]` runs the same two models (multilingual-e5-base and the mMiniLMv2 reranker) on ONNX Runtime from their official ONNX exports: 155 MB installed instead of ~2 GB, and on the hub one MCP recall took 7.0 s instead of 33.8 s through torch, with the same hits and scores (embeddings agree to 3e-7). It is picked automatically when installed; `SGM_BACKEND=torch|onnx` forces either, and an index built by one backend works with the other. `pick_device()` no longer imports torch on this path: on a Windows CPU laptop that import alone took 44 s and pushed the first MCP call past the client's tool timeout (2026-11-01). Models stay in the persistent Hugging Face cache (`SGM_MODEL_CACHE` overrides), and `sgm-index` fetches the reranker too, so the first recall is not also a download. `sgm-doctor` reports the light backend. Install commands in README keep `[embeddings]` until `[lite]` is on PyPI.
12
+
13
+ **`sgm-turnstate-show`: a corrupt ledger gets one line, not a traceback.** When `TURNSTATE_DB` is not a SQLite file the command now prints `not a database: <path>` on stderr and exits 1, leaving the file untouched; a missing ledger keeps its friendly line. Thanks @ShahadatTest (#77), who picked up #74.
14
+
15
+ **`sgm-stats`: a wikilink inside inline code is no longer a graph edge.** `_links_in` already ignored fenced blocks; it now ignores inline code spans too, so an example like `` `[[x]]` `` stops inflating the link counts. Thanks @bfs2021 (#78), who picked up #72.
16
+
17
+ **`sgm-stats --json` on an empty folder prints JSON.** A cron script that parses the output now gets an object with `verdict: fail`, `exit_code: 2` and an `error` field instead of plain text; the exit code stays 2 and plain mode is unchanged. Thanks @sharmao07 (#79), who picked up #73.
18
+
19
+ **`--version` on `sgm-stats` and `sgm-ask`.** Both print the package version and exit 0; `sgm-ask` answers before it touches a model or an index. Thanks @BiswasNehaa (#81), who picked up #75.
20
+
21
+ ## v0.3.5 - 2026-11-01
22
+
23
+ **Release fix.** v0.3.4 was tagged but never reached PyPI: the release commit changed only this file, and the publish job stopped on its version check (pyproject, `__init__`, server.json still said 0.3.3). v0.3.5 is the first PyPI build with everything listed under v0.3.4 plus the entries below, with the version set in all four places.
24
+
25
+ **MCP: recall no longer dies on the first cold call.** The default deadline is now 180 seconds (was a fixed 60): on a clean Windows install one CLI recall took 89 s, so the first MCP call timed out. `BRAIN_RECALL_TIMEOUT` overrides it; valid values are integer seconds from 1 to 600. Invalid values return a visible configuration error without starting recall. Timeout errors name the actual configured deadline. Reproduced during a clean Windows installation: CLI recall succeeded while the MCP child hit the previous fixed 60-second deadline.
26
+
27
+ **Tests: tilde expansion isolated on Windows.** The test sets the Windows home directory as well as the Unix home directory. It now checks the temporary profile on Windows instead of writing a marker into the real user's profile.
28
+
29
+ **Docs: preserve an existing agent setup.** README links to the existing-setup guide in second-brain-starter-kit, covering per-client memory installation and fresh-chat acceptance without replacing the owner's rules.
30
+
31
+ **`sgm-doctor`: one command that checks a fresh install in plain words.** Python, SQLite, numpy,
32
+ torch and sentence-transformers, the two models in the local cache, and your index, each with an
33
+ ok/warn/fail verdict and the fix printed next to it; exit 1 when anything fails. On an Intel Mac
34
+ with NumPy 2 it names the pairing that crashes indexing instead of a bare import error.
35
+
36
+ ## v0.3.4 - 2026-10-31
37
+
38
+ **Credit, written down at last.** Four outside pull requests merged since 19.10 and none was named
39
+ here. Thanks to [@Kaap10](https://github.com/Kaap10): the MCP server now answers non-object JSON
40
+ payloads with `-32600 Invalid Request` instead of failing (#32, closes #22), and finds its
41
+ `brain_ask` sibling and passes a non-zero exit through in test mode (#33, closes #24). Thanks to
42
+ [@Vamsi-2581](https://github.com/Vamsi-2581): a missing embedding index is now reported as an error
43
+ instead of passing silently (#35). Thanks to [@Khushbu677](https://github.com/Khushbu677): tests for
44
+ the turnstate hook's ledger writes (#57). From now on `scripts/credit_gate.py` runs in CI and goes red
45
+ when a merged outside PR has no line here, or when a `@handle` here does not exist; the rules are in
46
+ [CONTRIBUTING.md](CONTRIBUTING.md).
47
+
48
+ **Also in this release.** Benchmark adapters for four external memory systems (fidelis, mem0 local, second-brain, SQLite FTS5) with CI reruns pinned to one Ollama build and one CPU kernel, and CI guards that freeze released CHANGELOG sections and fail on unreadable tags, pre-release tags and duplicate headers.
49
+
7
50
  ## v0.3.3 — 2026-10-26
8
51
 
9
52
  **Hidden note files are skipped like hidden folders.** A note whose filename starts with a
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: sqlite-graph-memory
3
- Version: 0.3.3
3
+ Version: 0.3.6
4
4
  Summary: Associative memory for LLM agents: Graph RAG over a folder of markdown notes, in one SQLite file, with no server to run.
5
5
  Project-URL: Homepage, https://github.com/tonydzi/sqlite-graph-memory
6
6
  Project-URL: Repository, https://github.com/tonydzi/sqlite-graph-memory
@@ -47,23 +47,100 @@ Requires-Dist: numpy<2; (sys_platform == 'darwin' and platform_machine == 'x86_6
47
47
  Requires-Dist: sentence-transformers<5; (sys_platform == 'darwin' and platform_machine == 'x86_64') and extra == 'embeddings'
48
48
  Requires-Dist: sentence-transformers>=2.6; extra == 'embeddings'
49
49
  Requires-Dist: transformers<4.50; (sys_platform == 'darwin' and platform_machine == 'x86_64') and extra == 'embeddings'
50
+ Provides-Extra: lite
51
+ Requires-Dist: huggingface-hub>=0.20; extra == 'lite'
52
+ Requires-Dist: onnxruntime>=1.17; extra == 'lite'
53
+ Requires-Dist: tokenizers>=0.15; extra == 'lite'
50
54
  Description-Content-Type: text/markdown
51
55
 
52
56
  # sqlite-graph-memory: persistent memory for Claude Code, Cursor and Codex over your own markdown notes
53
57
 
54
58
  <!-- mcp-name: io.github.tonydzi/sqlite-graph-memory -->
55
59
 
56
- [![PyPI](https://img.shields.io/pypi/v/sqlite-graph-memory)](https://pypi.org/project/sqlite-graph-memory/) [![tests](https://img.shields.io/github/actions/workflow/status/tonydzi/sqlite-graph-memory/tests.yml?label=tests)](https://github.com/tonydzi/sqlite-graph-memory/actions/workflows/tests.yml) [![MCP Registry](https://img.shields.io/badge/MCP%20Registry-io.github.tonydzi%2Fsqlite--graph--memory-blue)](https://registry.modelcontextprotocol.io/v0/servers?search=sqlite-graph-memory) [![License: MIT](https://img.shields.io/badge/license-MIT-green)](LICENSE)
60
+ Your coding agent remembers what you already wrote down, and reaches the note a plain search
61
+ misses by following the links between your notes. It is an MCP server and a CLI over any
62
+ folder of markdown, Obsidian vaults included: `pip install`, point it at the folder, and
63
+ Claude Code, Cursor, Codex or any other MCP client can recall from it.
57
64
 
58
- Long-term memory for coding agents that lives in the notes you already keep: an MCP server
59
- and a CLI over any folder of markdown, Obsidian vaults included. `pip install`, point it at
60
- the folder, and Claude Code, Cursor, Codex or any other MCP client can recall from it.
65
+ ![sgm-index builds the index of the 202-note bench vault, then sgm-ask --ab shows tool-lanternfish entering the top 5 only through a graph hop; the one-minute CPU indexing wait is cut](docs/demo.gif)
61
66
 
62
67
  **Your agent forgets everything between sessions, and plain vector search gives it back
63
68
  flat, unrelated chunks. This gives it associative recall over your own markdown notes:
64
69
  vector search finds the entry points, the `[[wikilinks]]` you already wrote are the graph.
65
70
  One SQLite file, no graph database, no ETL pass, no server.**
66
71
 
72
+ [![PyPI](https://img.shields.io/pypi/v/sqlite-graph-memory)](https://pypi.org/project/sqlite-graph-memory/) [![tests](https://img.shields.io/github/actions/workflow/status/tonydzi/sqlite-graph-memory/tests.yml?label=tests)](https://github.com/tonydzi/sqlite-graph-memory/actions/workflows/tests.yml) [![MCP Registry](https://img.shields.io/badge/MCP%20Registry-io.github.tonydzi%2Fsqlite--graph--memory-blue)](https://registry.modelcontextprotocol.io/v0/servers?search=sqlite-graph-memory) [![License: MIT](https://img.shields.io/badge/license-MIT-green)](LICENSE)
73
+
74
+ ## Install in your client
75
+
76
+ Already using your own agent rules and projects? The [Russian existing-setup guide](https://github.com/tonydzi/second-brain-starter-kit/blob/master/docs/EXISTING-SETUP.ru.md) combines this memory backend with the optional starter-kit method, preserves existing settings, and checks recall in a fresh chat. Install one memory connection per client; the starter-kit memory plugin and manual registration are alternatives.
77
+
78
+ Build the index once (any folder of markdown; [`uv`](https://docs.astral.sh/uv/) gives you `uvx`):
79
+
80
+ ```bash
81
+ BRAIN_INDEX_DIR=$HOME/.sgm-index uvx --from 'sqlite-graph-memory[embeddings]' sgm-index ~/notes
82
+ ```
83
+
84
+ Then point your client at the server. Use the absolute path of that index folder.
85
+
86
+ **Cold-start timeout (0.3.5 and later).** The MCP server starts recall in a separate process with a default deadline of 180 seconds; a first call on a clean Windows install took 89 s, which the old fixed 60 s always cut off. Override with `BRAIN_RECALL_TIMEOUT` (integer seconds, 1 to 600; invalid values return an error). Your MCP client's own tool timeout must also allow the longer call. On 0.3.3 and earlier the deadline is a fixed 60 s: upgrade, or use `sgm-ask --ask` directly, and do not report MCP recall as verified merely because the CLI works.
87
+
88
+ **Claude Code**
89
+
90
+ ```bash
91
+ claude mcp add sqlite-graph-memory -e BRAIN_INDEX_DIR=$HOME/.sgm-index -- uvx --with 'sqlite-graph-memory[embeddings]' sqlite-graph-memory
92
+ ```
93
+
94
+ **Cursor** (`~/.cursor/mcp.json`; Claude Desktop, Zed and Windsurf take the same `mcpServers` block)
95
+
96
+ ```json
97
+ {
98
+ "mcpServers": {
99
+ "sqlite-graph-memory": {
100
+ "command": "uvx",
101
+ "args": ["--with", "sqlite-graph-memory[embeddings]", "sqlite-graph-memory"],
102
+ "env": { "BRAIN_INDEX_DIR": "/absolute/path/to/.sgm-index" }
103
+ }
104
+ }
105
+ }
106
+ ```
107
+
108
+ **VS Code** (`.vscode/mcp.json` in the workspace)
109
+
110
+ ```json
111
+ {
112
+ "servers": {
113
+ "sqlite-graph-memory": {
114
+ "type": "stdio",
115
+ "command": "uvx",
116
+ "args": ["--with", "sqlite-graph-memory[embeddings]", "sqlite-graph-memory"],
117
+ "env": { "BRAIN_INDEX_DIR": "/absolute/path/to/.sgm-index" }
118
+ }
119
+ }
120
+ }
121
+ ```
122
+
123
+ **Codex** (`~/.codex/config.toml`)
124
+
125
+ ```toml
126
+ [mcp_servers.sqlite-graph-memory]
127
+ command = "uvx"
128
+ args = ["--with", "sqlite-graph-memory[embeddings]", "sqlite-graph-memory"]
129
+ env = { BRAIN_INDEX_DIR = "/absolute/path/to/.sgm-index" }
130
+ ```
131
+
132
+ Size, `du -sh` of a fresh Python 3.12 venv on an x86_64 Mac (1 Nov 2026): the base install is
133
+ 26 MB and has no torch (numpy only, enough for the graph half and the SQLite ledger);
134
+ with `[embeddings]` (torch) it is 879 MB, 540 MB of that torch 2.2.2 CPU. With `[lite]` (from v0.3.6),
135
+ the same two models on ONNX Runtime and no torch, it is 155 MB (Windows, Python 3.12,
136
+ 3 Nov 2026), installs in 12 s, and one MCP recall on the 202-note bench vault took 7.0 s
137
+ against 33.8 s through torch on the same machine, with the same top hits and scores.
138
+ `[lite]` is picked automatically when installed; `SGM_BACKEND=torch` forces torch (for a GPU).
139
+ An index built by either backend is searched correctly by the other.
140
+ Already installed with pip? Replace `uvx --with ... sqlite-graph-memory` by `sgm-mcp`
141
+ ([`examples/mcp-config.json`](examples/mcp-config.json)). Agents that read files first:
142
+ [`llms.txt`](llms.txt).
143
+
67
144
  ## Three commands
68
145
 
69
146
  ```bash
@@ -110,14 +187,6 @@ That is the idea in one query, and it is not a blanket win. On this same vault v
110
187
  ranks ahead of graph mode overall; the numbers are in [`bench/`](bench/README.md). `--ab`
111
188
  exists so you can measure which one wins on your own notes.
112
189
 
113
- **From any MCP client** (Claude Desktop, Cursor, Zed, Windsurf): `sgm-mcp` after the install
114
- above, or `uvx --with 'sqlite-graph-memory[embeddings]' sqlite-graph-memory`. Set
115
- `BRAIN_INDEX_DIR` to the `index` folder `sgm-index` wrote. Config:
116
- [`examples/mcp-config.json`](examples/mcp-config.json). Claude Code:
117
- `claude mcp add sqlite-graph-memory -e BRAIN_INDEX_DIR=/path/to/index -- sgm-mcp`.
118
- Codex: a `[mcp_servers.sqlite-graph-memory]` table in `~/.codex/config.toml` with
119
- `command = "sgm-mcp"`. Agents that read files first: [`llms.txt`](llms.txt).
120
-
121
190
  ## What it is
122
191
 
123
192
  Graph RAG on SQLite for AI agents — a working pilot, not a framework. It is the extracted
@@ -144,7 +213,7 @@ For a single-user agent over a markdown knowledge base, all three are overkill:
144
213
  edges as `[[wikilinks]]`, and `brain_ask.py` just parses them.
145
214
  No extraction pass, and edge quality beats anything a model would mine.
146
215
  - **SQLite is enough** — the only things worth persisting are derived state (a per-turn
147
- ledger) and telemetry, and both are defined in [`schema.sql`](schema.sql).
216
+ ledger) and telemetry, and both are defined in [`schema.sql`](src/sqlite_graph_memory/schema.sql).
148
217
  One file, stdlib driver, zero ops.
149
218
  - The expensive part of RAG quality is a **reranker**, not graph infrastructure — see the
150
219
  rerank step in `brain_ask.py`.
@@ -176,7 +245,7 @@ markdown notes (with [[wikilinks]])
176
245
  turnstate_show.py = read-only viewer.
177
246
  ```
178
247
 
179
- [`schema.sql`](schema.sql) documents both tables. The graph is **not** materialized in SQL:
248
+ [`schema.sql`](src/sqlite_graph_memory/schema.sql) documents both tables. The graph is **not** materialized in SQL:
180
249
  `brain_ask.py` parses edges from the notes at query time, bounded to 1 hop / 40 neighbours.
181
250
  That keeps the graph permanently in sync with the notes at zero maintenance cost; materialize
182
251
  an edge table only when hop depth or corpus size demands it.
@@ -196,7 +265,7 @@ an edge table only when hop depth or corpus size demands it.
196
265
  vector-only recall, no ledger row.
197
266
  A memory layer must never make the agent worse than having no memory layer.
198
267
  - **Measure, don't believe.** `--ab` runs both pipelines on every real query and logs how
199
- many notes the graph promoted into the top-N, to `ab_recall` in [`schema.sql`](schema.sql).
268
+ many notes the graph promoted into the top-N, to `ab_recall` in [`schema.sql`](src/sqlite_graph_memory/schema.sql).
200
269
  Whether "associative memory" earns its keep is a weekly SQL query, not a vibe.
201
270
 
202
271
  ### What's intentionally missing
@@ -215,9 +284,9 @@ an edge table only when hop depth or corpus size demands it.
215
284
  ## Quickstart
216
285
 
217
286
  ```bash
218
- # Indexing and reranking need the embedding stack; the base install leaves it out
219
- # so that `pip install sqlite-graph-memory` stays small instead of pulling ~2 GB
220
- # of torch. Ask for it explicitly:
287
+ # Indexing and reranking need an embedding stack; the base install leaves it out.
288
+ # [lite] (from v0.3.6) runs the models on ONNX Runtime without torch (~155 MB); [embeddings]
289
+ # brings torch (~2 GB) if you want a GPU. Ask for one explicitly:
221
290
  pip install 'sqlite-graph-memory[embeddings]'
222
291
 
223
292
  # 1. index a folder of markdown notes
@@ -273,7 +342,7 @@ A/B RECALL: how should agent memory work
273
342
 
274
343
  On a corpus this small the graph adds nothing — every note is already in the candidate
275
344
  pool. The interesting deltas appear at scale, and that is exactly what the `ab_recall`
276
- table in [`schema.sql`](schema.sql) accumulates evidence for.
345
+ table in [`schema.sql`](src/sqlite_graph_memory/schema.sql) accumulates evidence for.
277
346
 
278
347
  ## Public benchmark — `bench/`
279
348
 
@@ -402,6 +471,11 @@ Seven other changes were rejected by the same ruler, under one rule fixed in adv
402
471
  | `sqlite-vec` (vec0) | full scan 11.99 s vs 0.14 s for a plain SQLite table, and its ANN missed 1.2 hits of 60 -> vectors live in SQLite, **the extension does not** |
403
472
  | bi-temporal demotion of superseded notes | temporal +0.130 nDCG on a 41-question temporal set, but title −0.012 -> **merged behind a flag, default off** (in the home pipeline, not in this package) |
404
473
 
474
+ The two rows marked "home pipeline" are not in this package: BM25 fusion and superseded-note
475
+ demotion exist only in the maintainer's home build. Check it yourself in a clone:
476
+ `grep -rniE 'bm25|superseded' src/` prints nothing. The PageRank lane above is the one
477
+ merged change that ships (`src/sqlite_graph_memory/ppr.py`).
478
+
405
479
  None of those verdicts is a claim about the models. They are claims about *this corpus with
406
480
  this ruler*, which is the only kind of claim a swap decision actually needs — and the reason
407
481
  the module is here rather than in a blog post is that your corpus will disagree with ours.
@@ -422,7 +496,7 @@ while the metric is broken never tested the metric.
422
496
 
423
497
  ## Roadmap
424
498
 
425
- **Now — [latest release](https://github.com/tonydzi/sqlite-graph-memory/releases/latest)** (v0.3.1 on PyPI and in the MCP Registry as of 2026-10-19).
499
+ **Now — [latest release](https://github.com/tonydzi/sqlite-graph-memory/releases/latest)** (the version badge above is the one on PyPI; the same version is in the MCP Registry).
426
500
  The pilot as it runs daily: retrieval pipeline, per-turn ledger and A/B telemetry, all in
427
501
  `brain_ask.py` and `turnstate_hook.py`, plus the bi-temporal design note. Known defects live in
428
502
  the [tracker](https://github.com/tonydzi/sqlite-graph-memory/issues) rather than in footnotes
@@ -441,7 +515,8 @@ does not notice, and that drift is the defect this paragraph used to carry twice
441
515
  materialize the graph instead of parsing it at query time, give every edge a validity
442
516
  window (`valid_from` / `valid_to` / `observed_at`) so a rebuild *closes* superseded facts
443
517
  instead of deleting them: history is kept, recall prefers the present, and `as_of` queries
444
- can reconstruct the past. Non-destructive aging by confidence decay. The day-1 A/B result
518
+ can reconstruct the past. Non-destructive aging by confidence decay. None of this is in
519
+ the package yet: it is a design note plus a home-pipeline experiment. The day-1 A/B result
445
520
  — context size ~unchanged, retrieved candidates ~60% fresher by mean age — is written up
446
521
  with its caveats in `docs/bitemporal.md`: the volume win is longitudinal, so that is one
447
522
  day on one corpus, not a benchmark.
@@ -496,6 +571,7 @@ Questions, war stories, or you want to run this on your own fleet:
496
571
  You tried this on your own notes and something was missing or broke. That is the most useful
497
572
  thing anyone can tell us.
498
573
 
574
+ - **Install or first run gone wrong:** run `sgm-doctor` first. It checks Python, numpy, torch, the models and your index in plain words and prints the fix for each.
499
575
  - **You started and it did not work:** [open the 3-question form](https://github.com/tonydzi/sqlite-graph-memory/issues/new?template=feature_request.yml) (what you tried, what broke, which machine).
500
576
  - **Not sure it is a bug, or just an idea:** [Discussions → Ideas](https://github.com/tonydzi/sqlite-graph-memory/discussions/categories/ideas).
501
577
 
@@ -2,17 +2,90 @@
2
2
 
3
3
  <!-- mcp-name: io.github.tonydzi/sqlite-graph-memory -->
4
4
 
5
- [![PyPI](https://img.shields.io/pypi/v/sqlite-graph-memory)](https://pypi.org/project/sqlite-graph-memory/) [![tests](https://img.shields.io/github/actions/workflow/status/tonydzi/sqlite-graph-memory/tests.yml?label=tests)](https://github.com/tonydzi/sqlite-graph-memory/actions/workflows/tests.yml) [![MCP Registry](https://img.shields.io/badge/MCP%20Registry-io.github.tonydzi%2Fsqlite--graph--memory-blue)](https://registry.modelcontextprotocol.io/v0/servers?search=sqlite-graph-memory) [![License: MIT](https://img.shields.io/badge/license-MIT-green)](LICENSE)
5
+ Your coding agent remembers what you already wrote down, and reaches the note a plain search
6
+ misses by following the links between your notes. It is an MCP server and a CLI over any
7
+ folder of markdown, Obsidian vaults included: `pip install`, point it at the folder, and
8
+ Claude Code, Cursor, Codex or any other MCP client can recall from it.
6
9
 
7
- Long-term memory for coding agents that lives in the notes you already keep: an MCP server
8
- and a CLI over any folder of markdown, Obsidian vaults included. `pip install`, point it at
9
- the folder, and Claude Code, Cursor, Codex or any other MCP client can recall from it.
10
+ ![sgm-index builds the index of the 202-note bench vault, then sgm-ask --ab shows tool-lanternfish entering the top 5 only through a graph hop; the one-minute CPU indexing wait is cut](docs/demo.gif)
10
11
 
11
12
  **Your agent forgets everything between sessions, and plain vector search gives it back
12
13
  flat, unrelated chunks. This gives it associative recall over your own markdown notes:
13
14
  vector search finds the entry points, the `[[wikilinks]]` you already wrote are the graph.
14
15
  One SQLite file, no graph database, no ETL pass, no server.**
15
16
 
17
+ [![PyPI](https://img.shields.io/pypi/v/sqlite-graph-memory)](https://pypi.org/project/sqlite-graph-memory/) [![tests](https://img.shields.io/github/actions/workflow/status/tonydzi/sqlite-graph-memory/tests.yml?label=tests)](https://github.com/tonydzi/sqlite-graph-memory/actions/workflows/tests.yml) [![MCP Registry](https://img.shields.io/badge/MCP%20Registry-io.github.tonydzi%2Fsqlite--graph--memory-blue)](https://registry.modelcontextprotocol.io/v0/servers?search=sqlite-graph-memory) [![License: MIT](https://img.shields.io/badge/license-MIT-green)](LICENSE)
18
+
19
+ ## Install in your client
20
+
21
+ Already using your own agent rules and projects? The [Russian existing-setup guide](https://github.com/tonydzi/second-brain-starter-kit/blob/master/docs/EXISTING-SETUP.ru.md) combines this memory backend with the optional starter-kit method, preserves existing settings, and checks recall in a fresh chat. Install one memory connection per client; the starter-kit memory plugin and manual registration are alternatives.
22
+
23
+ Build the index once (any folder of markdown; [`uv`](https://docs.astral.sh/uv/) gives you `uvx`):
24
+
25
+ ```bash
26
+ BRAIN_INDEX_DIR=$HOME/.sgm-index uvx --from 'sqlite-graph-memory[embeddings]' sgm-index ~/notes
27
+ ```
28
+
29
+ Then point your client at the server. Use the absolute path of that index folder.
30
+
31
+ **Cold-start timeout (0.3.5 and later).** The MCP server starts recall in a separate process with a default deadline of 180 seconds; a first call on a clean Windows install took 89 s, which the old fixed 60 s always cut off. Override with `BRAIN_RECALL_TIMEOUT` (integer seconds, 1 to 600; invalid values return an error). Your MCP client's own tool timeout must also allow the longer call. On 0.3.3 and earlier the deadline is a fixed 60 s: upgrade, or use `sgm-ask --ask` directly, and do not report MCP recall as verified merely because the CLI works.
32
+
33
+ **Claude Code**
34
+
35
+ ```bash
36
+ claude mcp add sqlite-graph-memory -e BRAIN_INDEX_DIR=$HOME/.sgm-index -- uvx --with 'sqlite-graph-memory[embeddings]' sqlite-graph-memory
37
+ ```
38
+
39
+ **Cursor** (`~/.cursor/mcp.json`; Claude Desktop, Zed and Windsurf take the same `mcpServers` block)
40
+
41
+ ```json
42
+ {
43
+ "mcpServers": {
44
+ "sqlite-graph-memory": {
45
+ "command": "uvx",
46
+ "args": ["--with", "sqlite-graph-memory[embeddings]", "sqlite-graph-memory"],
47
+ "env": { "BRAIN_INDEX_DIR": "/absolute/path/to/.sgm-index" }
48
+ }
49
+ }
50
+ }
51
+ ```
52
+
53
+ **VS Code** (`.vscode/mcp.json` in the workspace)
54
+
55
+ ```json
56
+ {
57
+ "servers": {
58
+ "sqlite-graph-memory": {
59
+ "type": "stdio",
60
+ "command": "uvx",
61
+ "args": ["--with", "sqlite-graph-memory[embeddings]", "sqlite-graph-memory"],
62
+ "env": { "BRAIN_INDEX_DIR": "/absolute/path/to/.sgm-index" }
63
+ }
64
+ }
65
+ }
66
+ ```
67
+
68
+ **Codex** (`~/.codex/config.toml`)
69
+
70
+ ```toml
71
+ [mcp_servers.sqlite-graph-memory]
72
+ command = "uvx"
73
+ args = ["--with", "sqlite-graph-memory[embeddings]", "sqlite-graph-memory"]
74
+ env = { BRAIN_INDEX_DIR = "/absolute/path/to/.sgm-index" }
75
+ ```
76
+
77
+ Size, `du -sh` of a fresh Python 3.12 venv on an x86_64 Mac (1 Nov 2026): the base install is
78
+ 26 MB and has no torch (numpy only, enough for the graph half and the SQLite ledger);
79
+ with `[embeddings]` (torch) it is 879 MB, 540 MB of that torch 2.2.2 CPU. With `[lite]` (from v0.3.6),
80
+ the same two models on ONNX Runtime and no torch, it is 155 MB (Windows, Python 3.12,
81
+ 3 Nov 2026), installs in 12 s, and one MCP recall on the 202-note bench vault took 7.0 s
82
+ against 33.8 s through torch on the same machine, with the same top hits and scores.
83
+ `[lite]` is picked automatically when installed; `SGM_BACKEND=torch` forces torch (for a GPU).
84
+ An index built by either backend is searched correctly by the other.
85
+ Already installed with pip? Replace `uvx --with ... sqlite-graph-memory` by `sgm-mcp`
86
+ ([`examples/mcp-config.json`](examples/mcp-config.json)). Agents that read files first:
87
+ [`llms.txt`](llms.txt).
88
+
16
89
  ## Three commands
17
90
 
18
91
  ```bash
@@ -59,14 +132,6 @@ That is the idea in one query, and it is not a blanket win. On this same vault v
59
132
  ranks ahead of graph mode overall; the numbers are in [`bench/`](bench/README.md). `--ab`
60
133
  exists so you can measure which one wins on your own notes.
61
134
 
62
- **From any MCP client** (Claude Desktop, Cursor, Zed, Windsurf): `sgm-mcp` after the install
63
- above, or `uvx --with 'sqlite-graph-memory[embeddings]' sqlite-graph-memory`. Set
64
- `BRAIN_INDEX_DIR` to the `index` folder `sgm-index` wrote. Config:
65
- [`examples/mcp-config.json`](examples/mcp-config.json). Claude Code:
66
- `claude mcp add sqlite-graph-memory -e BRAIN_INDEX_DIR=/path/to/index -- sgm-mcp`.
67
- Codex: a `[mcp_servers.sqlite-graph-memory]` table in `~/.codex/config.toml` with
68
- `command = "sgm-mcp"`. Agents that read files first: [`llms.txt`](llms.txt).
69
-
70
135
  ## What it is
71
136
 
72
137
  Graph RAG on SQLite for AI agents — a working pilot, not a framework. It is the extracted
@@ -93,7 +158,7 @@ For a single-user agent over a markdown knowledge base, all three are overkill:
93
158
  edges as `[[wikilinks]]`, and `brain_ask.py` just parses them.
94
159
  No extraction pass, and edge quality beats anything a model would mine.
95
160
  - **SQLite is enough** — the only things worth persisting are derived state (a per-turn
96
- ledger) and telemetry, and both are defined in [`schema.sql`](schema.sql).
161
+ ledger) and telemetry, and both are defined in [`schema.sql`](src/sqlite_graph_memory/schema.sql).
97
162
  One file, stdlib driver, zero ops.
98
163
  - The expensive part of RAG quality is a **reranker**, not graph infrastructure — see the
99
164
  rerank step in `brain_ask.py`.
@@ -125,7 +190,7 @@ markdown notes (with [[wikilinks]])
125
190
  turnstate_show.py = read-only viewer.
126
191
  ```
127
192
 
128
- [`schema.sql`](schema.sql) documents both tables. The graph is **not** materialized in SQL:
193
+ [`schema.sql`](src/sqlite_graph_memory/schema.sql) documents both tables. The graph is **not** materialized in SQL:
129
194
  `brain_ask.py` parses edges from the notes at query time, bounded to 1 hop / 40 neighbours.
130
195
  That keeps the graph permanently in sync with the notes at zero maintenance cost; materialize
131
196
  an edge table only when hop depth or corpus size demands it.
@@ -145,7 +210,7 @@ an edge table only when hop depth or corpus size demands it.
145
210
  vector-only recall, no ledger row.
146
211
  A memory layer must never make the agent worse than having no memory layer.
147
212
  - **Measure, don't believe.** `--ab` runs both pipelines on every real query and logs how
148
- many notes the graph promoted into the top-N, to `ab_recall` in [`schema.sql`](schema.sql).
213
+ many notes the graph promoted into the top-N, to `ab_recall` in [`schema.sql`](src/sqlite_graph_memory/schema.sql).
149
214
  Whether "associative memory" earns its keep is a weekly SQL query, not a vibe.
150
215
 
151
216
  ### What's intentionally missing
@@ -164,9 +229,9 @@ an edge table only when hop depth or corpus size demands it.
164
229
  ## Quickstart
165
230
 
166
231
  ```bash
167
- # Indexing and reranking need the embedding stack; the base install leaves it out
168
- # so that `pip install sqlite-graph-memory` stays small instead of pulling ~2 GB
169
- # of torch. Ask for it explicitly:
232
+ # Indexing and reranking need an embedding stack; the base install leaves it out.
233
+ # [lite] (from v0.3.6) runs the models on ONNX Runtime without torch (~155 MB); [embeddings]
234
+ # brings torch (~2 GB) if you want a GPU. Ask for one explicitly:
170
235
  pip install 'sqlite-graph-memory[embeddings]'
171
236
 
172
237
  # 1. index a folder of markdown notes
@@ -222,7 +287,7 @@ A/B RECALL: how should agent memory work
222
287
 
223
288
  On a corpus this small the graph adds nothing — every note is already in the candidate
224
289
  pool. The interesting deltas appear at scale, and that is exactly what the `ab_recall`
225
- table in [`schema.sql`](schema.sql) accumulates evidence for.
290
+ table in [`schema.sql`](src/sqlite_graph_memory/schema.sql) accumulates evidence for.
226
291
 
227
292
  ## Public benchmark — `bench/`
228
293
 
@@ -351,6 +416,11 @@ Seven other changes were rejected by the same ruler, under one rule fixed in adv
351
416
  | `sqlite-vec` (vec0) | full scan 11.99 s vs 0.14 s for a plain SQLite table, and its ANN missed 1.2 hits of 60 -> vectors live in SQLite, **the extension does not** |
352
417
  | bi-temporal demotion of superseded notes | temporal +0.130 nDCG on a 41-question temporal set, but title −0.012 -> **merged behind a flag, default off** (in the home pipeline, not in this package) |
353
418
 
419
+ The two rows marked "home pipeline" are not in this package: BM25 fusion and superseded-note
420
+ demotion exist only in the maintainer's home build. Check it yourself in a clone:
421
+ `grep -rniE 'bm25|superseded' src/` prints nothing. The PageRank lane above is the one
422
+ merged change that ships (`src/sqlite_graph_memory/ppr.py`).
423
+
354
424
  None of those verdicts is a claim about the models. They are claims about *this corpus with
355
425
  this ruler*, which is the only kind of claim a swap decision actually needs — and the reason
356
426
  the module is here rather than in a blog post is that your corpus will disagree with ours.
@@ -371,7 +441,7 @@ while the metric is broken never tested the metric.
371
441
 
372
442
  ## Roadmap
373
443
 
374
- **Now — [latest release](https://github.com/tonydzi/sqlite-graph-memory/releases/latest)** (v0.3.1 on PyPI and in the MCP Registry as of 2026-10-19).
444
+ **Now — [latest release](https://github.com/tonydzi/sqlite-graph-memory/releases/latest)** (the version badge above is the one on PyPI; the same version is in the MCP Registry).
375
445
  The pilot as it runs daily: retrieval pipeline, per-turn ledger and A/B telemetry, all in
376
446
  `brain_ask.py` and `turnstate_hook.py`, plus the bi-temporal design note. Known defects live in
377
447
  the [tracker](https://github.com/tonydzi/sqlite-graph-memory/issues) rather than in footnotes
@@ -390,7 +460,8 @@ does not notice, and that drift is the defect this paragraph used to carry twice
390
460
  materialize the graph instead of parsing it at query time, give every edge a validity
391
461
  window (`valid_from` / `valid_to` / `observed_at`) so a rebuild *closes* superseded facts
392
462
  instead of deleting them: history is kept, recall prefers the present, and `as_of` queries
393
- can reconstruct the past. Non-destructive aging by confidence decay. The day-1 A/B result
463
+ can reconstruct the past. Non-destructive aging by confidence decay. None of this is in
464
+ the package yet: it is a design note plus a home-pipeline experiment. The day-1 A/B result
394
465
  — context size ~unchanged, retrieved candidates ~60% fresher by mean age — is written up
395
466
  with its caveats in `docs/bitemporal.md`: the volume win is longitudinal, so that is one
396
467
  day on one corpus, not a benchmark.
@@ -445,6 +516,7 @@ Questions, war stories, or you want to run this on your own fleet:
445
516
  You tried this on your own notes and something was missing or broke. That is the most useful
446
517
  thing anyone can tell us.
447
518
 
519
+ - **Install or first run gone wrong:** run `sgm-doctor` first. It checks Python, numpy, torch, the models and your index in plain words and prints the fix for each.
448
520
  - **You started and it did not work:** [open the 3-question form](https://github.com/tonydzi/sqlite-graph-memory/issues/new?template=feature_request.yml) (what you tried, what broke, which machine).
449
521
  - **Not sure it is a bug, or just an idea:** [Discussions → Ideas](https://github.com/tonydzi/sqlite-graph-memory/discussions/categories/ideas).
450
522
 
@@ -161,7 +161,8 @@ bench/
161
161
  run.py run one system -> results/<name>.json
162
162
  validate.py the CI gate (+ --selftest, --reproduce)
163
163
  leaderboard.py results/*.json -> LEADERBOARD.md
164
- adapters/ template.py, bm25.py, sgm.py (+ _extract.py, the shared answer floor)
164
+ adapters/ template.py, bm25.py, sgm.py, sqlite_fts5.py, second_brain.py,
165
+ mem0_local.py, fidelis_memory.py (+ _extract.py, the shared answer floor)
165
166
  results/ one JSON per system
166
167
  ```
167
168
 
Binary file
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env bash
2
+ # Renders docs/demo.gif, the clip at the top of the README. Real run, output not edited.
3
+ #
4
+ # pip install 'sqlite-graph-memory[embeddings]' # sgm-index and sgm-ask on PATH
5
+ # uvx --from 'asciinema<3' asciinema rec --cols 104 --rows 36 -c 'bash docs/demo.sh' demo.cast
6
+ # agg --idle-time-limit 2 --last-frame-duration 10 --font-size 16 --theme monokai demo.cast docs/demo.gif
7
+ #
8
+ # The only cut is agg's idle-time limit: on an x86_64 Mac CPU the embedding pass
9
+ # takes about a minute and prints nothing (the progress bar is off), so the gif
10
+ # skips that silence. The query is the one from "Three commands" in the README.
11
+ set -e
12
+ export TQDM_DISABLE=1 SGM_NO_STAR_PROMPT=1 TOKENIZERS_PARALLELISM=false
13
+ demo=$(mktemp -d)
14
+ cp -R "$(dirname "$0")/../bench/vault" "$demo/notes"
15
+ cd "$demo"
16
+
17
+ say() { # print a command as if typed, then run it
18
+ printf '\033[1;32m$\033[0m '
19
+ for ((i = 0; i < ${#1}; i++)); do printf '%s' "${1:i:1}"; sleep 0.045; done
20
+ echo; sleep 0.4
21
+ eval "$1" 2>/dev/null # model-loading warnings go to stderr
22
+ }
23
+
24
+ clear
25
+ printf '\033[2m# 202 markdown notes that link to each other with [[wikilinks]]\033[0m\n'
26
+ sleep 1.5
27
+ say 'sgm-index ./notes'
28
+ sleep 2
29
+ echo
30
+ say "sgm-ask --ab 'In which programming language is the tool behind Project Ouzel written?'"
31
+ sleep 1.5
32
+ printf '\n\033[2m# the answer is in tool-lanternfish; only the graph hop from project-ouzel reaches it\033[0m\n'
33
+ sleep 2
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "sqlite-graph-memory"
7
- version = "0.3.3"
7
+ version = "0.3.6"
8
8
  description = "Associative memory for LLM agents: Graph RAG over a folder of markdown notes, in one SQLite file, with no server to run."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
@@ -40,6 +40,15 @@ classifiers = [
40
40
  dependencies = ["numpy>=1.24"]
41
41
 
42
42
  [project.optional-dependencies]
43
+ # The same two models on ONNX Runtime, no torch: ~60 MB instead of ~2 GB, and a recall
44
+ # that starts in seconds on a CPU laptop. Measured 2026-11-01 through the MCP server on
45
+ # Windows: `import torch` alone took 44 s and the client hit its 60 s tool timeout.
46
+ # brain_ask picks this stack automatically when it is installed (SGM_BACKEND overrides).
47
+ lite = [
48
+ "onnxruntime>=1.17",
49
+ "tokenizers>=0.15",
50
+ "huggingface_hub>=0.20",
51
+ ]
43
52
  # The indexer and the reranker need these; the graph half, the SQLite schema and
44
53
  # the turnstate memory do not. Kept out of the base install so that
45
54
  # `pip install sqlite-graph-memory` stays a two-second, ~20 MB operation instead
@@ -72,6 +81,7 @@ sgm-stats = "sqlite_graph_memory.vault_stats:main"
72
81
  sgm-turnstate-hook = "sqlite_graph_memory.turnstate_hook:main"
73
82
  sgm-turnstate-show = "sqlite_graph_memory.turnstate_show:main"
74
83
  sgm-mcp = "sqlite_graph_memory.mcp_server:main"
84
+ sgm-doctor = "sqlite_graph_memory.doctor:main"
75
85
  # Same server under the package's own name, so `uvx sqlite-graph-memory` (what MCP
76
86
  # registry clients run for a PyPI package) starts it without a --from flag.
77
87
  sqlite-graph-memory = "sqlite_graph_memory.mcp_server:main"
@@ -21,6 +21,6 @@ the indexer and the reranker will tell you what is missing instead of failing
21
21
  on an ``ImportError`` at startup.
22
22
  """
23
23
 
24
- __version__ = "0.3.3"
24
+ __version__ = "0.3.6"
25
25
 
26
26
  __all__ = ["__version__"]