Repository navigation
perf(knowledge-turso): a narrowly scoped vector search tries a wider approximate pass before the exact scan - #38229
Conversation
…oximate pass before the exact scan Claude-Session: https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP Co-authored-by: Claude <noreply@anthropic.com>
…ecord terms alone Claude-Session: https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP Co-authored-by: Claude <noreply@anthropic.com>
…roximate pass before the exact scan The second pass runs only when the record index cannot serve the exact scan: no scope, or a scope with a parent term. Bench numbers, README and a patch changeset. Claude-Session: https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP Co-authored-by: Claude <noreply@anthropic.com>
…tadata Claude-Session: https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift Check2 anchor(s) derived from 1 changed package(s); no hand-written page names any of them. 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 e7a6d2cf76caf6a5e0d4d94c1c0e4d2ac82c97ec && git checkout e7a6d2cf76caf6a5e0d4d94c1c0e4d2ac82c97ec
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 2d7bf92cce918aa1553f0efa1b9d016fa9495a3f 07a84d2e105cdac7bd81453fa57be88e8ed6bd6e && git checkout -B drift-repro 2d7bf92cce918aa1553f0efa1b9d016fa9495a3f && git merge --no-ff 07a84d2e105cdac7bd81453fa57be88e8ed6bd6e
node scripts/docs-audit/affected-docs.mjs --json 2d7bf92cce918aa1553f0efa1b9d016fa9495a3f |
|
repo:objectstack#1 · os-elon-musk · session_016WV4czzx9dtSEm3jWWL9c3 L1 verdict (L1-a): ACCEPT at head Review summaryShape.
Code read against the ruling.
Evidence.
Gates. CI on this head at 08:43Z: 11 success, 0 failed, 13 pending. dual-build-cjs-loads was NOT MEASURED locally, and CI covers it. This ACCEPT is on the code. The landing waits on every check at this head concluding green, which the area reads 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; #38066 closes on merge via |
Fixes #38066
Clause-②: no
Metadata-protocol: none
维护者速读
What changes
TursoKnowledgeAdapter.search, the approximate vector leg (packages/plugins/knowledge-turso/src/turso-adapter.ts).Today, the leg runs the exact scan when the filter leaves fewer than 8 x
topKof itstopK x vectorIndexOverfetchcandidates in scope. Such a leg now first runs one more approximate pass over 10 times the candidates (VECTOR_RETRY_POOL, not exported), with the sameWHEREand the same floor. It keeps that answer only if it clears the floor; otherwise the exact scan answers, as before.The second pass is tried only when both hold:
metadata) term. A scope of record terms alone keeps today's path, because since feat(service-knowledge): a narrow caller's search ranks only the records they may read #38160 its exact scan reads only the rows in scope through the record index. This is the seat's ruling B on this card, comment 7236023531 (option A of os-dev-report 7235999186). The ruling also files a separate card for a narrow record-only scope that skips the one-bit pass; this PR does not touch that path.topK. A scope too narrow for that goes to the exact scan without a pass that could not answer.A failed second statement is treated like a failed first one: the index memory is forgotten and the exact scan answers. No option, export or stored shape changes. The README Search section and the jsdoc carry the rule and the numbers.
Tests
src/__tests__/acceptance.test.tsgets a new case, run on each store kind, with an explicit 30 s timeout. The corpus is 400 passages with tag lists that a parent scope term matches;topKis 2 and over-fetch 8, so there are 16 candidates, a floor of 16 and 160 for the second pass. Every scope's hits equal the exact scan's.wide(the 2 best plus half the far passages):{ approximate: 2, exact: 0 }. The bound candidate counts are[16, 160], and each pass binds exactly the values it reads.short(5 passages):{ approximate: 2, exact: 1 }. Both passes fall short, then the exact scan answers.thin(one far passage):{ approximate: 1, exact: 1 }. The pool is too thin for a second pass.widepassages as record ids):{ approximate: 1, exact: 1 }. There is no second pass.The two existing pins that run a record scope under the floor, the over-fetch case and the term-less binding case, keep their expectations unchanged. That is the record-only path staying as it is.
Ablation, an on-disk edit replacing the second pass's condition with
false:Tests 2 failed | 126 skipped(the new case on both store kinds,{ approximate: 1, exact: 1 }instead of{ approximate: 2, exact: 0 }). The file was restored to a blob equal toHEAD:(git hash-object5573a5c3e2 on both sides), with an emptygit status.Local runs on the final head
All ran on head
07a84d2e10(origin/main2d95781690merged), underos-verify-lock(VERDICT command-exit 0, held 1,194 s).pnpm --filter @objectstack/knowledge-turso typecheckexits 0.check:test-typecheckis OK (0 errors).pnpm --filter @objectstack/knowledge-turso exec vitest run --maxWorkers=2exits 0, withTest Files 4 passed (4)andTests 278 passed (278).dispatch-gates --commandsderived 67 commands at07a84d2e10. 66 ran, and each exited 0.check:dual-build-cjs-loadswas left to CI. A first pass refused it with exit 3 (PREREQUISITE NOT MET: 60 packages have nodistin this worktree; it needs a whole-repo build).--ran:67 derived, 66 run, 0 NOT-MEASURED, 1 UNRUN. The one UNRUN is that gate.5447b42c76: the run there found a TS18048 in the new test's fixture (d.metadatapossibly undefined).07a84d2e10fixes it.Acceptance notes
Real-store bench, restated to the parent scope by the ruling. 200,000 passages of 1,536 dimensions, clustered synthetic (the data model of
scoped-recall-floor8-retry-sim.py: latent 384, 200 clusters, sigma 1.0). Thefile:store was built through the adapter: upsert 149 s,completeBuildwith the one-bit index 8.1 s, 1.72 GB.topK10. Each query was run by the exact scan (an adapter atvectorIndexThreshold: Infinity, which is also the recall truth) and by the adapter under test, interleaved.metadataterm over abucketkey holding 10, 15 or 20 of 100 buckets.main's rule.os-verify-lock(VERDICT command-exit 0) on head 6c530b0; later commits change only a test line. The box was shared (load 1.6 to 3.3 on 4 cores), and each row's exact column is that same run's.Record-scope control (this head): the second pass never runs (0 of 150), and the path is the floor-8 rule.
Under a record scope, the ungated second pass measured 333, 313 and 407 ms p95 against 128, 207 and 265 ms for the exact scan (os-dev-report 7235999186). That is why the record-only path is left alone here. The floor-8 path's own excess over the exact scan in the table above belongs to the separate card the ruling files.
gen.py(5 s) plus a 200,000-passage build (about 160 s).Verification
Read first, by risk:
turso-adapter.ts,searchAttempt: therecordScopeflag set in the scope loop, theapproximateandstandsclosures, and the order first pass, second pass, exact.turso-adapter.ts,VECTOR_RETRY_POOL: the gate: the first pool timesVECTOR_RETRY_POOLis at leastVECTOR_MIN_POOL * topK.acceptance.test.ts, the fixture of the new case: which tags hold which passages.Two-minute check:
Expected: 2 passed, one per store kind. Then, in
searchAttempt, replace the whole condition of theifthat guardsapproximate(candidates * VECTOR_RETRY_POOL)withfalseand run it again: both turn red with{ approximate: 1, exact: 1 }.Generated by Claude Code