Repository navigation
perf(knowledge-turso): compute the keyword leg once a search; send a scope too narrow for the approximate pass straight to the exact scan - #38697
Conversation
…statement; a request past its bound answers TIMEOUT A search with a record scope or a metadata filter read its WHERE row by row in the vector leg, the keyword candidates and the keyword count, and the keyword candidates were computed twice in one statement. Each was a pass over the passage table; on a remote libSQL database a scoped statement went past the 10 s request bound. The WHERE is now read once a statement into a materialized scope set that every other read looks up by chunk id, and the keyword candidates are materialized. A request past requestTimeoutMs answers TIMEOUT (504), "did not answer in time", instead of SERVICE_UNAVAILABLE "is not ready". Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JQwxbaAVoqUQiPmxMVpLst
…UT too Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JQwxbaAVoqUQiPmxMVpLst
…scope too narrow for the approximate pass straight to the exact scan The first statement of a search computes the keyword leg; a wider approximate pass or the exact scan after it binds the ranks it answered. A scope with a parent term or a metadata filter has its share estimated from 256 rows read by rowid and, under the record scope's cut, goes straight to the exact scan. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JQwxbaAVoqUQiPmxMVpLst
📓 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 — 3 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 5d72fa8c2ba0a7ed7db684b9670090fd3083362a && git checkout 5d72fa8c2ba0a7ed7db684b9670090fd3083362a
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 751e83941b805879e98a210539d242511021a505 7eed5616d6bd6184f8cf96e54cf7bee8a0331dbd && git checkout -B drift-repro 751e83941b805879e98a210539d242511021a505 && git merge --no-ff 7eed5616d6bd6184f8cf96e54cf7bee8a0331dbd
node scripts/docs-audit/affected-docs.mjs --json 751e83941b805879e98a210539d242511021a505 |
|
repo:objectstack#2 · os-warren · session_01JQwxbXyLoBzNYY1U8SNPFu 维护者速读
席位核对ACCEPT · L1 · area o2-A · Head-sha
|
…-slovhl-38676 # Conflicts: # packages/plugins/knowledge-turso/README.md # packages/plugins/knowledge-turso/src/__tests__/scope-plan.test.ts # packages/plugins/knowledge-turso/src/turso-adapter.ts
|
repo:objectstack#2 · os-warren · session_01JQwxbXyLoBzNYY1U8SNPFu 2026-11-30T08:09Z · Landing · seat ACCEPT 7270081145 at
|
… mode (objectstack-ai#38721) <!-- claude-projects-attribution: {"github_login":"os-warren"} --> _Requested by **Warren** · [project thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8QCBjsNDZa4iwo35VN5fKKg)_ Part of objectstack-ai#38692 Clause-②: yes (widening) Metadata-protocol: none ## 维护者速读 - 使用 turso 存储的知识源可以按选定方式检索:只按意思、只按字词或两者结合;不选仍是两者结合,结果与现在逐位相同。 - 属于知识管理专题「一期 a:检索方式」。 - 出错会是某种方式漏掉或多出段落;未声明方式的知识源不受影响,可直接撤回。 - 无。 ## Stack Base: `main`. objectstack-ai#38697, the spec PR objectstack-ai#38720 and the phase-0 ADR note objectstack-ai#38714 are all merged and `main` is merged in, so this diff is the adapter's own 6 files. It lands in the same release as the service PR objectstack-ai#38722, which is the first reader of the mode. ## What changes - `knowledge-turso` reports `capabilities.retrieval = { modes: ['vector', 'keyword', 'hybrid'], default: 'hybrid' }`. - A search runs only the legs its mode names, in SQL: `keyword` binds no vector and never calls the embedder (nor reads the one-bit approximate index); `vector` drops the FTS5 leg. - A single-leg answer is scored on the same RRF scale: rank n scores 61/(60+n) after normalising, so the first hit is 1. `hybrid` is unchanged; `fuse(rows, topK, legs)` keeps the two-leg expression bit-identical. - README "Retrieval modes" paragraph, protocol doc §4.2 sentence, patch changeset. - A mode the store does not list is refused (`400 VALIDATION_ERROR`) before anything is embedded or read, rather than run on the one-leg scale (review S1). `Clause-②: yes (widening)`: the exported adapter's `capabilities` grows `retrieval` (review M1). ## Tests - New `retrieval-modes.test.ts` on a real libSQL store: legs per mode, embedder calls, tie order by chunk id, single-leg scores, keyword never reads `vector1bit(` while vector does, hybrid fusion pinned bit-for-bit. - Contract suite with `implements.retrieval: true`. - `knowledge-turso`: 319 passed at 2496e51 (the refused-mode case added); typecheck clean. Ablation: keeping the keyword leg under `vector` turns 3 cases red, restored. ## Acceptance notes - With the service PR applied on top, the full turso suite (326, including the service-level mode cases) passes. ## Verification - Two-minute check: `pnpm --filter @objectstack/knowledge-turso exec vitest run src/__tests__/retrieval-modes.test.ts` → all pass. ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. - [ ] 4. One issue, one branch off an up-to-date `main`, one pull request. (Stacked: see "Stack" above.) - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [ ] 6. `packages/spec` touched: its generated artifacts are regenerated and committed. (Not touched.) - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. - [x] The *Before Submitting* list in CONTRIBUTING.md is done. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01JQwxbaASqBozmmj1n5tbUf <!-- signed: repo:objectstack#2 · os-warren · session_01JQwxbaASqBozmmj1n5tbUf --> --------- Co-authored-by: Claude <noreply@anthropic.com>
Requested by Warren · project thread
Part of #38676
Stacked on #38693. The base is that PR's branch, so this diff shows only #38676's commit. After #38693 lands, main is merged in and the PR is retargeted to
main.What changes
packages/plugins/knowledge-tursoonly (turso-adapter.ts,sql.ts, tests, README).kw AS (SELECT … FROM json_each(?n))) instead of matching up to 16 terms again. A statement binds only the shared values (query vector, scope and filter values,topK), the ranks, and its candidate count.filter, has its share estimated byscopeSampleSql: 256 rows at evenly spread rowids, withmin(rowid)/max(rowid)seeks for the bounds, so no pass over the table. The cut is the record scope's (VECTOR_RECORD_SCOPE_POOL: 25% of the passages at the default over-fetch of 40).Not built here: cause 3, the question embedded again on the second round. The adapter embeds once per
search()call. The repeat comes fromservice-knowledge's secondsearchRoundcallingadapter.searchagain. That file is held by #38660 and is outside this order's surface, so #38676 stays open for it (see the os-dev report on the card).Why
Re-measured on #38693's head (d3c750a), on the same local corpus as #38693: a
file:libSQL with 59,621 one-passage records, 1,024 dimensions, approximate index built, and the 16-term Chinese question. Total per search (statements):topK40topK8 shows the same pattern: the leaf unit went from 318–372 to 143–147 ms and the division from 227–507 to 210–214 ms.Verification
turso-adapter.tsandsql.tsreverted to fix(knowledge-turso): a scoped search reads its passage table once a statement; a request past its bound answers TIMEOUT #38693's head, 10 of 301 tests fail:scope-plan.test.ts: across one search's statements,MATERIALIZE candappears once, in the first.acceptance.test.tsretry case, rewritten for the new routing: the wide pass and the exact scan after a short first pass bind the keyword ranks (computed: 1, bound: 1); a 1% scope goes exact alone; the sample's plan reads the table bySEARCHonly, neverSCAN; each pass binds exactly what it reads.{approximate: 0, exact: 1}, and a parent-term scope over the cut still takes the first pass.exacttwin comparisons).pnpm --filter @objectstack/knowledge-turso test: 5 files, 301 tests pass.pnpm typecheckpasses. eslint on the changed files is clean.check:issue-citations,check:doc-authoring,check:objectql-double-limit,check:where-matcherandcheck:empty-changesetexit 0.Clause-②: no
Metadata-protocol: none
Human Minimum
packages/specholds no runtime logic. (not touched)pnpm lintwas not run locally.packages/spectouched: not touched.content/docs/references/,packages/*/CHANGELOG.mdorcontent/docs/releases/.🤖 Generated with Claude Code
https://claude.ai/code/session_01JQwxbaAVoqUQiPmxMVpLst