sqlite-graph-memory 0.3.3__tar.gz → 0.3.5__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.3 → sqlite_graph_memory-0.3.5}/CHANGELOG.md +31 -0
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/PKG-INFO +87 -19
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/README.md +86 -18
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/bench/README.md +2 -1
- sqlite_graph_memory-0.3.5/docs/demo.gif +0 -0
- sqlite_graph_memory-0.3.5/docs/demo.sh +33 -0
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/pyproject.toml +2 -1
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/src/sqlite_graph_memory/__init__.py +1 -1
- sqlite_graph_memory-0.3.5/src/sqlite_graph_memory/doctor.py +133 -0
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/src/sqlite_graph_memory/mcp_server.py +10 -2
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/tests/test_bench.py +43 -0
- sqlite_graph_memory-0.3.5/tests/test_changelog_released.py +146 -0
- sqlite_graph_memory-0.3.5/tests/test_doctor.py +70 -0
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/tests/test_mcp_server.py +38 -2
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/tests/test_star_prompt.py +3 -0
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/.gitignore +0 -0
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/CITATION.cff +0 -0
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/LICENSE +0 -0
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/bench/requirements.txt +0 -0
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/docs/RELEASING.md +0 -0
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/docs/bitemporal.md +0 -0
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/eval/build_gold.py +0 -0
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/eval/run_eval.py +0 -0
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/examples/README.md +0 -0
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/examples/claude-code-stop-hook.json +0 -0
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/examples/mcp-config.json +0 -0
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/requirements.txt +0 -0
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/src/sqlite_graph_memory/brain_ask.py +0 -0
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/src/sqlite_graph_memory/index_notes.py +0 -0
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/src/sqlite_graph_memory/ppr.py +0 -0
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/src/sqlite_graph_memory/schema.sql +0 -0
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/src/sqlite_graph_memory/turnstate_hook.py +0 -0
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/src/sqlite_graph_memory/turnstate_show.py +0 -0
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/src/sqlite_graph_memory/vault_stats.py +0 -0
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/tests/test_brain_ask.py +0 -0
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/tests/test_eval.py +0 -0
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/tests/test_feedback_link.py +0 -0
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/tests/test_index_notes.py +0 -0
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/tests/test_index_notes_dotfiles.py +0 -0
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/tests/test_llms_txt.py +0 -0
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/tests/test_mcp_script_mode.py +0 -0
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/tests/test_optional_extra.py +0 -0
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/tests/test_ppr.py +0 -0
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/tests/test_turnstate_hook.py +0 -0
- {sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/tests/test_vault_stats.py +0 -0
|
@@ -4,6 +4,37 @@ 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.5 - 2026-11-01
|
|
10
|
+
|
|
11
|
+
**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.
|
|
12
|
+
|
|
13
|
+
**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.
|
|
14
|
+
|
|
15
|
+
**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.
|
|
16
|
+
|
|
17
|
+
**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.
|
|
18
|
+
|
|
19
|
+
**`sgm-doctor`: one command that checks a fresh install in plain words.** Python, SQLite, numpy,
|
|
20
|
+
torch and sentence-transformers, the two models in the local cache, and your index, each with an
|
|
21
|
+
ok/warn/fail verdict and the fix printed next to it; exit 1 when anything fails. On an Intel Mac
|
|
22
|
+
with NumPy 2 it names the pairing that crashes indexing instead of a bare import error.
|
|
23
|
+
|
|
24
|
+
## v0.3.4 - 2026-10-31
|
|
25
|
+
|
|
26
|
+
**Credit, written down at last.** Four outside pull requests merged since 19.10 and none was named
|
|
27
|
+
here. Thanks to [@Kaap10](https://github.com/Kaap10): the MCP server now answers non-object JSON
|
|
28
|
+
payloads with `-32600 Invalid Request` instead of failing (#32, closes #22), and finds its
|
|
29
|
+
`brain_ask` sibling and passes a non-zero exit through in test mode (#33, closes #24). Thanks to
|
|
30
|
+
[@Vamsi-2581](https://github.com/Vamsi-2581): a missing embedding index is now reported as an error
|
|
31
|
+
instead of passing silently (#35). Thanks to [@Khushbu677](https://github.com/Khushbu677): tests for
|
|
32
|
+
the turnstate hook's ledger writes (#57). From now on `scripts/credit_gate.py` runs in CI and goes red
|
|
33
|
+
when a merged outside PR has no line here, or when a `@handle` here does not exist; the rules are in
|
|
34
|
+
[CONTRIBUTING.md](CONTRIBUTING.md).
|
|
35
|
+
|
|
36
|
+
**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.
|
|
37
|
+
|
|
7
38
|
## v0.3.3 — 2026-10-26
|
|
8
39
|
|
|
9
40
|
**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
|
+
Version: 0.3.5
|
|
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
|
|
@@ -53,17 +53,86 @@ Description-Content-Type: text/markdown
|
|
|
53
53
|
|
|
54
54
|
<!-- mcp-name: io.github.tonydzi/sqlite-graph-memory -->
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
Your coding agent remembers what you already wrote down, and reaches the note a plain search
|
|
57
|
+
misses by following the links between your notes. It is an MCP server and a CLI over any
|
|
58
|
+
folder of markdown, Obsidian vaults included: `pip install`, point it at the folder, and
|
|
59
|
+
Claude Code, Cursor, Codex or any other MCP client can recall from it.
|
|
57
60
|
|
|
58
|
-
|
|
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.
|
|
61
|
+

|
|
61
62
|
|
|
62
63
|
**Your agent forgets everything between sessions, and plain vector search gives it back
|
|
63
64
|
flat, unrelated chunks. This gives it associative recall over your own markdown notes:
|
|
64
65
|
vector search finds the entry points, the `[[wikilinks]]` you already wrote are the graph.
|
|
65
66
|
One SQLite file, no graph database, no ETL pass, no server.**
|
|
66
67
|
|
|
68
|
+
[](https://pypi.org/project/sqlite-graph-memory/) [](https://github.com/tonydzi/sqlite-graph-memory/actions/workflows/tests.yml) [](https://registry.modelcontextprotocol.io/v0/servers?search=sqlite-graph-memory) [](LICENSE)
|
|
69
|
+
|
|
70
|
+
## Install in your client
|
|
71
|
+
|
|
72
|
+
Already using your own agent rules and projects? The [Russian existing-setup guide (proposed revision)](https://github.com/tonydzi/second-brain-starter-kit/blob/codex/dima-brain-H55019/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
|
+
|
|
74
|
+
Build the index once (any folder of markdown; [`uv`](https://docs.astral.sh/uv/) gives you `uvx`):
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
BRAIN_INDEX_DIR=$HOME/.sgm-index uvx --from 'sqlite-graph-memory[embeddings]' sgm-index ~/notes
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Then point your client at the server. Use the absolute path of that index folder.
|
|
81
|
+
|
|
82
|
+
**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.
|
|
83
|
+
|
|
84
|
+
**Claude Code**
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
claude mcp add sqlite-graph-memory -e BRAIN_INDEX_DIR=$HOME/.sgm-index -- uvx --with 'sqlite-graph-memory[embeddings]' sqlite-graph-memory
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**Cursor** (`~/.cursor/mcp.json`; Claude Desktop, Zed and Windsurf take the same `mcpServers` block)
|
|
91
|
+
|
|
92
|
+
```json
|
|
93
|
+
{
|
|
94
|
+
"mcpServers": {
|
|
95
|
+
"sqlite-graph-memory": {
|
|
96
|
+
"command": "uvx",
|
|
97
|
+
"args": ["--with", "sqlite-graph-memory[embeddings]", "sqlite-graph-memory"],
|
|
98
|
+
"env": { "BRAIN_INDEX_DIR": "/absolute/path/to/.sgm-index" }
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
**VS Code** (`.vscode/mcp.json` in the workspace)
|
|
105
|
+
|
|
106
|
+
```json
|
|
107
|
+
{
|
|
108
|
+
"servers": {
|
|
109
|
+
"sqlite-graph-memory": {
|
|
110
|
+
"type": "stdio",
|
|
111
|
+
"command": "uvx",
|
|
112
|
+
"args": ["--with", "sqlite-graph-memory[embeddings]", "sqlite-graph-memory"],
|
|
113
|
+
"env": { "BRAIN_INDEX_DIR": "/absolute/path/to/.sgm-index" }
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
**Codex** (`~/.codex/config.toml`)
|
|
120
|
+
|
|
121
|
+
```toml
|
|
122
|
+
[mcp_servers.sqlite-graph-memory]
|
|
123
|
+
command = "uvx"
|
|
124
|
+
args = ["--with", "sqlite-graph-memory[embeddings]", "sqlite-graph-memory"]
|
|
125
|
+
env = { BRAIN_INDEX_DIR = "/absolute/path/to/.sgm-index" }
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Size, `du -sh` of a fresh Python 3.12 venv on an x86_64 Mac (1 Nov 2026): the base install is
|
|
129
|
+
26 MB and has no torch (numpy only, enough for the graph half and the SQLite ledger);
|
|
130
|
+
with `[embeddings]`, which indexing and recall need, it is 879 MB, 540 MB of that torch 2.2.2
|
|
131
|
+
CPU. On Linux the default torch wheel brings CUDA libraries and is bigger; not measured here.
|
|
132
|
+
Already installed with pip? Replace `uvx --with ... sqlite-graph-memory` by `sgm-mcp`
|
|
133
|
+
([`examples/mcp-config.json`](examples/mcp-config.json)). Agents that read files first:
|
|
134
|
+
[`llms.txt`](llms.txt).
|
|
135
|
+
|
|
67
136
|
## Three commands
|
|
68
137
|
|
|
69
138
|
```bash
|
|
@@ -110,14 +179,6 @@ That is the idea in one query, and it is not a blanket win. On this same vault v
|
|
|
110
179
|
ranks ahead of graph mode overall; the numbers are in [`bench/`](bench/README.md). `--ab`
|
|
111
180
|
exists so you can measure which one wins on your own notes.
|
|
112
181
|
|
|
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
182
|
## What it is
|
|
122
183
|
|
|
123
184
|
Graph RAG on SQLite for AI agents — a working pilot, not a framework. It is the extracted
|
|
@@ -144,7 +205,7 @@ For a single-user agent over a markdown knowledge base, all three are overkill:
|
|
|
144
205
|
edges as `[[wikilinks]]`, and `brain_ask.py` just parses them.
|
|
145
206
|
No extraction pass, and edge quality beats anything a model would mine.
|
|
146
207
|
- **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).
|
|
208
|
+
ledger) and telemetry, and both are defined in [`schema.sql`](src/sqlite_graph_memory/schema.sql).
|
|
148
209
|
One file, stdlib driver, zero ops.
|
|
149
210
|
- The expensive part of RAG quality is a **reranker**, not graph infrastructure — see the
|
|
150
211
|
rerank step in `brain_ask.py`.
|
|
@@ -176,7 +237,7 @@ markdown notes (with [[wikilinks]])
|
|
|
176
237
|
turnstate_show.py = read-only viewer.
|
|
177
238
|
```
|
|
178
239
|
|
|
179
|
-
[`schema.sql`](schema.sql) documents both tables. The graph is **not** materialized in SQL:
|
|
240
|
+
[`schema.sql`](src/sqlite_graph_memory/schema.sql) documents both tables. The graph is **not** materialized in SQL:
|
|
180
241
|
`brain_ask.py` parses edges from the notes at query time, bounded to 1 hop / 40 neighbours.
|
|
181
242
|
That keeps the graph permanently in sync with the notes at zero maintenance cost; materialize
|
|
182
243
|
an edge table only when hop depth or corpus size demands it.
|
|
@@ -196,7 +257,7 @@ an edge table only when hop depth or corpus size demands it.
|
|
|
196
257
|
vector-only recall, no ledger row.
|
|
197
258
|
A memory layer must never make the agent worse than having no memory layer.
|
|
198
259
|
- **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).
|
|
260
|
+
many notes the graph promoted into the top-N, to `ab_recall` in [`schema.sql`](src/sqlite_graph_memory/schema.sql).
|
|
200
261
|
Whether "associative memory" earns its keep is a weekly SQL query, not a vibe.
|
|
201
262
|
|
|
202
263
|
### What's intentionally missing
|
|
@@ -273,7 +334,7 @@ A/B RECALL: how should agent memory work
|
|
|
273
334
|
|
|
274
335
|
On a corpus this small the graph adds nothing — every note is already in the candidate
|
|
275
336
|
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.
|
|
337
|
+
table in [`schema.sql`](src/sqlite_graph_memory/schema.sql) accumulates evidence for.
|
|
277
338
|
|
|
278
339
|
## Public benchmark — `bench/`
|
|
279
340
|
|
|
@@ -402,6 +463,11 @@ Seven other changes were rejected by the same ruler, under one rule fixed in adv
|
|
|
402
463
|
| `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
464
|
| 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
465
|
|
|
466
|
+
The two rows marked "home pipeline" are not in this package: BM25 fusion and superseded-note
|
|
467
|
+
demotion exist only in the maintainer's home build. Check it yourself in a clone:
|
|
468
|
+
`grep -rniE 'bm25|superseded' src/` prints nothing. The PageRank lane above is the one
|
|
469
|
+
merged change that ships (`src/sqlite_graph_memory/ppr.py`).
|
|
470
|
+
|
|
405
471
|
None of those verdicts is a claim about the models. They are claims about *this corpus with
|
|
406
472
|
this ruler*, which is the only kind of claim a swap decision actually needs — and the reason
|
|
407
473
|
the module is here rather than in a blog post is that your corpus will disagree with ours.
|
|
@@ -422,7 +488,7 @@ while the metric is broken never tested the metric.
|
|
|
422
488
|
|
|
423
489
|
## Roadmap
|
|
424
490
|
|
|
425
|
-
**Now — [latest release](https://github.com/tonydzi/sqlite-graph-memory/releases/latest)** (
|
|
491
|
+
**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
492
|
The pilot as it runs daily: retrieval pipeline, per-turn ledger and A/B telemetry, all in
|
|
427
493
|
`brain_ask.py` and `turnstate_hook.py`, plus the bi-temporal design note. Known defects live in
|
|
428
494
|
the [tracker](https://github.com/tonydzi/sqlite-graph-memory/issues) rather than in footnotes
|
|
@@ -441,7 +507,8 @@ does not notice, and that drift is the defect this paragraph used to carry twice
|
|
|
441
507
|
materialize the graph instead of parsing it at query time, give every edge a validity
|
|
442
508
|
window (`valid_from` / `valid_to` / `observed_at`) so a rebuild *closes* superseded facts
|
|
443
509
|
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.
|
|
510
|
+
can reconstruct the past. Non-destructive aging by confidence decay. None of this is in
|
|
511
|
+
the package yet: it is a design note plus a home-pipeline experiment. The day-1 A/B result
|
|
445
512
|
— context size ~unchanged, retrieved candidates ~60% fresher by mean age — is written up
|
|
446
513
|
with its caveats in `docs/bitemporal.md`: the volume win is longitudinal, so that is one
|
|
447
514
|
day on one corpus, not a benchmark.
|
|
@@ -496,6 +563,7 @@ Questions, war stories, or you want to run this on your own fleet:
|
|
|
496
563
|
You tried this on your own notes and something was missing or broke. That is the most useful
|
|
497
564
|
thing anyone can tell us.
|
|
498
565
|
|
|
566
|
+
- **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
567
|
- **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
568
|
- **Not sure it is a bug, or just an idea:** [Discussions → Ideas](https://github.com/tonydzi/sqlite-graph-memory/discussions/categories/ideas).
|
|
501
569
|
|
|
@@ -2,17 +2,86 @@
|
|
|
2
2
|
|
|
3
3
|
<!-- mcp-name: io.github.tonydzi/sqlite-graph-memory -->
|
|
4
4
|
|
|
5
|
-
|
|
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
|
-
|
|
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
|
+

|
|
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
|
+
[](https://pypi.org/project/sqlite-graph-memory/) [](https://github.com/tonydzi/sqlite-graph-memory/actions/workflows/tests.yml) [](https://registry.modelcontextprotocol.io/v0/servers?search=sqlite-graph-memory) [](LICENSE)
|
|
18
|
+
|
|
19
|
+
## Install in your client
|
|
20
|
+
|
|
21
|
+
Already using your own agent rules and projects? The [Russian existing-setup guide (proposed revision)](https://github.com/tonydzi/second-brain-starter-kit/blob/codex/dima-brain-H55019/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]`, which indexing and recall need, it is 879 MB, 540 MB of that torch 2.2.2
|
|
80
|
+
CPU. On Linux the default torch wheel brings CUDA libraries and is bigger; not measured here.
|
|
81
|
+
Already installed with pip? Replace `uvx --with ... sqlite-graph-memory` by `sgm-mcp`
|
|
82
|
+
([`examples/mcp-config.json`](examples/mcp-config.json)). Agents that read files first:
|
|
83
|
+
[`llms.txt`](llms.txt).
|
|
84
|
+
|
|
16
85
|
## Three commands
|
|
17
86
|
|
|
18
87
|
```bash
|
|
@@ -59,14 +128,6 @@ That is the idea in one query, and it is not a blanket win. On this same vault v
|
|
|
59
128
|
ranks ahead of graph mode overall; the numbers are in [`bench/`](bench/README.md). `--ab`
|
|
60
129
|
exists so you can measure which one wins on your own notes.
|
|
61
130
|
|
|
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
131
|
## What it is
|
|
71
132
|
|
|
72
133
|
Graph RAG on SQLite for AI agents — a working pilot, not a framework. It is the extracted
|
|
@@ -93,7 +154,7 @@ For a single-user agent over a markdown knowledge base, all three are overkill:
|
|
|
93
154
|
edges as `[[wikilinks]]`, and `brain_ask.py` just parses them.
|
|
94
155
|
No extraction pass, and edge quality beats anything a model would mine.
|
|
95
156
|
- **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).
|
|
157
|
+
ledger) and telemetry, and both are defined in [`schema.sql`](src/sqlite_graph_memory/schema.sql).
|
|
97
158
|
One file, stdlib driver, zero ops.
|
|
98
159
|
- The expensive part of RAG quality is a **reranker**, not graph infrastructure — see the
|
|
99
160
|
rerank step in `brain_ask.py`.
|
|
@@ -125,7 +186,7 @@ markdown notes (with [[wikilinks]])
|
|
|
125
186
|
turnstate_show.py = read-only viewer.
|
|
126
187
|
```
|
|
127
188
|
|
|
128
|
-
[`schema.sql`](schema.sql) documents both tables. The graph is **not** materialized in SQL:
|
|
189
|
+
[`schema.sql`](src/sqlite_graph_memory/schema.sql) documents both tables. The graph is **not** materialized in SQL:
|
|
129
190
|
`brain_ask.py` parses edges from the notes at query time, bounded to 1 hop / 40 neighbours.
|
|
130
191
|
That keeps the graph permanently in sync with the notes at zero maintenance cost; materialize
|
|
131
192
|
an edge table only when hop depth or corpus size demands it.
|
|
@@ -145,7 +206,7 @@ an edge table only when hop depth or corpus size demands it.
|
|
|
145
206
|
vector-only recall, no ledger row.
|
|
146
207
|
A memory layer must never make the agent worse than having no memory layer.
|
|
147
208
|
- **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).
|
|
209
|
+
many notes the graph promoted into the top-N, to `ab_recall` in [`schema.sql`](src/sqlite_graph_memory/schema.sql).
|
|
149
210
|
Whether "associative memory" earns its keep is a weekly SQL query, not a vibe.
|
|
150
211
|
|
|
151
212
|
### What's intentionally missing
|
|
@@ -222,7 +283,7 @@ A/B RECALL: how should agent memory work
|
|
|
222
283
|
|
|
223
284
|
On a corpus this small the graph adds nothing — every note is already in the candidate
|
|
224
285
|
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.
|
|
286
|
+
table in [`schema.sql`](src/sqlite_graph_memory/schema.sql) accumulates evidence for.
|
|
226
287
|
|
|
227
288
|
## Public benchmark — `bench/`
|
|
228
289
|
|
|
@@ -351,6 +412,11 @@ Seven other changes were rejected by the same ruler, under one rule fixed in adv
|
|
|
351
412
|
| `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
413
|
| 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
414
|
|
|
415
|
+
The two rows marked "home pipeline" are not in this package: BM25 fusion and superseded-note
|
|
416
|
+
demotion exist only in the maintainer's home build. Check it yourself in a clone:
|
|
417
|
+
`grep -rniE 'bm25|superseded' src/` prints nothing. The PageRank lane above is the one
|
|
418
|
+
merged change that ships (`src/sqlite_graph_memory/ppr.py`).
|
|
419
|
+
|
|
354
420
|
None of those verdicts is a claim about the models. They are claims about *this corpus with
|
|
355
421
|
this ruler*, which is the only kind of claim a swap decision actually needs — and the reason
|
|
356
422
|
the module is here rather than in a blog post is that your corpus will disagree with ours.
|
|
@@ -371,7 +437,7 @@ while the metric is broken never tested the metric.
|
|
|
371
437
|
|
|
372
438
|
## Roadmap
|
|
373
439
|
|
|
374
|
-
**Now — [latest release](https://github.com/tonydzi/sqlite-graph-memory/releases/latest)** (
|
|
440
|
+
**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
441
|
The pilot as it runs daily: retrieval pipeline, per-turn ledger and A/B telemetry, all in
|
|
376
442
|
`brain_ask.py` and `turnstate_hook.py`, plus the bi-temporal design note. Known defects live in
|
|
377
443
|
the [tracker](https://github.com/tonydzi/sqlite-graph-memory/issues) rather than in footnotes
|
|
@@ -390,7 +456,8 @@ does not notice, and that drift is the defect this paragraph used to carry twice
|
|
|
390
456
|
materialize the graph instead of parsing it at query time, give every edge a validity
|
|
391
457
|
window (`valid_from` / `valid_to` / `observed_at`) so a rebuild *closes* superseded facts
|
|
392
458
|
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.
|
|
459
|
+
can reconstruct the past. Non-destructive aging by confidence decay. None of this is in
|
|
460
|
+
the package yet: it is a design note plus a home-pipeline experiment. The day-1 A/B result
|
|
394
461
|
— context size ~unchanged, retrieved candidates ~60% fresher by mean age — is written up
|
|
395
462
|
with its caveats in `docs/bitemporal.md`: the volume win is longitudinal, so that is one
|
|
396
463
|
day on one corpus, not a benchmark.
|
|
@@ -445,6 +512,7 @@ Questions, war stories, or you want to run this on your own fleet:
|
|
|
445
512
|
You tried this on your own notes and something was missing or broke. That is the most useful
|
|
446
513
|
thing anyone can tell us.
|
|
447
514
|
|
|
515
|
+
- **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
516
|
- **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
517
|
- **Not sure it is a bug, or just an idea:** [Discussions → Ideas](https://github.com/tonydzi/sqlite-graph-memory/discussions/categories/ideas).
|
|
450
518
|
|
|
@@ -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
|
|
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.
|
|
7
|
+
version = "0.3.5"
|
|
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"
|
|
@@ -72,6 +72,7 @@ sgm-stats = "sqlite_graph_memory.vault_stats:main"
|
|
|
72
72
|
sgm-turnstate-hook = "sqlite_graph_memory.turnstate_hook:main"
|
|
73
73
|
sgm-turnstate-show = "sqlite_graph_memory.turnstate_show:main"
|
|
74
74
|
sgm-mcp = "sqlite_graph_memory.mcp_server:main"
|
|
75
|
+
sgm-doctor = "sqlite_graph_memory.doctor:main"
|
|
75
76
|
# Same server under the package's own name, so `uvx sqlite-graph-memory` (what MCP
|
|
76
77
|
# registry clients run for a PyPI package) starts it without a --from flag.
|
|
77
78
|
sqlite-graph-memory = "sqlite_graph_memory.mcp_server:main"
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"""sgm-doctor: check this machine in plain words, one command, nothing downloaded.
|
|
2
|
+
|
|
3
|
+
Passport
|
|
4
|
+
in: environment (BRAIN_INDEX_DIR, HF_HOME), the installed packages
|
|
5
|
+
out: one line per check, ok / warn / fail, then a verdict; exit 1 if anything failed
|
|
6
|
+
who: a person who just ran `pip install sqlite-graph-memory` and got an error
|
|
7
|
+
rail: stdlib only. torch is imported inside a try block, because importing it is the check.
|
|
8
|
+
"""
|
|
9
|
+
import os
|
|
10
|
+
import platform
|
|
11
|
+
import sqlite3
|
|
12
|
+
import sys
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
|
|
15
|
+
from sqlite_graph_memory import brain_ask
|
|
16
|
+
|
|
17
|
+
OK, WARN, FAIL = 'ok', 'warn', 'fail'
|
|
18
|
+
MARK = {OK: '[ok] ', WARN: '[warn]', FAIL: '[FAIL]'}
|
|
19
|
+
FEEDBACK = brain_ask.FEEDBACK_URL
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def check_python(version=None):
|
|
23
|
+
v = version or sys.version_info[:3]
|
|
24
|
+
if v < (3, 9):
|
|
25
|
+
return FAIL, 'Python %d.%d.%d is too old.' % v, 'Install Python 3.9 or newer.'
|
|
26
|
+
return OK, 'Python %d.%d.%d.' % v, ''
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def check_numpy():
|
|
30
|
+
try:
|
|
31
|
+
import numpy
|
|
32
|
+
except ModuleNotFoundError:
|
|
33
|
+
return FAIL, 'numpy is not installed.', 'pip install sqlite-graph-memory'
|
|
34
|
+
return OK, 'numpy %s.' % numpy.__version__, ''
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _intel_mac(system=None, machine=None):
|
|
38
|
+
return (system or platform.system()) == 'Darwin' and (machine or platform.machine()) == 'x86_64'
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def check_embeddings(system=None, machine=None):
|
|
42
|
+
"""The heavy half. Without it the graph and the SQLite parts work, indexing and recall do not."""
|
|
43
|
+
try:
|
|
44
|
+
import numpy
|
|
45
|
+
np_major = int(numpy.__version__.split('.')[0])
|
|
46
|
+
except Exception:
|
|
47
|
+
np_major = 0
|
|
48
|
+
try:
|
|
49
|
+
import torch
|
|
50
|
+
import sentence_transformers
|
|
51
|
+
except ModuleNotFoundError as exc:
|
|
52
|
+
return (WARN, 'The embeddings extra is not installed (%s missing).' % exc.name,
|
|
53
|
+
'Only needed to index and recall. Install it with: pip install "sqlite-graph-memory[embeddings]"')
|
|
54
|
+
except Exception as exc: # torch dies at import on a numpy it was not built for
|
|
55
|
+
why = '%s: %s' % (type(exc).__name__, str(exc).splitlines()[0] if str(exc) else '')
|
|
56
|
+
if _intel_mac(system, machine) and np_major >= 2:
|
|
57
|
+
return (FAIL, 'torch cannot start on this Intel Mac with NumPy 2 (%s).' % why,
|
|
58
|
+
'pip install "numpy<2"')
|
|
59
|
+
return FAIL, 'torch or sentence-transformers fails to import (%s).' % why, \
|
|
60
|
+
'Reinstall in a fresh virtualenv: pip install --force-reinstall "sqlite-graph-memory[embeddings]"'
|
|
61
|
+
if _intel_mac(system, machine) and np_major >= 2:
|
|
62
|
+
return (WARN, 'Intel Mac with NumPy 2: torch imported, but this pairing is known to crash while indexing.',
|
|
63
|
+
'pip install "numpy<2"')
|
|
64
|
+
return OK, 'torch %s and sentence-transformers %s import cleanly.' % (
|
|
65
|
+
torch.__version__, sentence_transformers.__version__), ''
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _hf_cache_dirs():
|
|
69
|
+
roots = [os.getenv('HF_HUB_CACHE'), os.getenv('SENTENCE_TRANSFORMERS_HOME')]
|
|
70
|
+
hf_home = os.getenv('HF_HOME') or str(Path.home() / '.cache' / 'huggingface')
|
|
71
|
+
roots.append(str(Path(hf_home) / 'hub'))
|
|
72
|
+
return [Path(r) for r in roots if r]
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def check_models():
|
|
76
|
+
"""Look for the two model folders in the local cache. Never downloads anything."""
|
|
77
|
+
missing = []
|
|
78
|
+
for name in (brain_ask.E5_MODEL, brain_ask.RERANK_MODEL):
|
|
79
|
+
folder = 'models--' + name.replace('/', '--')
|
|
80
|
+
if not any((d / folder).exists() for d in _hf_cache_dirs()):
|
|
81
|
+
missing.append(name)
|
|
82
|
+
if missing:
|
|
83
|
+
return (WARN, 'Not downloaded yet: %s.' % ', '.join(missing),
|
|
84
|
+
'They download on the first index or recall (about 1 GB, needs internet once).')
|
|
85
|
+
return OK, 'Both models are already in the local cache.', ''
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def check_index(index_dir=None):
|
|
89
|
+
d = Path(index_dir) if index_dir else brain_ask.INDEX_DIR
|
|
90
|
+
emb, meta = d / '_brain_e5.npy', d / '_brain_e5_meta.pkl'
|
|
91
|
+
if not emb.exists() and not meta.exists():
|
|
92
|
+
return (WARN, 'No index in %s.' % d.resolve(),
|
|
93
|
+
'Run: sgm-index /path/to/your/notes (set BRAIN_INDEX_DIR to keep the index elsewhere)')
|
|
94
|
+
if emb.exists() != meta.exists():
|
|
95
|
+
left = meta.name if emb.exists() else emb.name
|
|
96
|
+
return FAIL, 'The index is half there: %s is missing.' % left, 'Rebuild it: sgm-index /path/to/your/notes'
|
|
97
|
+
return OK, 'Index found in %s (%.1f MB).' % (d.resolve(), emb.stat().st_size / 1e6), ''
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def check_sqlite():
|
|
101
|
+
return OK, 'SQLite %s.' % sqlite3.sqlite_version, ''
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def run_checks():
|
|
105
|
+
return [('Python', check_python()), ('SQLite', check_sqlite()), ('numpy', check_numpy()),
|
|
106
|
+
('Embeddings', check_embeddings()), ('Models', check_models()), ('Index', check_index())]
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def render(results):
|
|
110
|
+
lines = []
|
|
111
|
+
for name, (status, what, fix) in results:
|
|
112
|
+
lines.append('%s %-10s %s' % (MARK[status], name, what))
|
|
113
|
+
if fix:
|
|
114
|
+
lines.append(' -> %s' % fix)
|
|
115
|
+
fails = sum(1 for _, r in results if r[0] == FAIL)
|
|
116
|
+
warns = sum(1 for _, r in results if r[0] == WARN)
|
|
117
|
+
if fails:
|
|
118
|
+
lines.append('\n%d problem(s) to fix first. Still stuck? Tell us: %s' % (fails, FEEDBACK))
|
|
119
|
+
elif warns:
|
|
120
|
+
lines.append('\nNothing is broken; %d step(s) above are still to do.' % warns)
|
|
121
|
+
else:
|
|
122
|
+
lines.append('\nAll good.')
|
|
123
|
+
return '\n'.join(lines), fails
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def main():
|
|
127
|
+
text, fails = render(run_checks())
|
|
128
|
+
print(text)
|
|
129
|
+
return 1 if fails else 0
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
if __name__ == '__main__':
|
|
133
|
+
sys.exit(main())
|
{sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/src/sqlite_graph_memory/mcp_server.py
RENAMED
|
@@ -18,6 +18,7 @@ Config (env, optional):
|
|
|
18
18
|
BRAIN_INDEX_DIR dir holding embedding index (default: ./index)
|
|
19
19
|
TURNSTATE_DB SQLite db for telemetry (default: ./turnstate.db)
|
|
20
20
|
BRAIN_ANSWER_OUT file to mirror answer into (default: ./_brain_answer.txt)
|
|
21
|
+
BRAIN_RECALL_TIMEOUT recall child timeout in seconds (1..600, default: 180)
|
|
21
22
|
"""
|
|
22
23
|
import sys, os, json, subprocess, tempfile
|
|
23
24
|
from pathlib import Path
|
|
@@ -100,6 +101,13 @@ def run_recall(query: str, mode: str = "associative") -> tuple[str, bool]:
|
|
|
100
101
|
An empty answer file means no notes matched; stdout is never promoted to an answer
|
|
101
102
|
because it carries startup notices, load reports, and tokenizer warnings.
|
|
102
103
|
"""
|
|
104
|
+
try:
|
|
105
|
+
recall_timeout = int(os.environ.get("BRAIN_RECALL_TIMEOUT", "180"))
|
|
106
|
+
if not 1 <= recall_timeout <= 600:
|
|
107
|
+
raise ValueError
|
|
108
|
+
except ValueError:
|
|
109
|
+
return "Recall configuration error: BRAIN_RECALL_TIMEOUT must be an integer from 1 to 600 seconds.", True
|
|
110
|
+
|
|
103
111
|
base_cmd = _brain_ask_cmd()
|
|
104
112
|
if base_cmd is None:
|
|
105
113
|
return (
|
|
@@ -136,7 +144,7 @@ def run_recall(query: str, mode: str = "associative") -> tuple[str, bool]:
|
|
|
136
144
|
text=True,
|
|
137
145
|
encoding="utf-8",
|
|
138
146
|
errors="replace",
|
|
139
|
-
timeout=
|
|
147
|
+
timeout=recall_timeout
|
|
140
148
|
)
|
|
141
149
|
if res.returncode != 0:
|
|
142
150
|
err = (res.stderr or res.stdout or "").strip()
|
|
@@ -153,7 +161,7 @@ def run_recall(query: str, mode: str = "associative") -> tuple[str, bool]:
|
|
|
153
161
|
# Empty answer file: return explicit message and flag error so agent does not ingest stdout noise
|
|
154
162
|
return "(no matching notes found)", True
|
|
155
163
|
except subprocess.TimeoutExpired:
|
|
156
|
-
return "Recall error: timed out after
|
|
164
|
+
return f"Recall error: timed out after {recall_timeout} seconds.", True
|
|
157
165
|
except Exception as e:
|
|
158
166
|
return f"Recall exception: {e}", True
|
|
159
167
|
finally:
|
|
@@ -65,3 +65,46 @@ def test_inflated_number_is_caught():
|
|
|
65
65
|
errs = bc.check_result(r2, bc.load_questions(), bc.load_vault(), bc.tree_sha256(bc.VAULT),
|
|
66
66
|
bc.file_sha256(bc.QUESTIONS), filename=f)
|
|
67
67
|
assert any('answer_acc' in e for e in errs)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def test_adapter_named_after_installed_package_is_refused(tmp_path):
|
|
71
|
+
"""An adapter file named like an installed package (adapters/json.py) shadows it; run.py must say so."""
|
|
72
|
+
import importlib.util
|
|
73
|
+
spec = importlib.util.spec_from_file_location('bench_run_mod', ROOT / 'bench' / 'run.py')
|
|
74
|
+
run = importlib.util.module_from_spec(spec)
|
|
75
|
+
spec.loader.exec_module(run)
|
|
76
|
+
clash = tmp_path / 'json.py'
|
|
77
|
+
clash.write_text("SYSTEMS = {'x': {}}\n")
|
|
78
|
+
assert run.shadowed_package(clash) == 'json'
|
|
79
|
+
assert run.shadowed_package(tmp_path / 'no_such_pkg_zz9.py') is None
|
|
80
|
+
# the adapter's own folder never counts: a module found only there is the adapter itself
|
|
81
|
+
own = tmp_path / 'zz_only_here_9.py'
|
|
82
|
+
own.write_text("SYSTEMS = {'y': {}}\n")
|
|
83
|
+
sys.path.insert(0, str(tmp_path))
|
|
84
|
+
try:
|
|
85
|
+
assert run.shadowed_package(own) is None
|
|
86
|
+
finally:
|
|
87
|
+
sys.path.remove(str(tmp_path))
|
|
88
|
+
assert all(run.shadowed_package(p) is None for p in (ROOT / 'bench' / 'adapters').glob('*.py'))
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def test_ci_needs_picks_only_marked_systems(tmp_path):
|
|
92
|
+
"""The workflow chooses the interpreter per system from `needs:` notes; the badge ignores them."""
|
|
93
|
+
import importlib.util
|
|
94
|
+
spec = importlib.util.spec_from_file_location('bench_ci_needs', ROOT / 'bench' / 'ci_needs.py')
|
|
95
|
+
cn = importlib.util.module_from_spec(spec)
|
|
96
|
+
spec.loader.exec_module(cn)
|
|
97
|
+
f = tmp_path / 'list.txt'
|
|
98
|
+
f.write_text('# header, needs: ollama is only prose here\n'
|
|
99
|
+
'bm25\n'
|
|
100
|
+
'fidelis # needs: ollama\n'
|
|
101
|
+
'both # needs: torch, ollama\n'
|
|
102
|
+
'other # needs: torch\n'
|
|
103
|
+
'prose # not a needs: ollama line\n', encoding='utf-8')
|
|
104
|
+
assert cn.needing('ollama', f) == ['fidelis', 'both']
|
|
105
|
+
assert cn.needing('torch', f) == ['both', 'other']
|
|
106
|
+
assert cn.needing('gpu', f) == []
|
|
107
|
+
# the live list: the two Ollama systems are marked, and both carry the badge
|
|
108
|
+
live = set(cn.needing('ollama'))
|
|
109
|
+
assert live == {'fidelis', 'mem0-local'}
|
|
110
|
+
assert live <= bc.ci_reproduced()
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"""A released CHANGELOG section is frozen.
|
|
2
|
+
|
|
3
|
+
Once `vX.Y.Z` is tagged, its `## vX.Y.Z` section is what PyPI users read as
|
|
4
|
+
"what shipped in that version". On 2026-10-24 the #36 entry landed inside the
|
|
5
|
+
already-released v0.3.2 section, so the changelog claimed v0.3.2 contained a
|
|
6
|
+
change it did not; v0.3.3 (#59) had to move it out by hand. This test compares
|
|
7
|
+
every tagged section at HEAD with the same section in the CHANGELOG as it was
|
|
8
|
+
at the tag, and fails if they differ.
|
|
9
|
+
|
|
10
|
+
New entries belong under a version that has no tag yet. A deliberate edit of a
|
|
11
|
+
released section (a typo, a broken link) is allowed when the section carries a
|
|
12
|
+
line `<!-- edited after release: <reason> -->`, so the edit is visible to readers.
|
|
13
|
+
"""
|
|
14
|
+
import os
|
|
15
|
+
import re
|
|
16
|
+
import subprocess
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
|
|
19
|
+
import pytest
|
|
20
|
+
|
|
21
|
+
ROOT = Path(__file__).resolve().parents[1]
|
|
22
|
+
# The version must end the token: "## v0.4.0-rc1" or "## v0.3.3.post1" is a different
|
|
23
|
+
# section, not a second copy of v0.4.0 / v0.3.3.
|
|
24
|
+
HEADER = re.compile(r"^## (v\d+\.\d+\.\d+)(?=[ \t]|$)", re.M)
|
|
25
|
+
OVERRIDE = "<!-- edited after release:"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def sections(text):
|
|
29
|
+
"""{version: body} for every `## vX.Y.Z` header, body up to the next `## `."""
|
|
30
|
+
out = {}
|
|
31
|
+
marks = list(re.finditer(r"^## ", text, re.M))
|
|
32
|
+
for i, m in enumerate(marks):
|
|
33
|
+
end = marks[i + 1].start() if i + 1 < len(marks) else len(text)
|
|
34
|
+
chunk = text[m.start():end]
|
|
35
|
+
h = HEADER.match(chunk)
|
|
36
|
+
if h:
|
|
37
|
+
if h.group(1) in out:
|
|
38
|
+
out.setdefault("__duplicates__", []).append(h.group(1))
|
|
39
|
+
continue
|
|
40
|
+
# The header line itself may change: v0.3.1 was tagged as "v0.3.1 — unreleased"
|
|
41
|
+
# and got its date afterwards. Only the body is frozen.
|
|
42
|
+
out[h.group(1)] = chunk.split("\n", 1)[1].strip() if "\n" in chunk else ""
|
|
43
|
+
return out
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def frozen_violations(head_text, tagged_texts):
|
|
47
|
+
"""Versions whose released section changed. tagged_texts: {tag: CHANGELOG at that tag}."""
|
|
48
|
+
head = sections(head_text)
|
|
49
|
+
bad = [f"{v}: header appears twice" for v in head.pop("__duplicates__", [])]
|
|
50
|
+
for tag, old_text in tagged_texts.items():
|
|
51
|
+
then = sections(old_text).get(tag)
|
|
52
|
+
now = head.get(tag)
|
|
53
|
+
if then is None:
|
|
54
|
+
continue # section written after the fact (pre-2026-09-05 history)
|
|
55
|
+
if now is None:
|
|
56
|
+
bad.append(f"{tag}: released section was removed")
|
|
57
|
+
elif now != then and OVERRIDE not in now:
|
|
58
|
+
bad.append(f"{tag}: released section changed after the tag")
|
|
59
|
+
return bad
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _git(*args):
|
|
63
|
+
return subprocess.run(["git", *args], cwd=ROOT, capture_output=True, text=True, encoding="utf-8")
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def test_released_sections_are_frozen():
|
|
67
|
+
tags = [t for t in _git("tag", "--list", "v*").stdout.split() if re.fullmatch(r"v\d+\.\d+\.\d+", t)]
|
|
68
|
+
if not tags:
|
|
69
|
+
if os.environ.get("CI"):
|
|
70
|
+
pytest.fail("no version tags in the checkout: CI must fetch tags (fetch-depth: 0), "
|
|
71
|
+
"otherwise this guard is blind")
|
|
72
|
+
pytest.skip("no version tags in this checkout")
|
|
73
|
+
tagged, unreadable = {}, []
|
|
74
|
+
for t in tags:
|
|
75
|
+
# ls-tree tells "the file did not exist at this tag" (pre-2026-09-05 history, a
|
|
76
|
+
# legitimate skip) apart from "git could not read it" (a blind guard, a failure).
|
|
77
|
+
listed = _git("ls-tree", "--name-only", t, "--", "CHANGELOG.md")
|
|
78
|
+
if listed.returncode != 0:
|
|
79
|
+
unreadable.append(f"{t}: {listed.stderr.strip()[:120]}")
|
|
80
|
+
continue
|
|
81
|
+
if not listed.stdout.strip():
|
|
82
|
+
continue
|
|
83
|
+
r = _git("show", f"{t}:CHANGELOG.md")
|
|
84
|
+
if r.returncode != 0:
|
|
85
|
+
unreadable.append(f"{t}: {r.stderr.strip()[:120]}")
|
|
86
|
+
continue
|
|
87
|
+
tagged[t] = r.stdout
|
|
88
|
+
assert not unreadable, "could not read CHANGELOG.md at these tags, the guard would be blind:\n " + "\n ".join(unreadable)
|
|
89
|
+
head_text = (ROOT / "CHANGELOG.md").read_text(encoding="utf-8")
|
|
90
|
+
bad = frozen_violations(head_text, tagged)
|
|
91
|
+
assert not bad, ("released CHANGELOG sections must not change; put new entries under an "
|
|
92
|
+
"untagged version, or mark a deliberate fix with "
|
|
93
|
+
"'<!-- edited after release: reason -->':\n " + "\n ".join(bad))
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
OLD = "# Changelog\n\n## v0.3.2 — 2026-10-24\n\nPPR lane.\n\n## v0.3.1\n\nFixes.\n"
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def test_entry_slipped_into_released_section_is_caught():
|
|
100
|
+
head = OLD.replace("PPR lane.", "PPR lane.\n\nA change that shipped later.")
|
|
101
|
+
assert frozen_violations(head, {"v0.3.2": OLD}) == ["v0.3.2: released section changed after the tag"]
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def test_new_untagged_section_is_fine():
|
|
105
|
+
head = OLD.replace("# Changelog\n\n", "# Changelog\n\n## v0.3.3 — 2026-10-26\n\nNew.\n\n")
|
|
106
|
+
assert frozen_violations(head, {"v0.3.2": OLD, "v0.3.1": OLD}) == []
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def test_release_date_filled_in_after_tag_is_fine():
|
|
110
|
+
then = OLD.replace("## v0.3.2 — 2026-10-24", "## v0.3.2 — unreleased")
|
|
111
|
+
assert frozen_violations(OLD, {"v0.3.2": then}) == []
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def test_marked_edit_is_allowed():
|
|
115
|
+
head = OLD.replace("PPR lane.", "PPR lane (link fixed).\n<!-- edited after release: dead link -->")
|
|
116
|
+
assert frozen_violations(head, {"v0.3.2": OLD}) == []
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def test_unreadable_tag_fails_instead_of_skipping():
|
|
120
|
+
calls = {"_git": _git}
|
|
121
|
+
|
|
122
|
+
def broken(*args):
|
|
123
|
+
if args[0] == "tag":
|
|
124
|
+
return subprocess.CompletedProcess(args, 0, "v0.3.2\n", "")
|
|
125
|
+
return subprocess.CompletedProcess(args, 128, "", "fatal: bad object v0.3.2")
|
|
126
|
+
|
|
127
|
+
globals()["_git"] = broken
|
|
128
|
+
try:
|
|
129
|
+
try:
|
|
130
|
+
test_released_sections_are_frozen()
|
|
131
|
+
except AssertionError as e:
|
|
132
|
+
assert "could not read" in str(e)
|
|
133
|
+
else:
|
|
134
|
+
raise AssertionError("an unreadable tag must fail the guard")
|
|
135
|
+
finally:
|
|
136
|
+
globals()["_git"] = calls["_git"]
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def test_prerelease_header_is_its_own_section():
|
|
140
|
+
head = OLD + "\n## v0.3.2-rc1\n\nCandidate notes kept below the release.\n"
|
|
141
|
+
assert frozen_violations(head, {"v0.3.2": OLD}) == []
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def test_duplicate_header_is_caught():
|
|
145
|
+
head = OLD + "\n## v0.3.2 — copy\n\nAnother body.\n"
|
|
146
|
+
assert frozen_violations(head, {"v0.3.2": OLD}) == ["v0.3.2: header appears twice"]
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""sgm-doctor: each verdict has to come from the machine, not be hard-coded."""
|
|
2
|
+
import sys
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "src"))
|
|
6
|
+
|
|
7
|
+
from sqlite_graph_memory import doctor # noqa: E402
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def test_old_python_fails():
|
|
11
|
+
assert doctor.check_python((3, 8, 1))[0] == doctor.FAIL
|
|
12
|
+
assert doctor.check_python((3, 12, 0))[0] == doctor.OK
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def test_missing_index_warns_and_names_the_command(tmp_path):
|
|
16
|
+
status, what, fix = doctor.check_index(tmp_path)
|
|
17
|
+
assert status == doctor.WARN and "sgm-index" in fix
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def test_half_index_fails(tmp_path):
|
|
21
|
+
(tmp_path / "_brain_e5.npy").write_bytes(b"x")
|
|
22
|
+
status, what, _ = doctor.check_index(tmp_path)
|
|
23
|
+
assert status == doctor.FAIL and "_brain_e5_meta.pkl" in what
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def test_full_index_ok(tmp_path):
|
|
27
|
+
(tmp_path / "_brain_e5.npy").write_bytes(b"x")
|
|
28
|
+
(tmp_path / "_brain_e5_meta.pkl").write_bytes(b"x")
|
|
29
|
+
assert doctor.check_index(tmp_path)[0] == doctor.OK
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def test_models_missing_when_cache_is_empty(tmp_path, monkeypatch):
|
|
33
|
+
monkeypatch.setenv("HF_HUB_CACHE", str(tmp_path))
|
|
34
|
+
monkeypatch.delenv("SENTENCE_TRANSFORMERS_HOME", raising=False)
|
|
35
|
+
monkeypatch.setenv("HF_HOME", str(tmp_path / "none"))
|
|
36
|
+
assert doctor.check_models()[0] == doctor.WARN
|
|
37
|
+
(tmp_path / "models--intfloat--multilingual-e5-base").mkdir()
|
|
38
|
+
(tmp_path / "models--cross-encoder--mmarco-mMiniLMv2-L12-H384-v1").mkdir()
|
|
39
|
+
assert doctor.check_models()[0] == doctor.OK
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def test_missing_torch_is_a_warning_not_a_failure(monkeypatch):
|
|
43
|
+
monkeypatch.setitem(sys.modules, "torch", None) # import torch -> ModuleNotFoundError
|
|
44
|
+
status, what, fix = doctor.check_embeddings()
|
|
45
|
+
assert status == doctor.WARN and "embeddings" in fix
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def test_broken_torch_on_intel_mac_points_at_numpy(monkeypatch):
|
|
49
|
+
class Boom:
|
|
50
|
+
def __getattr__(self, name):
|
|
51
|
+
raise RuntimeError("Numpy is not available")
|
|
52
|
+
import builtins
|
|
53
|
+
real = builtins.__import__
|
|
54
|
+
|
|
55
|
+
def fake(name, *a, **k):
|
|
56
|
+
if name == "torch":
|
|
57
|
+
raise RuntimeError("Numpy is not available")
|
|
58
|
+
return real(name, *a, **k)
|
|
59
|
+
monkeypatch.setattr(builtins, "__import__", fake)
|
|
60
|
+
import numpy
|
|
61
|
+
monkeypatch.setattr(numpy, "__version__", "2.0.1")
|
|
62
|
+
status, what, fix = doctor.check_embeddings(system="Darwin", machine="x86_64")
|
|
63
|
+
assert status == doctor.FAIL and "numpy<2" in fix
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def test_render_exit_code_follows_failures():
|
|
67
|
+
text, fails = doctor.render([("A", (doctor.OK, "fine", "")), ("B", (doctor.FAIL, "bad", "fix it"))])
|
|
68
|
+
assert fails == 1 and "fix it" in text and "Tell us" in text
|
|
69
|
+
text, fails = doctor.render([("A", (doctor.WARN, "meh", "do x"))])
|
|
70
|
+
assert fails == 0 and "Nothing is broken" in text
|
|
@@ -176,14 +176,50 @@ def test_run_recall_timeout(tmp_path, monkeypatch):
|
|
|
176
176
|
"""Verify subprocess timeout is caught and returns clear error text."""
|
|
177
177
|
from sqlite_graph_memory import mcp_server
|
|
178
178
|
import subprocess
|
|
179
|
+
monkeypatch.delenv("BRAIN_RECALL_TIMEOUT", raising=False)
|
|
180
|
+
observed = []
|
|
179
181
|
def mock_run(*args, **kwargs):
|
|
180
|
-
|
|
182
|
+
observed.append(kwargs["timeout"])
|
|
183
|
+
raise subprocess.TimeoutExpired(cmd=kwargs.get("args") or [], timeout=kwargs["timeout"])
|
|
181
184
|
monkeypatch.setattr(mcp_server.subprocess, "run", mock_run)
|
|
182
185
|
text, is_err = mcp_server.run_recall("test query")
|
|
183
|
-
|
|
186
|
+
# Default covers a cold first call: a clean Windows install measured 89 s for one CLI recall.
|
|
187
|
+
assert observed == [180]
|
|
188
|
+
assert "timed out after 180 seconds" in text
|
|
184
189
|
assert is_err is True
|
|
185
190
|
|
|
186
191
|
|
|
192
|
+
def test_run_recall_respects_configured_startup_timeout(monkeypatch):
|
|
193
|
+
monkeypatch.setenv("BRAIN_RECALL_TIMEOUT", "180")
|
|
194
|
+
observed = []
|
|
195
|
+
|
|
196
|
+
def slow_model_start(*args, **kwargs):
|
|
197
|
+
observed.append(kwargs["timeout"])
|
|
198
|
+
raise subprocess.TimeoutExpired(cmd=args[0], timeout=kwargs["timeout"])
|
|
199
|
+
|
|
200
|
+
monkeypatch.setattr(mcp_server.subprocess, "run", slow_model_start)
|
|
201
|
+
text, is_err = mcp_server.run_recall("cold model start")
|
|
202
|
+
assert observed == [180]
|
|
203
|
+
assert is_err is True
|
|
204
|
+
assert "timed out after 180 seconds" in text
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
@pytest.mark.parametrize("value", ["0", "-1", "601", "infinity", "1.5", ""])
|
|
208
|
+
def test_run_recall_rejects_invalid_timeout_before_starting_child(monkeypatch, value):
|
|
209
|
+
monkeypatch.setenv("BRAIN_RECALL_TIMEOUT", value)
|
|
210
|
+
observed = []
|
|
211
|
+
|
|
212
|
+
def unexpected_child(*args, **kwargs):
|
|
213
|
+
observed.append(True)
|
|
214
|
+
raise RuntimeError("should not launch")
|
|
215
|
+
|
|
216
|
+
monkeypatch.setattr(mcp_server.subprocess, "run", unexpected_child)
|
|
217
|
+
text, is_err = mcp_server.run_recall("test query")
|
|
218
|
+
assert observed == []
|
|
219
|
+
assert is_err is True
|
|
220
|
+
assert "BRAIN_RECALL_TIMEOUT" in text
|
|
221
|
+
|
|
222
|
+
|
|
187
223
|
def test_run_recall_answer_file_is_unique_per_call_and_cleaned_up(tmp_path, monkeypatch):
|
|
188
224
|
"""The scoped answer file must differ between calls and must not survive them.
|
|
189
225
|
|
|
@@ -74,6 +74,9 @@ def test_ab_json_consumer_is_silent(tmp_path):
|
|
|
74
74
|
|
|
75
75
|
def test_tilde_in_config_dir_expands(tmp_path, monkeypatch):
|
|
76
76
|
monkeypatch.setenv("HOME", str(tmp_path))
|
|
77
|
+
# Windows expanduser reads USERPROFILE rather than HOME. Keep the marker
|
|
78
|
+
# inside this test's directory on both platforms, away from the real profile.
|
|
79
|
+
monkeypatch.setenv("USERPROFILE", str(tmp_path))
|
|
77
80
|
buf = io.StringIO()
|
|
78
81
|
assert maybe_star_prompt(stream=buf, env={"SGM_CONFIG_DIR": "~/sgm"}, interactive=True)
|
|
79
82
|
assert (tmp_path / "sgm" / STAR_MARKER).exists()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/src/sqlite_graph_memory/brain_ask.py
RENAMED
|
File without changes
|
{sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/src/sqlite_graph_memory/index_notes.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/src/sqlite_graph_memory/turnstate_hook.py
RENAMED
|
File without changes
|
{sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/src/sqlite_graph_memory/turnstate_show.py
RENAMED
|
File without changes
|
{sqlite_graph_memory-0.3.3 → sqlite_graph_memory-0.3.5}/src/sqlite_graph_memory/vault_stats.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|