sqlite-graph-memory 0.3.5__tar.gz → 0.3.7__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.
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/CHANGELOG.md +36 -0
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/PKG-INFO +87 -26
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/README.md +82 -25
- sqlite_graph_memory-0.3.7/docs/demo.gif +0 -0
- sqlite_graph_memory-0.3.7/docs/demo.sh +44 -0
- sqlite_graph_memory-0.3.7/eval/run_ablation.py +267 -0
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/eval/run_eval.py +9 -5
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/examples/README.md +1 -1
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/examples/mcp-config.json +1 -1
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/pyproject.toml +10 -1
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/src/sqlite_graph_memory/__init__.py +1 -1
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/src/sqlite_graph_memory/brain_ask.py +181 -19
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/src/sqlite_graph_memory/doctor.py +12 -1
- sqlite_graph_memory-0.3.7/src/sqlite_graph_memory/index_notes.py +280 -0
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/src/sqlite_graph_memory/mcp_server.py +1 -1
- sqlite_graph_memory-0.3.7/src/sqlite_graph_memory/onnx_backend.py +127 -0
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/src/sqlite_graph_memory/turnstate_show.py +14 -6
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/src/sqlite_graph_memory/vault_stats.py +27 -5
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/tests/test_bench.py +44 -0
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/tests/test_brain_ask.py +82 -0
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/tests/test_doctor.py +25 -1
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/tests/test_eval.py +169 -1
- sqlite_graph_memory-0.3.7/tests/test_incremental_index.py +307 -0
- sqlite_graph_memory-0.3.7/tests/test_onnx_backend.py +168 -0
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/tests/test_optional_extra.py +2 -0
- sqlite_graph_memory-0.3.7/tests/test_rerank_default.py +53 -0
- sqlite_graph_memory-0.3.7/tests/test_rerank_flag_eval.py +22 -0
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/tests/test_star_prompt.py +1 -1
- sqlite_graph_memory-0.3.7/tests/test_turnstate_show.py +52 -0
- sqlite_graph_memory-0.3.7/tests/test_uvx_python_pin.py +75 -0
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/tests/test_vault_stats.py +58 -1
- sqlite_graph_memory-0.3.7/tests/test_version_consistent.py +75 -0
- sqlite_graph_memory-0.3.7/tests/test_version_flag.py +36 -0
- sqlite_graph_memory-0.3.5/docs/demo.gif +0 -0
- sqlite_graph_memory-0.3.5/docs/demo.sh +0 -33
- sqlite_graph_memory-0.3.5/src/sqlite_graph_memory/index_notes.py +0 -151
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/.gitignore +0 -0
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/CITATION.cff +0 -0
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/LICENSE +0 -0
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/bench/README.md +0 -0
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/bench/requirements.txt +0 -0
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/docs/RELEASING.md +0 -0
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/docs/bitemporal.md +0 -0
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/eval/build_gold.py +0 -0
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/examples/claude-code-stop-hook.json +0 -0
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/requirements.txt +0 -0
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/src/sqlite_graph_memory/ppr.py +0 -0
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/src/sqlite_graph_memory/schema.sql +0 -0
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/src/sqlite_graph_memory/turnstate_hook.py +0 -0
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/tests/test_changelog_released.py +0 -0
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/tests/test_feedback_link.py +0 -0
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/tests/test_index_notes.py +0 -0
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/tests/test_index_notes_dotfiles.py +0 -0
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/tests/test_llms_txt.py +0 -0
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/tests/test_mcp_script_mode.py +0 -0
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/tests/test_mcp_server.py +0 -0
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/tests/test_ppr.py +0 -0
- {sqlite_graph_memory-0.3.5 → sqlite_graph_memory-0.3.7}/tests/test_turnstate_hook.py +0 -0
|
@@ -6,6 +6,42 @@ recorded after the fact rather than backdated to look contemporaneous.
|
|
|
6
6
|
|
|
7
7
|
## Unreleased
|
|
8
8
|
|
|
9
|
+
## v0.3.7 - 2026-11-05
|
|
10
|
+
|
|
11
|
+
**Recall: the cross-encoder rerank is off by default.** `sgm-ask`, the MCP tool and `eval/run_eval.py` now order candidates by dense e5 similarity; `--rerank` or `SGM_RERANK=1` brings the cross-encoder back. Measured before the change: on our 184-question gold set the reranker cut body nDCG@12 from 0.815 to 0.640, and on DolphinBench data (Riley, 50 tests, 1000 sessions) Recall@5 fell from 0.61 to 0.48; it still helped short title-style queries. Dense recall is also faster on CPU (about 0.04 s against 2.8 s per query on that slice). `rerank_candidates()` takes `sims=` and keeps dense order when no cross-encoder is passed.
|
|
12
|
+
|
|
13
|
+
**`uvx` install lines work on a newer default Python.** On an Intel Mac whose `uv` defaults to Python
|
|
14
|
+
3.14, `uvx --from 'sqlite-graph-memory[lite]' ...` fell back to release 0.3.5, which has no `[lite]`, and
|
|
15
|
+
`sgm-index` stopped with a hint to install `[embeddings]`. Apple Silicon below macOS 14 resolves the same
|
|
16
|
+
way. The `uvx` lines in the docs now pin `--python 3.12`; `server.json` does too, and that reaches the MCP
|
|
17
|
+
Registry with this release.
|
|
18
|
+
|
|
19
|
+
**Shorter demo gif.** It now shows the top 5 of each list, so the graph hit fits on one screen.
|
|
20
|
+
|
|
21
|
+
**`sgm-index`: a rerun re-embeds only what changed.** A manifest keyed on the content hash and the index settings lets `sgm-index` skip untouched notes; size and mtime are the fast path, the hash decides the changed set, and a corrupt manifest falls back to a full build. The default encoder still comes from `load_encoder()`, so `[lite]` installs keep working without torch. Thanks @Jason-Vaughan (#85), who picked up #17.
|
|
22
|
+
|
|
23
|
+
**Recall: folder-style wikilinks resolve in the graph hop.** `[[folder/note]]` links now reach their note in `expand_1hop` the same way `sgm-stats` counts them, preferring the exact vault-relative path; the vault root is computed once per index, not per link. Thanks @Jason-Vaughan (#84), who picked up #71.
|
|
24
|
+
|
|
25
|
+
**Bench: `tangleclaw-style` reference row.** A stdlib-only pipeline (BM25 + FTS5 + 1-hop wikilinks + `superseded_by` lineage) in the style of TangleClaw's markdown continuity, reproduced in CI. Same R@5 as bm25; its gain is on superseded decisions and abstention, with no domain words in the abstention gate. Thanks @Jason-Vaughan (#87), who picked up #21.
|
|
26
|
+
|
|
27
|
+
**`eval/run_ablation.py`: one run sweeps the retrieval knobs.** Scores a grid of cells (`hops`, `ghops`, `gmax`, `topk`, entity gate) on one gold file, reusing the same pipeline functions as `sgm-ask` and the metrics from `run_eval.py`; the dense pass runs once per question and each cell slices the widest pool, so only the rerank repeats. The default grid changes one axis at a time against `1-hop`; `--grid` takes multi-axis cells. Thanks @Jason-Vaughan (#86), who picked up #19.
|
|
28
|
+
|
|
29
|
+
**Light backend: a fallback to torch is no longer silent.** When the ONNX models fail to load and recall falls back to torch, the answer now starts with a `NOTE:` line naming the reason and pointing at `sgm-doctor`. Through MCP the agent sees only the answer, so the stderr line alone hid the slow path (#89).
|
|
30
|
+
|
|
31
|
+
**Docs: install commands use `[lite]`.** Now that v0.3.6 is on PyPI with the `[lite]` extra, README, llms.txt and the example MCP config install the torch-free stack; `[embeddings]` stays documented for a GPU.
|
|
32
|
+
|
|
33
|
+
## v0.3.6 - 2026-11-03
|
|
34
|
+
|
|
35
|
+
**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.
|
|
36
|
+
|
|
37
|
+
**`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.
|
|
38
|
+
|
|
39
|
+
**`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.
|
|
40
|
+
|
|
41
|
+
**`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.
|
|
42
|
+
|
|
43
|
+
**`--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.
|
|
44
|
+
|
|
9
45
|
## v0.3.5 - 2026-11-01
|
|
10
46
|
|
|
11
47
|
**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.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: sqlite-graph-memory
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.7
|
|
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,6 +47,10 @@ 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
|
|
@@ -69,14 +73,18 @@ One SQLite file, no graph database, no ETL pass, no server.**
|
|
|
69
73
|
|
|
70
74
|
## Install in your client
|
|
71
75
|
|
|
72
|
-
Already using your own agent rules and projects? The [Russian existing-setup guide
|
|
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.
|
|
73
77
|
|
|
74
78
|
Build the index once (any folder of markdown; [`uv`](https://docs.astral.sh/uv/) gives you `uvx`):
|
|
75
79
|
|
|
76
80
|
```bash
|
|
77
|
-
BRAIN_INDEX_DIR=$HOME/.sgm-index uvx --from 'sqlite-graph-memory[
|
|
81
|
+
BRAIN_INDEX_DIR=$HOME/.sgm-index uvx --python 3.12 --from 'sqlite-graph-memory[lite]' sgm-index ~/notes
|
|
78
82
|
```
|
|
79
83
|
|
|
84
|
+
`--python 3.12` is deliberate. onnxruntime has no wheels for Python 3.14 on an Intel Mac, or on
|
|
85
|
+
Apple Silicon below macOS 14. On such a machine an unpinned `uvx` falls back to release 0.3.5,
|
|
86
|
+
which has no `[lite]`, and `sgm-index` then stops and asks for `[embeddings]`.
|
|
87
|
+
|
|
80
88
|
Then point your client at the server. Use the absolute path of that index folder.
|
|
81
89
|
|
|
82
90
|
**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.
|
|
@@ -84,7 +92,7 @@ Then point your client at the server. Use the absolute path of that index folder
|
|
|
84
92
|
**Claude Code**
|
|
85
93
|
|
|
86
94
|
```bash
|
|
87
|
-
claude mcp add sqlite-graph-memory -e BRAIN_INDEX_DIR=$HOME/.sgm-index -- uvx --with 'sqlite-graph-memory[
|
|
95
|
+
claude mcp add sqlite-graph-memory -e BRAIN_INDEX_DIR=$HOME/.sgm-index -- uvx --python 3.12 --with 'sqlite-graph-memory[lite]' sqlite-graph-memory
|
|
88
96
|
```
|
|
89
97
|
|
|
90
98
|
**Cursor** (`~/.cursor/mcp.json`; Claude Desktop, Zed and Windsurf take the same `mcpServers` block)
|
|
@@ -94,7 +102,7 @@ claude mcp add sqlite-graph-memory -e BRAIN_INDEX_DIR=$HOME/.sgm-index -- uvx --
|
|
|
94
102
|
"mcpServers": {
|
|
95
103
|
"sqlite-graph-memory": {
|
|
96
104
|
"command": "uvx",
|
|
97
|
-
"args": ["--with", "sqlite-graph-memory[
|
|
105
|
+
"args": ["--python", "3.12", "--with", "sqlite-graph-memory[lite]", "sqlite-graph-memory"],
|
|
98
106
|
"env": { "BRAIN_INDEX_DIR": "/absolute/path/to/.sgm-index" }
|
|
99
107
|
}
|
|
100
108
|
}
|
|
@@ -109,7 +117,7 @@ claude mcp add sqlite-graph-memory -e BRAIN_INDEX_DIR=$HOME/.sgm-index -- uvx --
|
|
|
109
117
|
"sqlite-graph-memory": {
|
|
110
118
|
"type": "stdio",
|
|
111
119
|
"command": "uvx",
|
|
112
|
-
"args": ["--with", "sqlite-graph-memory[
|
|
120
|
+
"args": ["--python", "3.12", "--with", "sqlite-graph-memory[lite]", "sqlite-graph-memory"],
|
|
113
121
|
"env": { "BRAIN_INDEX_DIR": "/absolute/path/to/.sgm-index" }
|
|
114
122
|
}
|
|
115
123
|
}
|
|
@@ -121,27 +129,37 @@ claude mcp add sqlite-graph-memory -e BRAIN_INDEX_DIR=$HOME/.sgm-index -- uvx --
|
|
|
121
129
|
```toml
|
|
122
130
|
[mcp_servers.sqlite-graph-memory]
|
|
123
131
|
command = "uvx"
|
|
124
|
-
args = ["--with", "sqlite-graph-memory[
|
|
132
|
+
args = ["--python", "3.12", "--with", "sqlite-graph-memory[lite]", "sqlite-graph-memory"]
|
|
125
133
|
env = { BRAIN_INDEX_DIR = "/absolute/path/to/.sgm-index" }
|
|
126
134
|
```
|
|
127
135
|
|
|
128
136
|
Size, `du -sh` of a fresh Python 3.12 venv on an x86_64 Mac (1 Nov 2026): the base install is
|
|
129
137
|
26 MB and has no torch (numpy only, enough for the graph half and the SQLite ledger);
|
|
130
|
-
with `[embeddings]
|
|
131
|
-
|
|
132
|
-
|
|
138
|
+
with `[embeddings]` (torch) it is 879 MB, 540 MB of that torch 2.2.2 CPU. With `[lite]`,
|
|
139
|
+
the same two models on ONNX Runtime and no torch, it is 155 MB (Windows, Python 3.12,
|
|
140
|
+
3 Nov 2026), installs in 12 s, and one MCP recall on the 202-note bench vault took 7.0 s
|
|
141
|
+
against 33.8 s through torch on the same machine, with the same top hits and scores.
|
|
142
|
+
`[lite]` is picked automatically when installed; `SGM_BACKEND=torch` forces torch (for a GPU).
|
|
143
|
+
An index built by either backend is searched correctly by the other.
|
|
144
|
+
Already installed with pip? Replace `uvx --python 3.12 --with ... sqlite-graph-memory` by `sgm-mcp`
|
|
133
145
|
([`examples/mcp-config.json`](examples/mcp-config.json)). Agents that read files first:
|
|
134
146
|
[`llms.txt`](llms.txt).
|
|
135
147
|
|
|
136
148
|
## Three commands
|
|
137
149
|
|
|
138
150
|
```bash
|
|
139
|
-
pip install 'sqlite-graph-memory[
|
|
151
|
+
pip install 'sqlite-graph-memory[lite]'
|
|
140
152
|
sgm-index ./notes
|
|
141
153
|
sgm-ask --ab "In which programming language is the tool behind Project Ouzel written?"
|
|
142
154
|
```
|
|
143
155
|
|
|
144
|
-
|
|
156
|
+
On an Intel Mac, use Python 3.12 with `pip install`. On a newer Python it can quietly install 0.3.5, which has no `[lite]`.
|
|
157
|
+
|
|
158
|
+
`./notes` is any folder of markdown notes. Re-running `sgm-index` only re-embeds notes
|
|
159
|
+
that are new or changed since the last run (tracked by a manifest next to the index);
|
|
160
|
+
pass `--full` to force a complete rebuild.
|
|
161
|
+
|
|
162
|
+
To get exactly the output below, use the
|
|
145
163
|
202-note synthetic vault from this repo (it is not inside the pip package):
|
|
146
164
|
|
|
147
165
|
```bash
|
|
@@ -183,8 +201,9 @@ exists so you can measure which one wins on your own notes.
|
|
|
183
201
|
|
|
184
202
|
Graph RAG on SQLite for AI agents — a working pilot, not a framework. It is the extracted
|
|
185
203
|
memory layer of a personal "second brain" agent setup: vector search finds the entry
|
|
186
|
-
points, the `[[wikilinks]]` you already wrote by hand are the graph, and
|
|
187
|
-
|
|
204
|
+
points, the `[[wikilinks]]` you already wrote by hand are the graph, and dense similarity
|
|
205
|
+
orders what the hop dragged in (a cross-encoder rerank is opt-in with `--rerank`; see below
|
|
206
|
+
for why it is no longer the default).
|
|
188
207
|
SQLite is the only database ([`schema.sql`](src/sqlite_graph_memory/schema.sql)).
|
|
189
208
|
|
|
190
209
|
Status: **pilot**, and the word is load-bearing: it runs daily in one real setup (an index of ~28k curated notes, ~93k chunks, rebuilt nightly from a ~270k-file
|
|
@@ -207,12 +226,14 @@ For a single-user agent over a markdown knowledge base, all three are overkill:
|
|
|
207
226
|
- **SQLite is enough** — the only things worth persisting are derived state (a per-turn
|
|
208
227
|
ledger) and telemetry, and both are defined in [`schema.sql`](src/sqlite_graph_memory/schema.sql).
|
|
209
228
|
One file, stdlib driver, zero ops.
|
|
210
|
-
-
|
|
211
|
-
|
|
229
|
+
- **Measure before adding a stage.** The pilot shipped a cross-encoder reranker from day one;
|
|
230
|
+
measured later, it lowered recall on long queries (our 184-question gold set: body nDCG@12
|
|
231
|
+
0.640 reranked vs 0.815 dense; DolphinBench Riley slice, 1000 sessions: R@5 0.48 vs 0.61).
|
|
232
|
+
Since 0.3.7 it is off by default and stays available as `--rerank` / `SGM_RERANK=1`.
|
|
212
233
|
|
|
213
234
|
So the pilot's bet: *vector retrieval for entry points, hand-curated wikilinks for
|
|
214
|
-
association,
|
|
215
|
-
|
|
235
|
+
association, SQLite for everything that must persist.* All steps live in one file,
|
|
236
|
+
`brain_ask.py`, in that order.
|
|
216
237
|
|
|
217
238
|
## Architecture
|
|
218
239
|
|
|
@@ -226,7 +247,8 @@ markdown notes (with [[wikilinks]])
|
|
|
226
247
|
├── brain_ask.py recall pipeline:
|
|
227
248
|
│ 1. dense retrieve top-60 chunks, dedup by file
|
|
228
249
|
│ 2. --graph +1-hop wikilink neighbours of top-15 hits (max 40)
|
|
229
|
-
│ 3.
|
|
250
|
+
│ 3. order dense similarity → top-12
|
|
251
|
+
│ (--rerank: cross-encoder instead, opt-in)
|
|
230
252
|
│ 4. --ab run vector-only AND vector+graph, diff,
|
|
231
253
|
│ log the delta to SQLite (ab_recall)
|
|
232
254
|
│
|
|
@@ -245,7 +267,7 @@ an edge table only when hop depth or corpus size demands it.
|
|
|
245
267
|
### Design choices that survived contact with reality
|
|
246
268
|
|
|
247
269
|
- **Graph expansion is candidate generation, not ranking** (`brain_ask.py`). Neighbours go
|
|
248
|
-
into the same
|
|
270
|
+
into the same ranking pool as vector hits, so an irrelevant linked note gets buried.
|
|
249
271
|
That is what makes 1-hop expansion safe to leave on.
|
|
250
272
|
- **Entity gate** (`looks_like_entity` in `brain_ask.py`). A/B telemetry showed graph
|
|
251
273
|
expansion helps *theme* queries ("approaches to agent memory") but hurts *name/tool*
|
|
@@ -264,7 +286,7 @@ an edge table only when hop depth or corpus size demands it.
|
|
|
264
286
|
|
|
265
287
|
- No entity lane. The production setup has an extra retrieval lane over people/project
|
|
266
288
|
cards; it is too entangled with personal data to publish.
|
|
267
|
-
-
|
|
289
|
+
- Packaging exists since v0.3.0 (`pip install sqlite-graph-memory`). There IS an eval suite now — see
|
|
268
290
|
[Measure before you swap](#measure-before-you-swap--eval) — but it scores retrieval on
|
|
269
291
|
wikilink-derived gold, which is weak supervision and says so out loud. Test coverage is uneven:
|
|
270
292
|
`index_notes.py`, `brain_ask.py` and `mcp_server.py` have unit tests, and
|
|
@@ -276,10 +298,10 @@ an edge table only when hop depth or corpus size demands it.
|
|
|
276
298
|
## Quickstart
|
|
277
299
|
|
|
278
300
|
```bash
|
|
279
|
-
# Indexing and reranking need
|
|
280
|
-
#
|
|
281
|
-
#
|
|
282
|
-
pip install 'sqlite-graph-memory[
|
|
301
|
+
# Indexing and reranking need an embedding stack; the base install leaves it out.
|
|
302
|
+
# [lite] runs the models on ONNX Runtime without torch (~155 MB); [embeddings]
|
|
303
|
+
# brings torch (~2 GB) if you want a GPU. Ask for one explicitly:
|
|
304
|
+
pip install 'sqlite-graph-memory[lite]'
|
|
283
305
|
|
|
284
306
|
# 1. index a folder of markdown notes
|
|
285
307
|
sgm-index /path/to/notes
|
|
@@ -303,7 +325,7 @@ To enable the per-turn ledger in Claude Code, register the Stop hook (the exact
|
|
|
303
325
|
sgm-turnstate-show --stats
|
|
304
326
|
```
|
|
305
327
|
|
|
306
|
-
Working from a clone instead of an install? `pip install -e '.[
|
|
328
|
+
Working from a clone instead of an install? `pip install -e '.[lite]'` gives you the
|
|
307
329
|
same four commands, and the modules stay importable as
|
|
308
330
|
`from sqlite_graph_memory import brain_ask`.
|
|
309
331
|
|
|
@@ -404,6 +426,45 @@ is what runs. An eval that re-implements the pipeline measures the re-implementa
|
|
|
404
426
|
`--sqlite` appends one row per class and mode to a `gold_eval` table, which is how a run six
|
|
405
427
|
weeks from now can be diffed against today's.
|
|
406
428
|
|
|
429
|
+
### Sweeping the graph-expansion knobs — `eval/run_ablation.py`
|
|
430
|
+
|
|
431
|
+
`run_eval.py` scores one configuration at a time (`vector` vs `graph`). `run_ablation.py`
|
|
432
|
+
sweeps a grid of pipeline parameters — whether the 1-hop graph expansion runs at all
|
|
433
|
+
(`hops`), how many top hits seed it (`ghops`), how many neighbours it admits (`gmax`), the
|
|
434
|
+
dense-retrieve pool size (`topk`), and whether entity/name-shaped queries skip the hop
|
|
435
|
+
(`entity_gate`) — against the **same gold file**, in one run, reusing `brain_ask.py` and
|
|
436
|
+
`run_eval.py`'s own metrics so the sweep can't drift from what `sgm-ask` actually does:
|
|
437
|
+
|
|
438
|
+
```bash
|
|
439
|
+
python eval/run_ablation.py --list-grid # cells only, no model/index load
|
|
440
|
+
python eval/run_ablation.py --gold eval/gold-<today>.jsonl # the built-in 10-cell default grid
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
Each dense embedding is computed once per question and reused across every cell (a cell's
|
|
444
|
+
candidate pool is a slice of the widest pool asked for, not a re-retrieve); only the
|
|
445
|
+
cross-encoder rerank runs per `(question, cell)`, since the candidate set changes per cell.
|
|
446
|
+
The report — printed as a Markdown table and written as both `<prefix>.md` and `<prefix>.csv`
|
|
447
|
+
(`--out <prefix>`, or `--csv`/`--md` directly) — breaks down `n`, `Recall@12`, `MRR`, `nDCG@12`
|
|
448
|
+
and `delta_nDCG@12` (vs the grid's `0-hop` baseline) per `(cell, class)` and `overall`, and
|
|
449
|
+
warns explicitly whenever a class has fewer than 20 questions. The built-in `default`
|
|
450
|
+
10-cell grid varies **one axis at a time** against `1-hop` (`ghops=15, gmax=40, topk=60,
|
|
451
|
+
entity_gate=on`) rather than a full Cartesian product; `--grid` takes `default`, a
|
|
452
|
+
`';'`-separated `key=val` cell list (e.g. `--grid "hops=0;hops=1,ghops=30,gmax=80"` to test
|
|
453
|
+
multi-axis interactions), or a JSON array of cell dicts.
|
|
454
|
+
|
|
455
|
+
Sample run (`intfloat/multilingual-e5-base` + `cross-encoder/mmarco-mMiniLMv2-L12-H384-v1` on CPU) over a 5-note synthetic mini-vault (`12` questions: `5` title, `5` body, `1` bridge, `1` temporal) with `--grid "hops=0,topk=3;hops=1,ghops=2,gmax=5,topk=3,entity_gate=on;hops=1,ghops=2,gmax=5,topk=3,entity_gate=off"`:
|
|
456
|
+
|
|
457
|
+
| cell | class | n | Recall@12 | MRR | nDCG@12 | delta_nDCG@12 |
|
|
458
|
+
|---|---|---:|---:|---:|---:|---:|
|
|
459
|
+
| `cell-0` (`hops=0, topk=3`) | bridge | 1 | 0.500 | 0.500 | 0.387 | +0.000 |
|
|
460
|
+
| `cell-0` (`hops=0, topk=3`) | overall | 12 | 0.958 | 0.903 | 0.907 | +0.000 |
|
|
461
|
+
| `cell-1` (`hops=1, ghops=2, gmax=5, topk=3, gate=on`) | bridge | 1 | 1.000 | 0.500 | 0.693 | +0.307 |
|
|
462
|
+
| `cell-1` (`hops=1, ghops=2, gmax=5, topk=3, gate=on`) | overall | 12 | 1.000 | 0.903 | 0.933 | +0.026 |
|
|
463
|
+
| `cell-2` (`hops=1, ghops=2, gmax=5, topk=3, gate=off`) | bridge | 1 | 1.000 | 0.500 | 0.693 | +0.307 |
|
|
464
|
+
| `cell-2` (`hops=1, ghops=2, gmax=5, topk=3, gate=off`) | overall | 12 | 1.000 | 0.903 | 0.933 | +0.026 |
|
|
465
|
+
|
|
466
|
+
When `topk` is smaller than the vault (`topk=3 < 5` notes), 1-hop `[[wikilink]]` expansion (`cell-1`, `cell-2`) lifts `bridge` Recall@12 from `0.500` to `1.000` (`+0.307` nDCG@12, `+0.026` overall) without regressing `title`, `body`, or `temporal`. On the default 10-cell grid (`topk=20..80 > 5` notes), every cell scores identically (`overall` Recall@12 `1.000`, nDCG@12 `0.929`, `delta_nDCG@12 = +0.000`) because dense retrieval already admits the entire mini-vault before the graph hop runs.
|
|
467
|
+
|
|
407
468
|
### What it cost us to find out
|
|
408
469
|
|
|
409
470
|
Numbers from the home vault (~24k chunks, RU+EN, 2026-09-16), one frozen gold set of 184
|
|
@@ -18,14 +18,18 @@ One SQLite file, no graph database, no ETL pass, no server.**
|
|
|
18
18
|
|
|
19
19
|
## Install in your client
|
|
20
20
|
|
|
21
|
-
Already using your own agent rules and projects? The [Russian existing-setup guide
|
|
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
22
|
|
|
23
23
|
Build the index once (any folder of markdown; [`uv`](https://docs.astral.sh/uv/) gives you `uvx`):
|
|
24
24
|
|
|
25
25
|
```bash
|
|
26
|
-
BRAIN_INDEX_DIR=$HOME/.sgm-index uvx --from 'sqlite-graph-memory[
|
|
26
|
+
BRAIN_INDEX_DIR=$HOME/.sgm-index uvx --python 3.12 --from 'sqlite-graph-memory[lite]' sgm-index ~/notes
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
+
`--python 3.12` is deliberate. onnxruntime has no wheels for Python 3.14 on an Intel Mac, or on
|
|
30
|
+
Apple Silicon below macOS 14. On such a machine an unpinned `uvx` falls back to release 0.3.5,
|
|
31
|
+
which has no `[lite]`, and `sgm-index` then stops and asks for `[embeddings]`.
|
|
32
|
+
|
|
29
33
|
Then point your client at the server. Use the absolute path of that index folder.
|
|
30
34
|
|
|
31
35
|
**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.
|
|
@@ -33,7 +37,7 @@ Then point your client at the server. Use the absolute path of that index folder
|
|
|
33
37
|
**Claude Code**
|
|
34
38
|
|
|
35
39
|
```bash
|
|
36
|
-
claude mcp add sqlite-graph-memory -e BRAIN_INDEX_DIR=$HOME/.sgm-index -- uvx --with 'sqlite-graph-memory[
|
|
40
|
+
claude mcp add sqlite-graph-memory -e BRAIN_INDEX_DIR=$HOME/.sgm-index -- uvx --python 3.12 --with 'sqlite-graph-memory[lite]' sqlite-graph-memory
|
|
37
41
|
```
|
|
38
42
|
|
|
39
43
|
**Cursor** (`~/.cursor/mcp.json`; Claude Desktop, Zed and Windsurf take the same `mcpServers` block)
|
|
@@ -43,7 +47,7 @@ claude mcp add sqlite-graph-memory -e BRAIN_INDEX_DIR=$HOME/.sgm-index -- uvx --
|
|
|
43
47
|
"mcpServers": {
|
|
44
48
|
"sqlite-graph-memory": {
|
|
45
49
|
"command": "uvx",
|
|
46
|
-
"args": ["--with", "sqlite-graph-memory[
|
|
50
|
+
"args": ["--python", "3.12", "--with", "sqlite-graph-memory[lite]", "sqlite-graph-memory"],
|
|
47
51
|
"env": { "BRAIN_INDEX_DIR": "/absolute/path/to/.sgm-index" }
|
|
48
52
|
}
|
|
49
53
|
}
|
|
@@ -58,7 +62,7 @@ claude mcp add sqlite-graph-memory -e BRAIN_INDEX_DIR=$HOME/.sgm-index -- uvx --
|
|
|
58
62
|
"sqlite-graph-memory": {
|
|
59
63
|
"type": "stdio",
|
|
60
64
|
"command": "uvx",
|
|
61
|
-
"args": ["--with", "sqlite-graph-memory[
|
|
65
|
+
"args": ["--python", "3.12", "--with", "sqlite-graph-memory[lite]", "sqlite-graph-memory"],
|
|
62
66
|
"env": { "BRAIN_INDEX_DIR": "/absolute/path/to/.sgm-index" }
|
|
63
67
|
}
|
|
64
68
|
}
|
|
@@ -70,27 +74,37 @@ claude mcp add sqlite-graph-memory -e BRAIN_INDEX_DIR=$HOME/.sgm-index -- uvx --
|
|
|
70
74
|
```toml
|
|
71
75
|
[mcp_servers.sqlite-graph-memory]
|
|
72
76
|
command = "uvx"
|
|
73
|
-
args = ["--with", "sqlite-graph-memory[
|
|
77
|
+
args = ["--python", "3.12", "--with", "sqlite-graph-memory[lite]", "sqlite-graph-memory"]
|
|
74
78
|
env = { BRAIN_INDEX_DIR = "/absolute/path/to/.sgm-index" }
|
|
75
79
|
```
|
|
76
80
|
|
|
77
81
|
Size, `du -sh` of a fresh Python 3.12 venv on an x86_64 Mac (1 Nov 2026): the base install is
|
|
78
82
|
26 MB and has no torch (numpy only, enough for the graph half and the SQLite ledger);
|
|
79
|
-
with `[embeddings]
|
|
80
|
-
|
|
81
|
-
|
|
83
|
+
with `[embeddings]` (torch) it is 879 MB, 540 MB of that torch 2.2.2 CPU. With `[lite]`,
|
|
84
|
+
the same two models on ONNX Runtime and no torch, it is 155 MB (Windows, Python 3.12,
|
|
85
|
+
3 Nov 2026), installs in 12 s, and one MCP recall on the 202-note bench vault took 7.0 s
|
|
86
|
+
against 33.8 s through torch on the same machine, with the same top hits and scores.
|
|
87
|
+
`[lite]` is picked automatically when installed; `SGM_BACKEND=torch` forces torch (for a GPU).
|
|
88
|
+
An index built by either backend is searched correctly by the other.
|
|
89
|
+
Already installed with pip? Replace `uvx --python 3.12 --with ... sqlite-graph-memory` by `sgm-mcp`
|
|
82
90
|
([`examples/mcp-config.json`](examples/mcp-config.json)). Agents that read files first:
|
|
83
91
|
[`llms.txt`](llms.txt).
|
|
84
92
|
|
|
85
93
|
## Three commands
|
|
86
94
|
|
|
87
95
|
```bash
|
|
88
|
-
pip install 'sqlite-graph-memory[
|
|
96
|
+
pip install 'sqlite-graph-memory[lite]'
|
|
89
97
|
sgm-index ./notes
|
|
90
98
|
sgm-ask --ab "In which programming language is the tool behind Project Ouzel written?"
|
|
91
99
|
```
|
|
92
100
|
|
|
93
|
-
|
|
101
|
+
On an Intel Mac, use Python 3.12 with `pip install`. On a newer Python it can quietly install 0.3.5, which has no `[lite]`.
|
|
102
|
+
|
|
103
|
+
`./notes` is any folder of markdown notes. Re-running `sgm-index` only re-embeds notes
|
|
104
|
+
that are new or changed since the last run (tracked by a manifest next to the index);
|
|
105
|
+
pass `--full` to force a complete rebuild.
|
|
106
|
+
|
|
107
|
+
To get exactly the output below, use the
|
|
94
108
|
202-note synthetic vault from this repo (it is not inside the pip package):
|
|
95
109
|
|
|
96
110
|
```bash
|
|
@@ -132,8 +146,9 @@ exists so you can measure which one wins on your own notes.
|
|
|
132
146
|
|
|
133
147
|
Graph RAG on SQLite for AI agents — a working pilot, not a framework. It is the extracted
|
|
134
148
|
memory layer of a personal "second brain" agent setup: vector search finds the entry
|
|
135
|
-
points, the `[[wikilinks]]` you already wrote by hand are the graph, and
|
|
136
|
-
|
|
149
|
+
points, the `[[wikilinks]]` you already wrote by hand are the graph, and dense similarity
|
|
150
|
+
orders what the hop dragged in (a cross-encoder rerank is opt-in with `--rerank`; see below
|
|
151
|
+
for why it is no longer the default).
|
|
137
152
|
SQLite is the only database ([`schema.sql`](src/sqlite_graph_memory/schema.sql)).
|
|
138
153
|
|
|
139
154
|
Status: **pilot**, and the word is load-bearing: it runs daily in one real setup (an index of ~28k curated notes, ~93k chunks, rebuilt nightly from a ~270k-file
|
|
@@ -156,12 +171,14 @@ For a single-user agent over a markdown knowledge base, all three are overkill:
|
|
|
156
171
|
- **SQLite is enough** — the only things worth persisting are derived state (a per-turn
|
|
157
172
|
ledger) and telemetry, and both are defined in [`schema.sql`](src/sqlite_graph_memory/schema.sql).
|
|
158
173
|
One file, stdlib driver, zero ops.
|
|
159
|
-
-
|
|
160
|
-
|
|
174
|
+
- **Measure before adding a stage.** The pilot shipped a cross-encoder reranker from day one;
|
|
175
|
+
measured later, it lowered recall on long queries (our 184-question gold set: body nDCG@12
|
|
176
|
+
0.640 reranked vs 0.815 dense; DolphinBench Riley slice, 1000 sessions: R@5 0.48 vs 0.61).
|
|
177
|
+
Since 0.3.7 it is off by default and stays available as `--rerank` / `SGM_RERANK=1`.
|
|
161
178
|
|
|
162
179
|
So the pilot's bet: *vector retrieval for entry points, hand-curated wikilinks for
|
|
163
|
-
association,
|
|
164
|
-
|
|
180
|
+
association, SQLite for everything that must persist.* All steps live in one file,
|
|
181
|
+
`brain_ask.py`, in that order.
|
|
165
182
|
|
|
166
183
|
## Architecture
|
|
167
184
|
|
|
@@ -175,7 +192,8 @@ markdown notes (with [[wikilinks]])
|
|
|
175
192
|
├── brain_ask.py recall pipeline:
|
|
176
193
|
│ 1. dense retrieve top-60 chunks, dedup by file
|
|
177
194
|
│ 2. --graph +1-hop wikilink neighbours of top-15 hits (max 40)
|
|
178
|
-
│ 3.
|
|
195
|
+
│ 3. order dense similarity → top-12
|
|
196
|
+
│ (--rerank: cross-encoder instead, opt-in)
|
|
179
197
|
│ 4. --ab run vector-only AND vector+graph, diff,
|
|
180
198
|
│ log the delta to SQLite (ab_recall)
|
|
181
199
|
│
|
|
@@ -194,7 +212,7 @@ an edge table only when hop depth or corpus size demands it.
|
|
|
194
212
|
### Design choices that survived contact with reality
|
|
195
213
|
|
|
196
214
|
- **Graph expansion is candidate generation, not ranking** (`brain_ask.py`). Neighbours go
|
|
197
|
-
into the same
|
|
215
|
+
into the same ranking pool as vector hits, so an irrelevant linked note gets buried.
|
|
198
216
|
That is what makes 1-hop expansion safe to leave on.
|
|
199
217
|
- **Entity gate** (`looks_like_entity` in `brain_ask.py`). A/B telemetry showed graph
|
|
200
218
|
expansion helps *theme* queries ("approaches to agent memory") but hurts *name/tool*
|
|
@@ -213,7 +231,7 @@ an edge table only when hop depth or corpus size demands it.
|
|
|
213
231
|
|
|
214
232
|
- No entity lane. The production setup has an extra retrieval lane over people/project
|
|
215
233
|
cards; it is too entangled with personal data to publish.
|
|
216
|
-
-
|
|
234
|
+
- Packaging exists since v0.3.0 (`pip install sqlite-graph-memory`). There IS an eval suite now — see
|
|
217
235
|
[Measure before you swap](#measure-before-you-swap--eval) — but it scores retrieval on
|
|
218
236
|
wikilink-derived gold, which is weak supervision and says so out loud. Test coverage is uneven:
|
|
219
237
|
`index_notes.py`, `brain_ask.py` and `mcp_server.py` have unit tests, and
|
|
@@ -225,10 +243,10 @@ an edge table only when hop depth or corpus size demands it.
|
|
|
225
243
|
## Quickstart
|
|
226
244
|
|
|
227
245
|
```bash
|
|
228
|
-
# Indexing and reranking need
|
|
229
|
-
#
|
|
230
|
-
#
|
|
231
|
-
pip install 'sqlite-graph-memory[
|
|
246
|
+
# Indexing and reranking need an embedding stack; the base install leaves it out.
|
|
247
|
+
# [lite] runs the models on ONNX Runtime without torch (~155 MB); [embeddings]
|
|
248
|
+
# brings torch (~2 GB) if you want a GPU. Ask for one explicitly:
|
|
249
|
+
pip install 'sqlite-graph-memory[lite]'
|
|
232
250
|
|
|
233
251
|
# 1. index a folder of markdown notes
|
|
234
252
|
sgm-index /path/to/notes
|
|
@@ -252,7 +270,7 @@ To enable the per-turn ledger in Claude Code, register the Stop hook (the exact
|
|
|
252
270
|
sgm-turnstate-show --stats
|
|
253
271
|
```
|
|
254
272
|
|
|
255
|
-
Working from a clone instead of an install? `pip install -e '.[
|
|
273
|
+
Working from a clone instead of an install? `pip install -e '.[lite]'` gives you the
|
|
256
274
|
same four commands, and the modules stay importable as
|
|
257
275
|
`from sqlite_graph_memory import brain_ask`.
|
|
258
276
|
|
|
@@ -353,6 +371,45 @@ is what runs. An eval that re-implements the pipeline measures the re-implementa
|
|
|
353
371
|
`--sqlite` appends one row per class and mode to a `gold_eval` table, which is how a run six
|
|
354
372
|
weeks from now can be diffed against today's.
|
|
355
373
|
|
|
374
|
+
### Sweeping the graph-expansion knobs — `eval/run_ablation.py`
|
|
375
|
+
|
|
376
|
+
`run_eval.py` scores one configuration at a time (`vector` vs `graph`). `run_ablation.py`
|
|
377
|
+
sweeps a grid of pipeline parameters — whether the 1-hop graph expansion runs at all
|
|
378
|
+
(`hops`), how many top hits seed it (`ghops`), how many neighbours it admits (`gmax`), the
|
|
379
|
+
dense-retrieve pool size (`topk`), and whether entity/name-shaped queries skip the hop
|
|
380
|
+
(`entity_gate`) — against the **same gold file**, in one run, reusing `brain_ask.py` and
|
|
381
|
+
`run_eval.py`'s own metrics so the sweep can't drift from what `sgm-ask` actually does:
|
|
382
|
+
|
|
383
|
+
```bash
|
|
384
|
+
python eval/run_ablation.py --list-grid # cells only, no model/index load
|
|
385
|
+
python eval/run_ablation.py --gold eval/gold-<today>.jsonl # the built-in 10-cell default grid
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
Each dense embedding is computed once per question and reused across every cell (a cell's
|
|
389
|
+
candidate pool is a slice of the widest pool asked for, not a re-retrieve); only the
|
|
390
|
+
cross-encoder rerank runs per `(question, cell)`, since the candidate set changes per cell.
|
|
391
|
+
The report — printed as a Markdown table and written as both `<prefix>.md` and `<prefix>.csv`
|
|
392
|
+
(`--out <prefix>`, or `--csv`/`--md` directly) — breaks down `n`, `Recall@12`, `MRR`, `nDCG@12`
|
|
393
|
+
and `delta_nDCG@12` (vs the grid's `0-hop` baseline) per `(cell, class)` and `overall`, and
|
|
394
|
+
warns explicitly whenever a class has fewer than 20 questions. The built-in `default`
|
|
395
|
+
10-cell grid varies **one axis at a time** against `1-hop` (`ghops=15, gmax=40, topk=60,
|
|
396
|
+
entity_gate=on`) rather than a full Cartesian product; `--grid` takes `default`, a
|
|
397
|
+
`';'`-separated `key=val` cell list (e.g. `--grid "hops=0;hops=1,ghops=30,gmax=80"` to test
|
|
398
|
+
multi-axis interactions), or a JSON array of cell dicts.
|
|
399
|
+
|
|
400
|
+
Sample run (`intfloat/multilingual-e5-base` + `cross-encoder/mmarco-mMiniLMv2-L12-H384-v1` on CPU) over a 5-note synthetic mini-vault (`12` questions: `5` title, `5` body, `1` bridge, `1` temporal) with `--grid "hops=0,topk=3;hops=1,ghops=2,gmax=5,topk=3,entity_gate=on;hops=1,ghops=2,gmax=5,topk=3,entity_gate=off"`:
|
|
401
|
+
|
|
402
|
+
| cell | class | n | Recall@12 | MRR | nDCG@12 | delta_nDCG@12 |
|
|
403
|
+
|---|---|---:|---:|---:|---:|---:|
|
|
404
|
+
| `cell-0` (`hops=0, topk=3`) | bridge | 1 | 0.500 | 0.500 | 0.387 | +0.000 |
|
|
405
|
+
| `cell-0` (`hops=0, topk=3`) | overall | 12 | 0.958 | 0.903 | 0.907 | +0.000 |
|
|
406
|
+
| `cell-1` (`hops=1, ghops=2, gmax=5, topk=3, gate=on`) | bridge | 1 | 1.000 | 0.500 | 0.693 | +0.307 |
|
|
407
|
+
| `cell-1` (`hops=1, ghops=2, gmax=5, topk=3, gate=on`) | overall | 12 | 1.000 | 0.903 | 0.933 | +0.026 |
|
|
408
|
+
| `cell-2` (`hops=1, ghops=2, gmax=5, topk=3, gate=off`) | bridge | 1 | 1.000 | 0.500 | 0.693 | +0.307 |
|
|
409
|
+
| `cell-2` (`hops=1, ghops=2, gmax=5, topk=3, gate=off`) | overall | 12 | 1.000 | 0.903 | 0.933 | +0.026 |
|
|
410
|
+
|
|
411
|
+
When `topk` is smaller than the vault (`topk=3 < 5` notes), 1-hop `[[wikilink]]` expansion (`cell-1`, `cell-2`) lifts `bridge` Recall@12 from `0.500` to `1.000` (`+0.307` nDCG@12, `+0.026` overall) without regressing `title`, `body`, or `temporal`. On the default 10-cell grid (`topk=20..80 > 5` notes), every cell scores identically (`overall` Recall@12 `1.000`, nDCG@12 `0.929`, `delta_nDCG@12 = +0.000`) because dense retrieval already admits the entire mini-vault before the graph hop runs.
|
|
412
|
+
|
|
356
413
|
### What it cost us to find out
|
|
357
414
|
|
|
358
415
|
Numbers from the home vault (~24k chunks, RU+EN, 2026-09-16), one frozen gold set of 184
|
|
Binary file
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Renders docs/demo.gif, the clip at the top of the README. Real run, real numbers.
|
|
3
|
+
#
|
|
4
|
+
# pip install 'sqlite-graph-memory[lite]' # sgm-index and sgm-ask on PATH
|
|
5
|
+
# uvx --python 3.12 --from 'asciinema<3' asciinema rec --cols 100 --rows 22 -c 'bash docs/demo.sh' demo.cast
|
|
6
|
+
# agg --idle-time-limit 2 --last-frame-duration 12 --font-size 16 --theme monokai demo.cast docs/demo.gif
|
|
7
|
+
#
|
|
8
|
+
# Trimmed from the display so the result fits one screen: the indexer's progress lines,
|
|
9
|
+
# the (Direct=...) counts line and ranks 6-12 of each list. Green marks the graph-only hit.
|
|
10
|
+
# Trimmed from the time: agg's idle-time limit skips the silence while the index builds.
|
|
11
|
+
# The query is the one from "Three commands" in the README.
|
|
12
|
+
set -eo pipefail
|
|
13
|
+
for tool in sgm-index sgm-ask; do
|
|
14
|
+
command -v "$tool" > /dev/null || { echo "$tool must be on PATH" >&2; exit 1; }
|
|
15
|
+
done
|
|
16
|
+
export TQDM_DISABLE=1 SGM_NO_STAR_PROMPT=1 TOKENIZERS_PARALLELISM=false
|
|
17
|
+
export TERM="${TERM:-xterm-256color}" # asciinema rec may start without one, and clear needs it
|
|
18
|
+
demo=$(mktemp -d)
|
|
19
|
+
cp -R "$(dirname "$0")/../bench/vault" "$demo/notes"
|
|
20
|
+
cd "$demo"
|
|
21
|
+
|
|
22
|
+
top5() { # keep the title, the list headers and ranks 1-5; green on the graph hit
|
|
23
|
+
awk '/^\(Direct=/ { next }
|
|
24
|
+
/^---|^A\/B/ || /^ [1-5]\. / || /^$/ {
|
|
25
|
+
if (/<== \+graph/) printf "\033[1;32m%s\033[0m\n", $0; else print }'
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
say() { # print a command as if typed, then run it; $2 = optional display filter
|
|
29
|
+
printf '\033[1;32m$\033[0m '
|
|
30
|
+
for ((i = 0; i < ${#1}; i++)); do printf '%s' "${1:i:1}"; sleep 0.03; done
|
|
31
|
+
echo; sleep 0.4
|
|
32
|
+
eval "$1 ${2:+| $2}" 2>/dev/null # model-loading warnings go to stderr
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
clear
|
|
36
|
+
printf '\033[2m# 202 markdown notes that link to each other with [[wikilinks]]\033[0m\n'
|
|
37
|
+
sleep 1.5
|
|
38
|
+
say 'sgm-index ./notes' "grep -v '^ encoded '"
|
|
39
|
+
sleep 2
|
|
40
|
+
echo
|
|
41
|
+
say "sgm-ask --ab 'In which programming language is the tool behind Project Ouzel written?'" top5
|
|
42
|
+
sleep 1.5
|
|
43
|
+
printf '\033[2m# the answer is in tool-lanternfish; only the graph hop from project-ouzel reaches it\033[0m\n'
|
|
44
|
+
sleep 2
|