spike: the rag store on Cozo-SQLite HNSW, measured against the design's pass bar (macula-ci-images#19) #1

Manually merged
terra merged 0 commits from ceres/19-rag-cozo-spike into main 2026-11-23 10:42:16 +00:00
Member

Purpose (spike): decide, with measurements, whether Cozo 0.7.6's persisted HNSW index on its SQLite
engine is good enough to replace mcl-rag's barrel_vectordb index — macula-io/macula-ci-images#19,
step 1c, design §2 (mcl-rag). Nothing is deployed and no service file changes: this branch is the
instrument and its report. No merge needed; the decision it informs is recorded on #19.

DECIDED 2026-11-23 "Yes, build it (Recommended)" (off-rocksdb-design-go), carried by the Supervisor's
"come on, delegate some work!".

What is here

  • spike/export/export_chunks.erl — opens a COPY of today's store with the ship image's own barrel
    and writes one JSON line per vector: {"id","type","topics","vec"}. Never the live store.
  • spike/cozo-hnsw/ — a Rust program on cozo = "0.7" with storage-sqlite (Cargo.lock committed:
    cozo 0.7.6). Builds the index from the export, then measures every line of the pass bar and writes
    them to a JSON report.
  • spike/cozo-hnsw/src/bin/ — four follow-up probes that explain a number on the FINISHED database
    rather than re-measure it: probe_replace_unique (replace with donors no other row shares),
    probe_heal (why a row is unfindable, and :rm+:put vs a repeat :put), probe_paths (four
    write paths on disjoint sets, each check repeated after a reopen), probe_scan (the exact
    brute-force fallback, timed at three sizes).
  • spike/VERDICT.md — the pass bar line by line, each number with the command that produced it,
    plus the engine facts that cost a run each.

Verdict (full table and commands in spike/VERDICT.md)

Bar (design §2) Measured on 55,450 vectors, msi00
recall@10 ≥ 0.95 vs EXACT cosine, 100 queries 0.9810 PASS
p95 query < 200 ms 23.1 ms PASS
topic-scoped equal to brute force, 20 queries not measurable on today's corpus (30 of 55,450 chunks carry a topic); 60/60 equal on a seeded 4-topic store —
restart opens in < 10 s 33 ms PASS
delete and replace correct, before and after restart deleted back 0/100, found by old 0/100, found by new 99/100; probes read 99.2% at k: 10, ef: 50 not proven either way

The exact scan is taken, on its own merits: it meets the bar with no index to trust, and it is the
design's own fallback. Cozo is not condemned by this spike — where measured it does what the design
wanted (33 ms open instead of 39 minutes) — and its delete/replace line is not proven either way:
0.8% self-miss at k: 10 is the index's own recall@10, only two rows were shown unreachable at
k: 200, there is no never-rewritten control, Cozo 0.7.6's :put makes the four write paths one, and
no probe writes a new vector. :replace refusing the indexed relation is an engine fact, not an
upsert path.

Notes for the reviewer

  • r=2 is doc-only, on Uranus's FAIL at r=1 (R1-R5): the verdict no longer calls the delete/replace
    result a Cozo defect, :replace is out of the reasons, the README's older aggregate is replaced by
    this round's numbers, and the log name is corrected. The limits that remain are named in
    spike/VERDICT.md: measured at k: 10 / ef: 50, no never-rewritten control, one write path, no
    new-vector write, probe_replace_unique does not reopen.
  • No CI runs on this repository: macula-services/mcl-rag has no Actions enabled (has_actions
    false), and its workflows are still the github.com shape. The instrument is reproducible from
    spike/README.md on msi00; the report it produced, with its sha256, is named in spike/VERDICT.md.
Purpose (spike): decide, with measurements, whether Cozo 0.7.6's persisted HNSW index on its SQLite engine is good enough to replace mcl-rag's barrel_vectordb index — macula-io/macula-ci-images#19, step 1c, design §2 (mcl-rag). Nothing is deployed and no service file changes: this branch is the instrument and its report. No merge needed; the decision it informs is recorded on #19. DECIDED 2026-11-23 "Yes, build it (Recommended)" (off-rocksdb-design-go), carried by the Supervisor's "come on, delegate some work!". ## What is here - `spike/export/export_chunks.erl` — opens a COPY of today's store with the ship image's own barrel and writes one JSON line per vector: `{"id","type","topics","vec"}`. Never the live store. - `spike/cozo-hnsw/` — a Rust program on `cozo = "0.7"` with `storage-sqlite` (Cargo.lock committed: cozo 0.7.6). Builds the index from the export, then measures every line of the pass bar and writes them to a JSON report. - `spike/cozo-hnsw/src/bin/` — four follow-up probes that explain a number on the FINISHED database rather than re-measure it: `probe_replace_unique` (replace with donors no other row shares), `probe_heal` (why a row is unfindable, and `:rm`+`:put` vs a repeat `:put`), `probe_paths` (four write paths on disjoint sets, each check repeated after a reopen), `probe_scan` (the exact brute-force fallback, timed at three sizes). - `spike/VERDICT.md` — the pass bar line by line, **each number with the command that produced it**, plus the engine facts that cost a run each. ## Verdict (full table and commands in `spike/VERDICT.md`) | Bar (design §2) | Measured on 55,450 vectors, msi00 | | | --- | --- | --- | | recall@10 ≥ 0.95 vs EXACT cosine, 100 queries | 0.9810 | PASS | | p95 query < 200 ms | 23.1 ms | PASS | | topic-scoped equal to brute force, 20 queries | not measurable on today's corpus (30 of 55,450 chunks carry a topic); 60/60 equal on a seeded 4-topic store | — | | restart opens in < 10 s | 33 ms | PASS | | delete and replace correct, before and after restart | deleted back 0/100, found by old 0/100, found by new 99/100; probes read 99.2% at k: 10, ef: 50 | **not proven either way** | The exact scan is taken, on its own merits: it meets the bar with no index to trust, and it is the design's own fallback. Cozo is not condemned by this spike — where measured it does what the design wanted (33 ms open instead of 39 minutes) — and its delete/replace line is not proven either way: 0.8% self-miss at k: 10 is the index's own recall@10, only two rows were shown unreachable at k: 200, there is no never-rewritten control, Cozo 0.7.6's `:put` makes the four write paths one, and no probe writes a new vector. `:replace` refusing the indexed relation is an engine fact, not an upsert path. ## Notes for the reviewer - r=2 is doc-only, on Uranus's FAIL at r=1 (R1-R5): the verdict no longer calls the delete/replace result a Cozo defect, `:replace` is out of the reasons, the README's older aggregate is replaced by this round's numbers, and the log name is corrected. The limits that remain are named in `spike/VERDICT.md`: measured at k: 10 / ef: 50, no never-rewritten control, one write path, no new-vector write, `probe_replace_unique` does not reopen. - No CI runs on this repository: macula-services/mcl-rag has no Actions enabled (`has_actions` false), and its workflows are still the github.com shape. The instrument is reproducible from `spike/README.md` on msi00; the report it produced, with its sha256, is named in `spike/VERDICT.md`.
The instrument and the export, not the verdict yet: no service changes, nothing
deployed. The export opens a copy of the store with the ship image's own barrel;
the program builds the index and measures recall@10 against exact cosine,
latency, topic-scoped answers, restart time and delete/replace.
The export's shapes are taken from the pinned deps, not guessed: barrel:open
returns {ok, Db}, fold_docs calls the fun as Fun(Doc, Acc) -> {ok, Acc}, and
vector_get returns a {ok, #{vector := [float()]}}. A doc that does not fit is
counted and named, never allowed to end a run that spent the store's open
first.

The Cozo side needed its own corrections, each found by running it: the sqlite
engine takes a database FILE, the option is keep_pruned_connections, a search
query goes in as vec($q), a filter may only read symbols the search binds (so
topics is bound), :put demands every column, and $rows is a list of rows.

Also measured honestly what the design's bar can flatter: every query is a
stored vector, so recall_at_10_excluding_self drops the free self-hit; the
sqlite open is lazy, so the restart number is open plus the first answered
query; and a search that ERRORS after a delete is counted, not skipped.
probe_replace names the row the replace check missed: its donor vector is shared
by 170 rows at cos_dist 0, so the top-k is all ties and the line is unmeasurable.
probe_replace_unique repeats the check with donors whose vector no other row
shares, and 98/100 are found: 2 lose their index entry. probe_heal shows the row
is stored with the new vector (in-engine cos_dist 0), is absent from the index at
k=200, survives a cold reopen, is not healed by a repeat :put, and IS healed by
:rm then :put. README carries each engine fact that cost a run.
:replace refuses this indexed relation. A two-statement write needs each
statement in braces or Cozo answers 'Program has no entry'. Measured on four
disjoint sets of 100 rows, before and after a reopen: :put 495/500, :rm+:put
298/300, the atomic brace form 100/100 find their own vector, and the same
rows stay missing across a cold reopen (~1 in 100 on every path), which is the
index's own recall rate, not a write-path fault.
Brute-force cosine over every vector, k=10, on msi00: 3.2 ms at 5,545 rows,
15.5 at 27,725, 32.8 at 55,450 (p95 36.9). Linear in rows, 0.59 ms per 1,000,
so 200 ms is reached near 6x today's corpus, not 10x.
spike/VERDICT.md carries the design's five-bar table line by line, every number
with the command that produced it and the log it is in. The follow-up probes
were re-run from these sources at five disjoint offsets (the earlier aggregate
had no command log behind it); the same conclusions hold: about 0.8% of
upserted rows cannot be found by their own vector on any write path, on disk
and across a reopen, and :replace is refused on the indexed relation.

Also: Cargo.lock committed so the numbers pin cozo 0.7.6, the README's probe
count corrected, and the spike's Rust target/ ignored.
Uranus's r=1 FAIL (R1-R5) is right: the 0.8% self-miss was measured at
k:10/ef:50, where it is the index's own recall@10 of 0.981; only the two
probe_heal rows were shown unreachable at k:200/ef:200; there is no
never-rewritten control; Cozo 0.7.6's :put makes the four write paths one;
no probe writes a new vector; and :replace is not the upsert path.

VERDICT.md and the README now read line 5 as "not proven either way", name
those limits, drop :replace from the reasons, carry the export's real vecless
count (13,324, not 5,001), the r=2 probe numbers in place of the old
aggregate, and the right log name for the idle exact-scan run. The exact
scan is taken on its own merits, per the Supervisor's ruling on #19.
terra manually merged commit 50e62d6655 into main 2026-11-23 10:42:16 +00:00
Member

Landed --no-ff at 50e62d66 (parents d15f57f1 main, 2fca69b7 PR head) by Terra.

Reviews ran by direct message: Uranus PASS r=2 d15f57f..fd028d5 (with Ceres PASS of the reviewer fix), Uranus PASS r=3 fd028d5..2fca69b (README line 1 = evidence record). mcl-rag has no CI, so there are no runs. Main read back by ls-remote = 50e62d66.

Landed --no-ff at 50e62d66 (parents d15f57f1 main, 2fca69b7 PR head) by Terra. Reviews ran by direct message: Uranus PASS r=2 d15f57f..fd028d5 (with Ceres PASS of the reviewer fix), Uranus PASS r=3 fd028d5..2fca69b (README line 1 = evidence record). mcl-rag has no CI, so there are no runs. Main read back by ls-remote = 50e62d66.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
macula-services/mcl-rag!1
No description provided.