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 |
…r the running deployment does not mount (objectstack-ai#38060) repo:objectstack#1 · os-elon-musk · session_016WV4cwPhGV4g9p1BGQaZbP Fixes objectstack-ai#37961 Clause-②: no (narrowing) Metadata-protocol: narrowed Skills-docs: follow-up objectstack-ai#38158 — `skills/objectstack-ai/SKILL.md` § Knowledge Sources (its `adapter` row, added on `main` by objectstack-ai#38053) does not yet name this PR's save refusal of an unmounted adapter; objectstack-ai#38158 teaches it there. `content/docs/ai/knowledge-rag.mdx` and `content/docs/protocol/knowledge.mdx` name the refusal here ## 维护者速读 - 用户能看到什么变化:在 Studio、通过接口或用 AI(MCP)保存知识源时,如果写了本部署没装的存储(例如已退役的 ragflow 或拼错),保存会当场被拒,错误里写明知识源、写的存储名和本部署已装的存储;不写存储、或写已装的存储,照常保存。 - 为什么做:知识库检索专题(按调用者权限过滤的知识检索)的收尾一项,替写知识源的作者和 AI 解决“写错存储要到启动日志或检索报错时才发现”。 - 出错会怎样:最坏是某个本该能保存的知识源被拒;改动只在保存这一处,可直接撤回。包安装、代码注册和离线校验不经过这一检查,仍由启动日志和检索报错兜底。 - 要你做什么:无(这是收窄,按惯例走契约审核)。 ## What changes - **The check** (`packages/services/service-knowledge/src/knowledge-service.ts`, `admitAuthoredSource`): a `knowledge_source` item whose `adapter` is a string naming no adapter the running deployment has registered is refused `400 VALIDATION_ERROR`. The message names the source, the adapter and the mounted adapters, as a rule and its remedy: "it names adapter 'ragflow', which this deployment does not mount (mounted: memory), and a source's `adapter` must name a mounted store. Name one of 'memory' as its `adapter`, or leave `adapter` out, and the deployment's store holds it, or mount the 'ragflow' store and save it again." Leaving `adapter` out is offered only where an omitted adapter would be placed (the deployment's store is mounted, or one adapter is). The hunk sits beside the existing unplaced-source check (several adapters, none the deployment's), the other "which store holds it" refusal, and reads the registry at request time, after every store's `start()`: nothing is recorded. - **Not refused:** an omitted `adapter` (legal since the deployment's-store change; it is placed by `adapterIdFor`); a named adapter that is mounted. - **Doors reached:** every caller of `authoredKnowledgeSourceRefusal` (`@objectstack/metadata-core`), unchanged: `PUT /meta/knowledge_source/:name` on both transports, the MCP `save_metadata_draft` tool, and the package duplicate (`refuseDuplicatedKnowledgeSources`), which judges each source it copies for the caller and now refuses a copy whose source names an unmounted adapter, as it already refused an unplaced one. - **Not covered by this door, said in the docs and the changeset:** a package install and any other engine write (`isSystem`, skipped by `authoredKnowledgeSourceRefusal` before the knowledge service is asked); a source registered in code (`registerSource`, `KnowledgeServicePlugin({ sources })`), which registers at `init()` before its store's `start()`, so "not mounted yet" is no verdict there; `objectstack validate`, which runs with no deployment. For those, `reportUnmountedAdapters` at boot (`error`) and the `503 SERVICE_UNAVAILABLE` at index and search stay the signal. - **How the refusals at this door order:** with no knowledge service mounted, the door never reaches `admitAuthoredSource`, so the no-service refusal that objectstack-ai#38013 adds (`503`) comes before this one (`400`). Inside `admitAuthoredSource`: no identity (`403`), then the unplaced source (`400`), then this check (`400`), then no data engine (`503`), then the exposure and field gates (`403`/`503`). The code is the existing `VALIDATION_ERROR`, the sibling unplaced refusal's code: no new error code. - **Docs:** `content/docs/ai/knowledge-rag.mdx` (the not-mounted bullet) and `content/docs/protocol/knowledge.mdx` (the "Named" binding rule and guard two, source admission at save). - **ADR-0087:** semantic entry `knowledge-source-unmounted-adapter-refused-at-save` (`packages/spec/src/migrations/entries/semantic/`), registered by the changeset. ## Tests - `packages/services/service-knowledge/src/__tests__/knowledge-source-admission.test.ts`, in the `admitAuthoredSource` describe, through the real `KnowledgeService`: a retired (`ragflow`), mistyped (`memroy`) and empty adapter are each refused `VALIDATION_ERROR`/`400` naming the source, the adapter and `mounted: memory`; the refusal comes before the field gate; the system context is admitted; with none mounted the message says `mounted: none`, with two it names both; CONTROL: a mounted adapter, and an omitted one (deployment's store, two registered), are admitted. One existing fixture (`new KnowledgeService({})` in the fail-closed case) now registers the `memory` adapter its item names, so it still reaches the no-engine `503` it pins. - `packages/qa/dogfood/test/knowledge-source-unmounted-adapter-save.dogfood.test.ts`, a real booted showcase (knowledge service plus `memory`) with the MCP server: `PUT /meta/knowledge_source` refuses `ragflow` and `memroy` `400 VALIDATION_ERROR`, nothing stored (GET `404`, not registered); MCP `save_metadata_draft` with a real OAuth token (`metadata:write actions:execute`) refuses `ragflow` the same way, and no draft is stored; CONTROL: a named `memory` source and an omitted-adapter source save at both doors. <details><summary>Local runs on head 0b2a3bc (all under os-verify-lock)</summary> - Dependency closure `pnpm exec turbo run build --filter='@objectstack/dogfood^...' --concurrency=2`: exit 0 (covers `service-knowledge^...`). - `service-knowledge`: vitest Test Files 18 passed (18), Tests 573 passed (573); `typecheck` (tsc plus `check:test-typecheck`) exit 0. - `metadata-core`: Test Files 29 passed (29), Tests 1111 passed (1111); typecheck exit 0. - Door tests that pin save refusals: runtime `mcp-authoring`, `meta-save-capability-gate`, `packages-knowledge-source-gate`, `meta-type-write-capability-parity`: 4 files, 195 passed; rest `meta-write-door-capability-enumeration`, `meta-type-write-capability`: 2 files, 135 passed. - `spec` `src/migrations`: 5 files, 206 passed. New dogfood file: 4 passed (4). - **Dogfood battery** (`pnpm --filter @objectstack/dogfood test`, no shard, no path): `VERDICT command-exit 0`, held the lock 2405 s; Test Files 491 passed, 3 skipped (494); Tests 4148 passed, 68 skipped (4216). </details> <details><summary>Ablation: the check removed, both layers red; restored, green</summary> Through `scripts/ablation-replace.mjs` (anchor hit, restore trap) on the condition `if (typeof authoredAdapter === 'string' && ...)`, prefixed with an always-false string comparison carrying the marker `ABLATED_UNMOUNTED_CHECK`. - Unit leg (vitest reads `src`; marker count 1 on disk): 2 failed, 43 passed (45). Red: the two refusal cases (`ragflow: expected { admitted: true } to match object { admitted: false, ... }`). Green: the CONTROL. - Door leg: `service-knowledge` rebuilt, `ablation-dist-preflight` found the marker in `dist/` (exit 0); dogfood file 2 failed, 2 passed (4). Red: the PUT leg (`Saved knowledge_source 'ks_retired_store' ... expected 200 to be 400`) and the MCP leg. Green: the booted-store check and the CONTROL. - A first attempt spelled the mutation as a literal comparison, which the DTS build refused (TS2367), so that door leg ran with no `dist/` and is discarded; the unit leg of that attempt is the one above. - Restore: `git diff HEAD` empty, `git status --porcelain` empty, rebuilt, `ablation-dist-preflight --absent` exit 0, unit file 45 passed, dogfood file 4 passed. </details> ## Acceptance notes - The claim's file surface names `knowledge-source-admission.ts` for `admitAuthoredSource`; on 8d34c44 that function lives in `knowledge-service.ts`, beside the other adapter refusals. The admission module (`knowledge-source-admission.ts`, the gates) is untouched, so objectstack-ai#38038's gate-2 rewording and objectstack-ai#37963 do not meet this hunk; overlap-check reads clean against both. - `metadata-core` `knowledge-source-save-admission.ts` needed no threading: the verdict carries `status`/`code`/`message`, which the doors already pass through. - A source already stored with an unmounted adapter is not touched; it keeps answering `503` until it is saved again. ## Verification Read first: (1) `knowledge-service.ts` the new hunk after the unplaced-source check in `admitAuthoredSource`, and `unmountedAdapterSaveText` (remedy wording); (2) the dogfood file's MCP leg (token, `save_metadata_draft`); (3) the semantic migration entry. Two-minute check: `pnpm --filter @objectstack/service-knowledge exec vitest run --maxWorkers=2 src/__tests__/knowledge-source-admission.test.ts` shows 45 passed, three of them the new unmounted-adapter cases. <details><summary>Gates</summary> - `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack`: 118 families, all run locally on 0b2a3bc, exit codes captured before any pipe. `--ran`: "118 derived famil(ies) accounted for — 115 run, 3 NOT-MEASURED (3 DERIVED from a recorded exit 3)". - NOT MEASURED: `check:skill-examples`, reason: it reads `packages/client-react/dist`, outside the dogfood closure built here (PREREQUISITE NOT MET). - NOT MEASURED: `check:dual-build-cjs-loads`, reason: it needs a whole-tree `dist/` build (PREREQUISITE NOT MET). - NOT MEASURED: `check:type-check-debt`, reason: its re-measure build waited on the shared verify lock while this branch's battery held it, and exited 3. - Local-only: `check:skill-frame-freshness` exit 0; `check:dev-prereqs` exit 1, "38 of 110 workspace packages declare an entry point under dist/ that is not on disk" (only the dogfood closure is built in this worktree; a local reading, not a finding). - `check:adr-0087-registration`: "1 declared-breaking changeset(s), each carrying an ADR-0087 disposition ... registered knowledge-source-unmounted-adapter-refused-at-save (new here)". - `overlap-check` before the PR: "VERDICT clean exit 0" against origin/main 27ee984 and six open PR heads (objectstack-ai#38056, objectstack-ai#38050, objectstack-ai#38038, objectstack-ai#38013, objectstack-ai#37982, objectstack-ai#37963). - CI check-runs: not yet reported at the time of writing; the seat reads them. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
…rds they may read (objectstack-ai#38160) repo:objectstack#1 · os-elon-musk · session_016WV4cwPhGV4g9p1BGQaZbP Fixes objectstack-ai#37957 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:只能看到少量记录的用户(例如一千条里只能看二十条)在知识库搜索里,能搜到自己有权看的答案了;以前这些答案排名靠后时会一条都搜不到。系统身份和能看到很多记录的用户行为不变。 - 为什么做:属于“云上知识库(Turso)”这一主线,替权限范围窄的普通用户解决“明明有答案却搜不到”。 - 出错会怎样:最坏是这类用户仍然搜不到(回到以前的样子),不会多看到无权看的内容,因为每条结果仍逐条按权限复核;改动可以直接撤回,旧索引无需迁移。 - 要你做什么:无。 ## What changes **Problem.** A knowledge search re-checks every hit as the caller after ranking and refills once at `topK × 20`. A caller who may read 20 of 1,000 indexed records gets none of them when they all rank below that cap. **`@objectstack/service-knowledge`.** Before the first round, for a caller who is not the system identity (and has an engine to re-check with), each object source is narrowed to the records that caller may read (`sourcesNarrowedToVisible`, `readVisibleIds`): - One read per object and `where`, as the caller: `find(object, { where: source.where, fields: ['id'], limit: 501, context })`. - 500 or fewer ids: the source is handed one `record` scope term holding them, so the adapter ranks only those rows. - The adapters OR their scope terms, so the visible ids are INTERSECTED with a caller-given record scope (`narrowToVisible`, a pure function in `knowledge-search-scope.ts`), never appended: a one-record scope stays one record. - Unchanged path (searched exactly as before): more than 500 ids; a caller scope holding a parent (`metadata`) term, the card's first option, since a union of terms cannot say "this parent AND these records" without an adapter contract change; a narrowing that names no record (so a caller who reads nothing is answered as before, no hit or the source's refusal, never a new kind of empty); a read that fails (logged at `warn`); the system identity. - The rounds, the refill, the per-hit permission re-check and the organization filter are untouched. The removed-hit count is still never returned. **`@objectstack/knowledge-turso`.** `passageTableDdl` adds `CREATE INDEX TABLE_record ON TABLE (source_record_id)`. New generations carry it; an existing generation gets it from its next build. No migration. **`@objectstack/knowledge-pgvector`.** Its DDL lacked the index too: `vectorTableDdl` adds `CREATE INDEX IF NOT EXISTS "TABLE_record" ON TABLE (source_id, generation, source_record_id)` (the table is shared by every source and generation, hence the prefix). **Conformance harness** (`@objectstack/service-knowledge/testing`): its engine double answers the caller's visible-id read under the case's `wall`, and one new case runs the narrowed search through each real adapter. Docs: `content/docs/protocol/knowledge.mdx` (the re-check paragraph, both stores' table lines). Changeset: patch on the three packages. ### Read first 1. `packages/services/service-knowledge/src/knowledge-search-scope.ts`, `narrowToVisible`: the intersection. A union here would widen a caller's own scope; ablation A1 below. 2. `packages/services/service-knowledge/src/knowledge-service.ts`, `sourcesNarrowedToVisible` / `readVisibleIds`: the read as the caller, the 500 bound, the fall-backs. 3. `packages/plugins/knowledge-pgvector/src/sql.ts`: the new index on an existing shared table (see Acceptance notes). ## Tests All on head `27b7a296bb` (after merging `origin/main` 9726bd8), under `scripts/pm/os-verify-lock.sh`. <details><summary>Package suites and typechecks: all exit 0</summary> ``` build closure (service-knowledge, knowledge-turso, knowledge-memory, knowledge-pgvector ^...) B=0 @objectstack/service-knowledge Test Files 19 passed (19) Tests 677 passed (677) typecheck 0 @objectstack/knowledge-turso Test Files 4 passed (4) Tests 235 passed (235) typecheck 0 @objectstack/knowledge-memory Test Files 3 passed (3) Tests 66 passed (66) typecheck 0 @objectstack/knowledge-pgvector Test Files 3 passed | 7 skipped (10) Tests 14 passed | 90 skipped (104) typecheck 0 ``` The pgvector live-Postgres files skip here (no Postgres server in this container): the pgvector index and the conformance case through pgvector are NOT MEASURED locally. </details> New pins: - `knowledge-service.test.ts`, describe "a narrow caller's search ranks only the records they may read" (13 cases): 20 of 1,000 readable, all ranked 900th to 919th, answered best first in one round; more than 500 readable takes the path before (control: none reached); exactly 500 narrows, 501 does not; a one-record scope stays one record; mixed readable/unreadable scope ids keep only the readable, in the caller's order; no readable id in scope, and no readable record at all, search as before; a parent term reads nothing and hands the caller's terms unchanged; the system identity reads nothing and is handed no scope; the organization filter is handed beside the narrowed term, equal to the unnarrowed path's; the source's `where` is the read's `where`, one read for two sources sharing it; a failed read warns and searches as before; a record the read answered but the re-check refuses is not served. - `knowledge-search-scope.test.ts`: `narrowToVisible` (7 cases). - Conformance (`testing.ts`, through memory and turso): a caller who may read only the two clauses every other outranks is answered from them past the refill cap; their one-record scope stays one record. - `knowledge-turso` acceptance: `EXPLAIN QUERY PLAN` of the adapter's own scoped search SQL (captured from the client) shows `USING INDEX TABLE_record` and no scan of the passage table. Fixture updates (same assertions, now naming the extra caller read): three pins that counted the caller's reads (`drops hits the user cannot read`, `the permission re-read stays one query as the caller`, `passes the caller's context to the row-level re-check`) now see the visible-id read before the re-check. <details><summary>Ablations: each mutation reds its pins, then restored (git status clean after)</summary> ``` A1 intersection -> union (visible ids appended as one more term) 8 failed | 205 passed exit=1 incl. "a caller's one-record scope stays one record", "a one-record scope stays one record however many ids are visible", "20 records, two of them in scope, topK 5", "a caller scope naming readable and unreadable records" A2 no narrowing at all 7 failed exit=1 incl. "a caller who may read 20 of 1,000 records is answered from their 20" A3 the 500 bound dropped 2 failed exit=1 "control: ... more than 500 records takes the path before", "exactly 500 ... still narrow; 501 do not" A4 the system identity narrowed too 1 failed exit=1 "the system identity: no read, no scope handed, one round of topK" A5 the organization filter dropped when narrowing 1 failed exit=1 "the organization filter is handed as before beside the narrowed term" A6 turso source_record_id index removed from passageTableDdl 2 failed (memory and file: URL) exit=1 ``` </details> ## Measurements (amendment) Scratch script, not committed: 100,000 passages (one per record) bulk-loaded into one turso generation table (`file:` database, 64-wide fake embedder), the adapter's own search SQL captured and planned. Shared box, so read the ratios. <details><summary>EXPLAIN QUERY PLAN, 20 visible ids of 100k passages</summary> ``` SEARCH knowledge_bench_g1 USING INDEX knowledge_bench_g1_record (source_record_id=?) vector leg SEARCH knowledge_bench_g1 USING INDEX knowledge_bench_g1_record (source_record_id=?) keyword leg candidates SEARCH knowledge_bench_g1 USING COVERING INDEX knowledge_bench_g1_record (source_record_id=?) count(*) in scope ``` </details> <details><summary>Adapter search latency, median of 7 (index dropped: median of 3)</summary> ``` query ids with index index dropped vector-led ("zebra quokka") 20 1.1 ms 38.2 ms vector-led 500 3.3 ms 48.5 ms vector-led 2000 8.5 ms 55.2 ms vector-led, unscoped topK 100 59.0 ms keyword-heavy (3 words each in ~30% of passages) 20 232.4 ms 346.3 ms 500 240.9 ms 376.4 ms 2000 262.9 ms 388.8 ms keyword-heavy, unscoped topK 25 521.6 ms; topK 100: 533.0 ms ``` </details> The 500 cap is not raised. 500 to 2,000 ids costs about 2.6x on the vector leg (3.3 to 8.5 ms) and about 1.1x on a keyword-heavy query. ## Acceptance notes - This PR raises recall. With the index the narrowed vector leg reads only the named records' passages. The keyword leg's candidate set is still the FTS matches of each term ANDed with the scope (the plan above: `MULTI-INDEX OR` over the FTS matches), so a query of very common words still costs FTS-match time. Measured, not filed: no contract or recall defect. - pgvector: `CREATE INDEX IF NOT EXISTS` runs on an existing table at the first write or build per process after the upgrade. It is not `CONCURRENTLY`, so writes to that table wait while it builds. Same shape as the existing keyword index's creation. - `find` does not promise `min(limit, remaining)` rows (an `afterFind` hook may drop rows from a page). If a hook drops rows from the 501-row page, a caller with more than 500 rows could be read as having 500 or fewer, and their search narrowed to a subset. Recall only, never exposure: every hit is still re-checked. The platform's row security is pushed into the query, not into `afterFind`. - An index name `TABLE_record` shares SQLite's table/index namespace with a legacy table name `knowledge_SOURCE` only for a source id ending in `_gN_record`. The existing `TABLE_document` index has the same property. - Overlap: `node scripts/pm/overlap-check.mjs` on the branch before the merge: `VERDICT clean exit 0` against `origin/main` and objectstack-ai#38060, objectstack-ai#38056, objectstack-ai#38050, objectstack-ai#38038, objectstack-ai#38013. objectstack-ai#38056 (F6) shares `sql.ts` and the turso acceptance file and merges cleanly. Whichever lands second merges main. ## Verification Two minutes: `pnpm --filter @objectstack/service-knowledge exec vitest run --maxWorkers=2 src/__tests__/knowledge-service.test.ts -t "narrow caller"`. Expect 13 passed. Then `pnpm --filter @objectstack/knowledge-turso exec vitest run --maxWorkers=2 src/__tests__/acceptance.test.ts -t "source_record_id index"`. Expect 2 passed (`:memory:` and `file:`). Local gate families (`dispatch-gates --commands`) NOT MEASURED: the run was denied by the session's action classifier. CI runs them all. --- _Generated by [Claude Code](https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
…approximate pass before the exact scan (objectstack-ai#38229) Fixes objectstack-ai#38066 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:托管版大知识源上,按上级记录(例如某个客户名下)限定、只覆盖一到两成内容的检索,从约 0.9 秒降到约 0.35 秒;按具体记录限定的检索保持原样。 - 为什么做:属于“云上知识库(Turso)”主线,替检索范围窄的用户提速;席位已按实测把范围收窄到这一种限定方式。 - 出错会怎样:最坏是多做一次近似检索后照旧逐条比对,结果与以前一致、只慢约 0.2 秒;召回率实测与原规则相同;改动可以直接撤回,无需迁移。 - 要你做的:无。 ## 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 `topK` of its `topK x vectorIndexOverfetch` candidates in scope. Such a leg now first runs one more approximate pass over 10 times the candidates (`VECTOR_RETRY_POOL`, not exported), with the same `WHERE` and 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: - **The scope cannot use the record index.** That means no scope, or a scope with at least one parent (`metadata`) term. A scope of record terms alone keeps today's path, because since objectstack-ai#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. - **The first pool says the wider pass can clear the floor**, that is pool x 10 is at least 8 x `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.ts` gets 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; `topK` is 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. - **Record-only control** (the `wide` passages 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 to `HEAD:` (`git hash-object` 5573a5c on both sides), with an empty `git status`. <details><summary>Local runs on the final head</summary> All ran on head `07a84d2e10` (origin/main `2d95781690` merged), under `os-verify-lock` (`VERDICT command-exit 0`, held 1,194 s). - **Typecheck:** `pnpm --filter @objectstack/knowledge-turso typecheck` exits 0. `check:test-typecheck` is OK (0 errors). - **Tests:** `pnpm --filter @objectstack/knowledge-turso exec vitest run --maxWorkers=2` exits 0, with `Test Files 4 passed (4)` and `Tests 278 passed (278)`. - **Derived gates:** `dispatch-gates --commands` derived 67 commands at `07a84d2e10`. 66 ran, and each exited 0. - `check:dual-build-cjs-loads` was left to CI. A first pass refused it with exit 3 (`PREREQUISITE NOT MET`: 60 packages have no `dist` in this worktree; it needs a whole-repo build). - Reconciled with `--ran`: `67 derived, 66 run, 0 NOT-MEASURED, 1 UNRUN`. The one UNRUN is that gate. - **Tests on `5447b42c76`:** the run there found a TS18048 in the new test's fixture (`d.metadata` possibly undefined). `07a84d2e10` fixes it. </details> ## 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). The `file:` store was built through the adapter: upsert 149 s, `completeBuild` with the one-bit index 8.1 s, 1.72 GB. - Each share ran 50 vector-only queries at `topK` 10. Each query was run by the exact scan (an adapter at `vectorIndexThreshold: Infinity`, which is also the recall truth) and by the adapter under test, interleaved. - The parent scope is one `metadata` term over a `bucket` key holding 10, 15 or 20 of 100 buckets. - "Floor 8" is this head with the second pass ablated on disk, which equals `main`'s rule. - Everything ran under `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. | Parent scope | Exact scan p95 | Floor 8 p95 | Second pass p95 | recall@10, floor 8 / second pass | Sent exact, floor 8 / second pass | |---|---|---|---|---|---| | 10% | 810 / 848 ms | 947 ms | **351 ms** | 1.000 / 1.000 | 100% / 0% | | 15% | 824 / 907 ms | 948 ms | **328 ms** | 1.000 / 1.000 | 100% / 0% | | 20% | 910 / 908 ms | 974 ms | **337 ms** | 0.986 / 0.986 (worst 0.8 on both) | 44% / 0% | - The exact column gives two readings: the one from the floor-8 run, then the one from the second-pass run. - **Ablation pin on the bench.** With the second pass removed, the share of queries sent exact goes back up from 0% to 100%, 100% and 44%. - **Statement costs (p50):** the first one-bit pass (400 candidates) takes 115 to 119 ms, and the second (4,000) takes 168 to 175 ms. - **The recall at 20% is the first pass's.** The 56% of queries that clear the floor in the first pass are answered there, under both rules. The second pass answered the other 44% with the exact scan's top 10. **Record-scope control** (this head): the second pass never runs (0 of 150), and the path is the floor-8 rule. | Record scope | Exact scan p95 | This head p95 | Sent exact | |---|---|---|---| | 10% | 135 ms | 262 ms | 100% | | 15% | 177 ms | 345 ms | 98% | | 20% | 269 ms | 422 ms | 48% | 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. - **Caveats.** - Synthetic vectors only, as in objectstack-ai#38056. - The bench is a scratch script and is not committed. Its data was deleted after the run; rebuilding it is `gen.py` (5 s) plus a 200,000-passage build (about 160 s). - A hybrid query also re-runs its keyword leg in the second statement. This bench measured vector-only queries. - **Out of scope, noted:** none beyond the ruling's separate card. ## Verification Read first, by risk: 1. `turso-adapter.ts`, `searchAttempt`: the `recordScope` flag set in the scope loop, the `approximate` and `stands` closures, and the order first pass, second pass, exact. 2. `turso-adapter.ts`, `VECTOR_RETRY_POOL`: the gate: the first pool times `VECTOR_RETRY_POOL` is at least `VECTOR_MIN_POOL * topK`. 3. `acceptance.test.ts`, the fixture of the new case: which tags hold which passages. Two-minute check: ``` pnpm --filter @objectstack/knowledge-turso exec vitest run --maxWorkers=2 src/__tests__/acceptance.test.ts -t "tries 10" ``` Expected: 2 passed, one per store kind. Then, in `searchAttempt`, replace the whole condition of the `if` that guards `approximate(candidates * VECTOR_RETRY_POOL)` with `false` and run it again: both turn red with `{ approximate: 1, exact: 1 }`. --- _Generated by [Claude Code](https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
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