Repository navigation
perf(knowledge-turso): a narrow record-only scope goes straight to the exact scan - #38327
Conversation
… exact scan Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP
…e of its ids; tests Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP
…two sources Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP
…ll of them Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP
…r and its bench Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP
📓 Docs Drift Check5 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 9c0b9009a8b468402d48d7ccd78540124f49e039 && git checkout 9c0b9009a8b468402d48d7ccd78540124f49e039
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 4cb162bfb9bbd4ac9f974d5d6ab1281645615765 f041d0a89858bddc6451d41e561b08fa770b35dd && git checkout -B drift-repro 4cb162bfb9bbd4ac9f974d5d6ab1281645615765 && git merge --no-ff f041d0a89858bddc6451d41e561b08fa770b35dd
node scripts/docs-audit/affected-docs.mjs --json 4cb162bfb9bbd4ac9f974d5d6ab1281645615765 |
|
repo:objectstack#1 · os-elon-musk · session_016WV4czzx9dtSEm3jWWL9c3 L1 verdict (L1-a): ACCEPT at head Review summary
Notes, not blocking.
Next: Tier S. The area marks it ready and lands it once every check is green at this head. |
|
repo:objectstack#1 · os-elon-musk · session_016WV4cwPhGV4g9p1BGQaZbP Landing · area o1-C · head
State: ready + auto-merge; #38215 closes on merge via |
Fixes #38215
Clause-②: no
Metadata-protocol: none
维护者速读
What changes
TursoKnowledgeAdapter.search, the vector leg on a generation that has the approximate index (packages/plugins/knowledge-turso/src/turso-adapter.ts).Today a scope of record terms alone (no parent term) always runs the one-bit pass first. When that pass keeps fewer than 8 x
topKcandidates in scope, the exact scan runs after it. Since the record index lets the exact scan read only the rows in scope, a narrow record scope pays for both.Now such a scope is estimated first. If the first pass's
topK x vectorIndexOverfetchcandidates are not expected to keep 1.25 x the floor in scope (VECTOR_RECORD_SCOPE_POOL, not exported), the search goes straight to the exact scan. With the default over-fetch of 40, that means a scope of under 25% of the source's passages.VECTOR_SCOPE_SAMPLE), spread evenly over the terms. A scope of 256 ids or fewer is counted exactly. A record split into many passages counts as many, and an id that names no passage counts as none. It costs about 2 ms at 200,000 passages (p50 1-2 ms on the bench).metadata) term, a search with no scope, and the whole of perf(knowledge-turso): a narrowly scoped vector search tries a wider approximate pass before the exact scan #38229's path (first pass, second pass, exact). Wider record scopes keep the first pass and its exact fallback. No option, export or stored shape changes.Tests
src/__tests__/acceptance.test.tsadds one case, run on each store kind. The corpus is 400 passages: records 000 to 039 hold five passages each, and records 040 to 239 hold one each.topKis 2 with the default over-fetch: 80 candidates, a floor of 16, and a cut-over of 100 passages. Every scope's hits equal the exact scan's.{ approximate: 0, exact: 1 }. 100 passages:{ approximate: 1, exact: 0 }. These two pin the cut-over exactly.Three existing pins move with the new path:
{ approximate: 0, exact: 1 }.{ approximate: 0, exact: 1 }. At over-fetch 8, no record scope can be expected to reach 1.25 x the floor.Ablation (on disk, through
scripts/ablation-replace.mjs): the direct-exactifis replaced byif (false). Result:Tests 2 failed | 128 skipped. The new case fails on both store kinds: at 99 passages it reads{ approximate: 1, exact: 0 }instead of{ approximate: 0, exact: 1 }. The file was restored to blobff1f06686b, equal toHEAD:, withgit diff HEADempty.Local runs on the final head
All test runs went through
os-verify-lock.eefc6556905(VERDICT command-exit 0, held 329 s, shared box):pnpm --filter @objectstack/knowledge-turso test: exit 0,Test Files 4 passed (4),Tests 280 passed (280).typecheck: exit 0.check:test-typecheckis OK (0 errors).build: exit 0, withcheck-dts-emitted2/2.f041d0a8985(README and changeset only on top ofeefc6556905):dispatch-gates --commands --repo objectstack-ai/objectstackderived 67 commands, all run on this head.check:type-check-debt(re-measured, 0 errors) andcheck:query-options-erasure.check:dual-build-cjs-loadsexited 3 (PREREQUISITE NOT MET: about 60 packages have nodistin this worktree, so it needs a whole-repo build). It is left to CI.--ran(exit codes recorded):67 derived, 66 run, 1 NOT-MEASURED, 0 UNRUN.pnpm --filter '@objectstack/knowledge-turso^...' build:VERDICT command-exit 0.test:repowas not run locally (CI'sTest Core). The diff touches no repo-project test.Acceptance notes
Real-store bench. 200,000 passages of 1,536 dimensions, clustered synthetic (the #38066 bench data: latent 384, 200 clusters, sigma 1.0, one passage per record). The
file:store was built through the adapter: upsert 171 s,completeBuildwith the one-bit index 7.0 s.topK10, with record-only scopes drawn at random.vectorIndexThreshold: Infinity, also the recall truth), then origin/main's adapter (today) and this head (head), those two alternating which goes first.os-verify-lockon a shared box (load about 6 to 8 on 4 cores), so compare within a row, not across runs.At 5% to 20%, head runs the exact scan alone (0% of queries take the one-bit pass). At 25% and wider it takes today's path (100% take the pass, with the same exact fallback share). The head column was measured on
eefc6556905;f041d0a8985changes only the README and the changeset.gen.py(5 s) plus a 200,000-passage build (about 3 min).Verification
Read first, by risk:
turso-adapter.ts,recordScopeUnderCut: the even sample over the terms, the count statement, and the comparison ofinScope x overfetchagainst1.25 x 8 x n.turso-adapter.ts,searchAttempt: the direct-exactif. It sits afterapproximateSearchableand before the first approximate statement, and it is gated byrecordScope.acceptance.test.ts: the new case's fixture (which records hold five passages) and the 99 / 100 boundary.Two-minute check:
Expected: 2 passed, one per store kind. Then replace the direct-exact
if (recordScope && ...)insearchAttemptwithif (false)and run it again. Both turn red:{ approximate: 1, exact: 0 }instead of{ approximate: 0, exact: 1 }.Generated by Claude Code