Repository navigation
feat(knowledge-turso): an approximate vector index for a large source of one organization - #38056
Conversation
…ization sources Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP
…owledge docs; plugin options Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP
…uctured vectors Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP
… of libSQL's DiskANN index DiskANN measured a recall@10 of 0.39 at 200,000 clustered passages and took 24 minutes and 2.2 GB to build; a one-bit side table scanned whole and re-ranked by the float32 vectors measured 0.99, 3 s and 54 MB. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP
… index at 200,000 passages Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP
📓 Docs Drift CheckThis PR changes 1 package(s): 5 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
⛔ 1 release-owned page(s) also name something this change touched. These are read-only:
What this run could not see
Coarse fallback — 2 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin d6db67f4c5b1ae1e6ffed4f55fe4f24c6e8706e8 && git checkout d6db67f4c5b1ae1e6ffed4f55fe4f24c6e8706e8
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 33a0d4fa625cdfb69873a89a1e0f5d9f49fea744 73d277418b303a87e50e4fd79592b6035f37fed5 && git checkout -B drift-repro 33a0d4fa625cdfb69873a89a1e0f5d9f49fea744 && git merge --no-ff 73d277418b303a87e50e4fd79592b6035f37fed5
node scripts/docs-audit/affected-docs.mjs --json 33a0d4fa625cdfb69873a89a1e0f5d9f49fea744
|
…both keep the exact scan The approximate vector leg now answers only when at least 4 x topK of its candidates are in scope; a narrow record scope or filter runs the exact scan instead of re-ranking a thin pool. vectorIndexOverfetch is now a whole number of 4 or more to match. A database that refuses vector1bit or the side table's DDL gets no index: a probe runs before any DDL (a trigger naming an unknown function is created without complaint and then fails every write), a refused DDL transaction rolls back, a refused backfill batch ends the copy, and the build completes on the exact scan. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP
…ures as present Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP
… and refuses each statement that computes one Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP
…ector index A database without one-bit vectors is named by healthCheck's message at boot (the plugin logs it), and each source whose complete build had its index refused is named with the reason until a later build makes it or the source is dropped. ok stays true: the index is a speed-up, and a store whose index works keeps the message it had. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP
…dates in scope, and the over-fetch 8 or more Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP
|
repo:objectstack#1 · os-elon-musk · session_016WV4czzx9dtSEm3jWWL9c3 Contract-review-claim: session_016WV4czzx9dtSEm3jWWL9c3 · c77819e · 2026-11-28T01:21Z |
|
repo:objectstack#1 · os-elon-musk · session_016WV4czzx9dtSEm3jWWL9c3 Contract reviewServed-tier: Read: card #37975 body and all four comments (triage 7220587871, claim 7226962676, dev report 7229320124, ruling A 7231124445); PR #38056 body, both comments, the ten-file net diff against the merge-base with Check-runs as read on this head: every completed run is ① Derived judgmentsPublic surface the diff implies, each named:
Tenancy (rule: the candidates are ranked before the filter, so an index is never used over more than one organization, per passage table):
Hosted DDL guard (ruling A, item 3):
Other findings:
Docs, README and changeset against the code: the thresholds, the 2,048-row batches, the ② Semver level
③ Boundary flags
Open on this head: S1, S2, S3 and S4 (cross-process index-complete memory; a pin for a refused copy batch; the per-search catalog reads; the surplus bound value on a term-less exact search). Each earns a delta review of its fix. N4 (nit) — the PR body's "nothing that was accepted before is refused" is slightly too strong: a foreign object under one of the store's new hyphenated names is now refused, as the changeset states. Nits N1 to N4 are optional. Implemented-by: VERDICT: PASS |
|
repo:objectstack#1 · os-elon-musk · session_016WV4czzx9dtSEm3jWWL9c3 L1 verdict (L1-a): REWORK at head Review summaryFace. The face is declaration (TIER_DEFAULT): there is no Contract review. Declaration record 7231688504 has no must-fix. It does have four graded should-fix findings, S1 to S4, so the queue guard reads them as open on this head. Each needs its fix and a delta read.
What holds. Tenancy holds on the build, on a later second-organization write and on the search. The approximate and exact statements share the identical in-scope Nits, optional:
The body should also name follow-up #38066 for ruling item 6. Gates. CI was still running at this reading. The next head needs every check green. Next: fix S1 to S4. Then a delta declaration record and a delta L1 follow, and the area lands it. |
…stance; reads and bound values only where used The approximate-index memory is now keyed per generation instance, and a failed approximate statement is answered by the exact scan. A search at vectorIndexThreshold Infinity reads no catalog for an index, and a build remembers what it found, so a source under the threshold costs no catalog read in its own process and two reads once in another. The candidate count is bound for the approximate statement alone. A refused copy batch is pinned beside the refused probe and DDL. The protocol doc's two leftover exact-scan sentences now name the approximate index. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP
… no index catalog at Infinity either Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP
|
repo:objectstack#1 · os-elon-musk · session_016WV4czzx9dtSEm3jWWL9c3 Contract-review-claim: session_016WV4czzx9dtSEm3jWWL9c3 · 50e245a · 2026-11-28T04:42Z |
|
repo:objectstack#1 · os-elon-musk · session_016WV4czzx9dtSEm3jWWL9c3 Contract reviewServed-tier: Delta round on the record in comment 7231688504 (head c77819e), which left S1 to S4 open. Face unchanged: declaration, plus the published option surface. Read: the first-parent moves c77819e to 50e245a (f5d171e main merge, 98ffbe4, b113f08, 50e245a main merge); the author delta Check-runs on this head, read at 04:44Z: every completed run is Not found when read: the area's announcement comment on the PR and a new dev report on #37975. The PR thread holds the docs-drift comment, the two review claims, the earlier record and the L1 verdict; the card still holds its four earlier comments. The PR body v3 was read in their place. ① Derived judgmentsClosures of the earlier findings: S1 (should-fix): closed The index memory is keyed per generation instance, with a catch backstop on the approximate statement. Pinned by two acceptance tests. The backstop runs the exact statement, which carries the same in-scope S2 (should-fix): closed A third refusal variant, S3 (should-fix): closed At S4 (should-fix): closed The candidate count is bound for the approximate statement alone, after every other value; the exact statement binds exactly the values it reads. Pinned by a test of a query without a keyword term. Earlier nits: N3 (the health check's refusal record is process memory) is closed by a README sentence and a PR-body line. N4 (the PR body's "nothing accepted before is refused") is closed: the Clause-② paragraph now names the one exception, the refusal of a hand-made object under a Public surface in the delta: none added, none removed. No export, option, default or accepted value moves. One behavior is now defined where it was not: at Tenancy, re-read on the delta: the organization count is still read from the passage table at every search that would take the index and is not part of the remembered answer; a remembered "complete" alone never admits the index. The backfill's still-here check now also matches the generation row's creation time. Holds. The two main merges: f5d171e changes none of the PR's ten files. 50e245a changes two of them, Changeset and docs, sentence by sentence against the code:
PR body v3, the new lines: the S1 to S4 paragraphs match the code as closed above; the operator sentence on ② Semver levelUnchanged and still right: ③ Boundary flags
Open after this round: three nits (the changeset's No must-fix, no should-fix. Implemented-by: VERDICT: PASS |
…timeout; the Infinity wording says what a search reads The scoped recall case took 5,971 ms on CI against the 5 s default; both 2,000-passage cases now carry an explicit timeout citing the local and CI readings. The changeset and README now say that at Infinity a search never reads the catalog for an index, and an index made earlier stays in place unsearched. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP
|
repo:objectstack#1 · os-elon-musk · session_016WV4czzx9dtSEm3jWWL9c3 Contract-review-claim: session_016WV4czzx9dtSEm3jWWL9c3 · 73d2774 · 2026-11-28T05:01Z |
|
repo:objectstack#1 · os-elon-musk · session_016WV4czzx9dtSEm3jWWL9c3 Contract reviewServed-tier: This is the second delta of the declaration record 7231688504. It follows delta 7234240432, which passed at ① Derived judgments
② Semver levelThe level is unchanged: patch on ③ ReadingsCI on this head had only started at 05:00Z. The record names the head; the gate verdicts are the check-runs on it, read by the landing seat. No must-fix, no should-fix. Nits from 7234240432: both are closed by this delta. The two-statement organization nit stays as it was. VERDICT: PASS |
|
repo:objectstack#1 · os-elon-musk · session_016WV4czzx9dtSEm3jWWL9c3 L1 verdict (L1-a): ACCEPT (delta) at head Review summaryRecords on this PR.
Delta read since the REWORK.
Gates. The PR is not governed (Tier S). CI on this head had only started at 05:05Z: 13 success, 0 failed, 16 pending. This ACCEPT is on the code. The landing waits on every check at this head concluding green, and the area reads that before it lands. Next: the area lands it on all-green at this head. |
|
repo:objectstack#1 · os-elon-musk · session_016WV4cwPhGV4g9p1BGQaZbP Landing · area o1-C · head
State: ready + auto-merge; #37975 closes on merge via |
repo:objectstack#1 · os-elon-musk · session_016WV4cwPhGV4g9p1BGQaZbP
Fixes #37975
Clause-②: yes (widening)
Metadata-protocol: none
Skills-docs: none — the diff adds two options of one plugin and changes no metadata an author writes; no published skill names the libSQL store's search.
维护者速读
What changes
A libSQL store read every vector in scope on every search: at 1,536 dimensions, about 1.2 GB at 200,000 passages. Now, when a complete build finishes on a generation that holds
vectorIndexThresholdpassages or more (default 20,000), and all of them belong to one organization, the store gives that generation an approximate index. It is on by default, per the maintainer's ruling A on #37975 (「A 采用新索引,默认开启」, recorded in comment 7231124445).The index. It is a side table,
knowledge_SOURCE_gN-vec. It holds each passage's vector quantized to one bit per dimension (F1BIT_BLOB), a 32nd the size of the float32 column. Three triggers keep it in step with every write.The vector leg. The leg takes the
topK x vectorIndexOverfetchpassages (default 40 per hit) nearest the query's one-bit vector. It runs the unchanged organization, record-scope and metadataWHEREover them (thepool), then ranks the pool by the stored float32 vector.How it feeds RRF. Its ranks feed the reciprocal rank fusion with the keyword leg exactly as the exact scan's ranks did. The keyword leg and the merge are unchanged.
The scoped-recall floor. The search runs again as the exact scan in either of two cases:
topKof the candidates are in scope;topKhits.The candidates are ranked before the filter, so a thin pool would re-rank the wrong neighbours. The second case exists because the service reads a short answer as "the source holds no more". The real-store rows are under Acceptance notes.
Never over two organizations. The candidates are ranked before the filter.
-orgindex (min,max, andEXISTS ... IS NULL: three seeks). It takes the exact scan as soon as a second organization's passage is written.When the index is built. At the end of
completeBuild, before the switch transaction, and never on a search.os knowledge rebuild, a fingerprint change, the boot build or the daily reconcile.A database that refuses the index. The source keeps the exact scan, and the build completes.
vector1bitruns before any DDL. It has to come first: SQLite creates a trigger that names an unknown function without complaint, and that trigger would then fail every passage write.The refusal is signalled through the existing
healthCheck(). The service's health endpoint reads it, and the plugin logs it at boot.healthCheck()line is how an operator tells whether a hosted database refused a source's index: a source it names runs the exact scan for that reason. A source it does not name may still run the exact scan for another reason above: two organizations, under the threshold at its last complete build, or a narrow scope.okstaystrue, and a store whose index works keeps the messagelibSQL vectors readyunchanged.What a search reads to choose the index.
vectorIndexThreshold: Infinity, a search never reads the catalog for an index; an index made earlier under a finite threshold stays in place and is not searched.The candidate count is bound only where it is read, by the approximate statement. The exact statement binds exactly the values it reads, so a query without a keyword term leaves no surplus value.
Lifecycle and safety.
dropSourcedrop the side table, the-orgindex and the triggers together with the generation's passage table.SERVICE_UNAVAILABLE, names the object, and is never dropped.Options.
vectorIndexThreshold(Infinityturns the index off) andvectorIndexOverfetch, on bothKnowledgeTursoPluginandTursoKnowledgeAdapter. ExportsVECTOR_INDEX_THRESHOLDandVECTOR_INDEX_OVERFETCH.vectorIndexOverfetchmust be a whole number of 8 or more, and the constructor throwsRangeErrorbelow 8. The minimum follows the 8 xtopKfloor: a smaller over-fetch could never answer approximately and would only add a one-bit scan to every search.mainthe PR only widens; the 8 is a narrowing of what this PR first offered (1 or more), and the ruling leaves it to the contract review.Docs. The README Search section, and the two docs pages where they name the exact scan.
The mechanism is not
libsql_vector_idx/vector_top_k; the ruling keeps the card's outcomes and changes only this. I built the card's mechanism first (commits09b0571582and earlier) and measured it at 200,000 passages:libsql_vector_idx)k, sincevector_top_kcaps at 200 rows. At 20,000 passages the best setting I tried reached 0.845, at 13 ms per row and 1.27 GB.Out of scope here:
Tests
New and changed tests in
src/__tests__/acceptance.test.ts, run on each store kind (file, memory) with a threshold of 40:Threshold. At the threshold, the vector leg is approximate. At 61, or at
Infinity, it stays exact.Organizations. Each of these takes the exact path: two organizations at build time; a second organization written after the build; a passage with no organization.
Filter, over-fetch and the floor.
topK2, a scope of all but the two best passages keeps 18 or more of the 20 candidates, at or above the floor of 16, and stays approximate.Refused index. Three variants:
vector1bit.F1BIT_BLOBcolumn.In all three, the build completes, later writes are found by the exact scan, and
healthCheck()staysokand names the source and the reason (plus the missing one-bit vectors for ann_no_1bit). No index objects are left for the first two. For ann_no_copy the index is there, short of its passage table, and is never searched. AfterdropSourcethe source is no longer named.Catalog reads. A search under the threshold, or at
Infinity, issues no catalog read for an index, on each store kind. On one file store, a second adapter reads the catalog of a source under the threshold once (two reads) over three searches.Case timeouts. The two 2,000-passage recall cases carry a 30 s timeout: 1,017 ms and 1,384 ms locally, and 5,971 ms for the scoped case on CI, past the 5 s default.
A term-less query. It binds exactly the values each vector statement reads: an approximate answer, then an approximate statement and the exact one for a scope under the floor.
Two adapters on one file store.
Lifecycle.
dropSourceleaves nothing.Growth. A source that grew past the threshold gets its index at its next build.
A foreign
-vectable. It refusescompleteBuildanddropSourcewithSERVICE_UNAVAILABLEand is kept.Recall. recall@10 is at least 0.95 against the exact scan in two tests:
Options.
RangeErrorfor a threshold below 1 and for an over-fetch of 7 or 8.5; 8 is accepted.plugin.test.tschecks that the plugin passes both options through.Ablations: each an on-disk source edit run through vitest, each red as intended, each restored to a blob equal to HEAD with an empty
git diff HEAD. Ablations 1a to 3 ran on the first design. Ablations 4 to 15 ran onb113f0830funder the verify lock; the later merge ofmaindoes not touch this package's files.publishedinstead ofdraftInfinitytopKfloor removed{approximate: 1, exact: 0}instead ofexact: 1)vector1bitprobe before the DDL disabledcompleteBuildrejects{approximate: 1, exact: 1}instead of{approximate: 0, exact: 1}no such tablecompleteBuildrejectsInfinityskip of the catalog read removedThe scoped-recall unit test stays green with ablation 4 (0.997, 0.993, 0.963). It guards recall; the over-fetch test is what pins the floor.
Local runs on the final head 73d2774 (origin/main 6e06729 merged)
On 73d2774 (test timeouts and wording only, on top of 50e245a), under the lock: typecheck exit 0,
Tests 256 passed (256); the four derived gates that read the changeset and README exit 0 (check-changeset-no-major,check-empty-changeset,check:nul-bytes,check:published-readme-links). The 100-family union below is from 50e245a.All under
os-verify-lock, sloto1C-37975,VERDICT command-exit 0; the lock was held 1,544 s after a 201 s wait.knowledge-turso^...plus itself,--concurrency=2): exit 0.pnpm --filter @objectstack/knowledge-turso typecheckexit 0, withcheck:test-typecheckOK (0 errors).pnpm --filter @objectstack/knowledge-turso exec vitest run --maxWorkers=2exit 0:Test Files 4 passed (4),Tests 256 passed (256).dispatch-gates --commandsderived 100 commands at 50e245a, and all 100 ran.--ran, exit codes recorded:100 derived, 100 run, 0 NOT-MEASURED.check:dual-build-cjs-loadsexited 1 on that pass, naming@objectstack/plugin-approvals(a package this diff does not touch; itsdistwas rewritten during that pass).VERDICT clean exit 0against origin/main 0e36120 and the open PRs feat(knowledge)!: refuse a knowledge_source save that names an adapter the running deployment does not mount #38060, docs(knowledge): the 18 to 19 id row names the underscore exception and the dropSource cleanup #38050, feat(metadata-core)!: a knowledge source is saved only on a deployment that mounts the knowledge service #38013 and fix(knowledge-turso)!: Test connection comes with the Turso fields it checks; the group text drops the cloud fallback #37982.b113f0830f, the head before the merge, under the lock: ablations 4 to 15 as in the table, each red and each restored to a clean tree; the reconciliation read 100 of 100.Acceptance notes
Measured, unscoped, at 200,000 passages of 1,536 dimensions. The vectors are clustered synthetic data (latent dimension 384, 200 clusters), all of one organization,
topK10. The box was shared, with a load of about 8 on 4 cores. The script is a scratchbench.mts, not committed.Measured, scoped, on the same 200,000-passage store: 50 vector-only queries per share, a record scope, against the exact scan of that scope. The "old rule" answers whenever the pool fills
topK, computed in SQL on the same store.topK, the same bench gave 0.970 at 10% in scope, with a worst query of 0.7 and 44% of queries sent exact. With 5% and 3% in scope, floor 4 already sent every query exact (recall 1.000), where the old rule gave 0.914 and 0.878.scoped-recall-floor8-retry-sim.py, run under the verify lock) gives, at floor 8: 41% exact and 0.988 at 20%, 99% exact at 15%, 100% exact at 10% and below.Caveats.
vectorIndexOverfetchmay be higher.LIKEfor terms under 3 characters, and the trigram match for common trigrams, on an adversarial bench vocabulary where every word starts withterm. This PR does not touch that leg, and no card covers it yet.knowledge_SOURCE_gN-vecside table exists. The one-bit vectors and the DDL have only run on localfile:and:memory:stores here. If it is missing, the health check names the reason.The organization rule is per passage table, not store-wide, as the ruling confirms. Pinned in both directions (ablations 1a and 1b).
Clause-②: yes (widening), re-judged on the final diff. Two optional adapter and plugin options and two exported constants are new. Nothing that was accepted before is refused, with one exception: an object the store did not make under one of its new hyphenated names (
knowledge_SOURCE_gN-vec,-org, or a-vec-*trigger) now refusescompleteBuild,dropSourceand the opening of a generation withSERVICE_UNAVAILABLE. That is the rulemainalready applies to the keyword index's names, and the changeset states it. The claim'snois corrected here. Both options are code options, not stored metadata:Metadata-protocol: none.Out-of-scope, noted and not filed:
Verification
Read first, by risk:
turso-adapter.ts,buildVectorIndex: the probe, the guarded DDL transaction, the batched backfill against a generation being swapped away, and the refusal record.turso-adapter.ts,searchAttemptandapproximateSearchable: thepoolcount, the 8 xtopKfloor, the per-search organization check, and the short-leg fallback.sql.ts,vectorIndexDdlandvectorIndexShape: the triggers and the shape check before a drop.Two-minute check:
Expected: every test passes, on both store kinds. Then edit
searchAttempt: changepool >= VECTOR_MIN_POOL * topK &&to nothing, and run it again. The over-fetch test turns red with{ approximate: 1, exact: 0 }.Generated by Claude Code