Repository navigation
perf(knowledge): embed the search question once per search, the refill round included - #38798
Conversation
…he vector to every round The knowledge service now embeds a question at most once per adapter per search, through the adapter's new optional embedQuery, and hands the vector to both the first round and the refill as AdapterSearchOptions.queryVector. turso and pgvector implement embedQuery and rank with a handed vector instead of embedding again. A keyword search embeds nothing; an adapter without embedQuery embeds on every call, as before. Claude-Session: https://claude.ai/code/session_01JQwxbXfgA45f3y5YpDPT5h Co-authored-by: Claude <noreply@anthropic.com>
…gvector Claude-Session: https://claude.ai/code/session_01JQwxbXfgA45f3y5YpDPT5h Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JQwxbXfgA45f3y5YpDPT5h Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 4 package(s): 5 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
⛔ 3 release-owned page(s) also name something this change touched. These are read-only:
What this run could not see
Coarse fallback — 183 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 1ddba5052a7ca3c86566feb443079db0d2f89733 && git checkout 1ddba5052a7ca3c86566feb443079db0d2f89733
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 13a0d3fedf45a0d47630e8aa16aaa7d22591795c e434583729f51a1ed49d6bc4c53f227bd23ea4d1 && git checkout -B drift-repro 13a0d3fedf45a0d47630e8aa16aaa7d22591795c && git merge --no-ff e434583729f51a1ed49d6bc4c53f227bd23ea4d1
node scripts/docs-audit/affected-docs.mjs --json 13a0d3fedf45a0d47630e8aa16aaa7d22591795c
|
…earch Claude-Session: https://claude.ai/code/session_01JQwxbXfgA45f3y5YpDPT5h Co-authored-by: Claude <noreply@anthropic.com>
… it hands back Claude-Session: https://claude.ai/code/session_01JQwxbXfgA45f3y5YpDPT5h Co-authored-by: Claude <noreply@anthropic.com>
|
repo:objectstack#2 · os-warren · session_01JQwxbXfgA45f3y5YpDPT5h Contract reviewServed-tier: Rendered by an isolated review sub-agent of this seat's thread; the seat adopts it as written. PR #38798, card #38676 (cause 3, route A of 7269702419). Read: the card body and its comments, the PR body and file list, the net diff against ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgment
M1 (must-fix) — the two members are added to a closed list with no dated note on the record that closes it. ADR-0161 K8, "What counts as a member": "a method or a descriptor on
S1 (should-fix) — K8 rule 1: "A member lands with its first reader, in the same PR, and with a case in the contract test suite." Against the scenario accepted (cause 3: a refilled search embedded twice): the member pair removes the second embed, and
S2 (should-fix) — the embed now runs before every gate the adapter's The rest agrees with the contract sentence by sentence: one slot per adapter instance per N1 (nit) — the N2 (nit) — if the embedder answers no vector, the slot resolves to
N3 (nit) — a handed vector of another width is refused with "the embedder answered a N-wide query vector" (operator line only).
N4 (nit) — on M1 fails the round. M1, S1 and S2 each earn a delta review of their fix. Implemented-by: VERDICT: FAIL |
|
repo:objectstack#2 · os-warren · session_01JQwxbXfgA45f3y5YpDPT5h CI note on head |
…ls where it embeds The knowledge service no longer embeds the question ahead of search. It hands every search call to an adapter instance that has embedQuery one memoised function per instance per search; turso and pgvector call it at the line where they embed today, after every refusal they answer first (ADR-0161, the dated note of 2026-12-01 under K8). Claude-Session: https://claude.ai/code/session_01JQwxbXfgA45f3y5YpDPT5h Co-authored-by: Claude <noreply@anthropic.com>
…ce, both stores and the contract suite Per store: a rebuild-required source behind a failing embedder answers KNOWLEDGE_REBUILD_REQUIRED 409 with 0 embedder calls; keyword embeds nothing; a refilled search over two sources of one instance embeds once. The contract suite gains one embedQuery case, wired into turso and pgvector (ADR-0161, the dated note of 2026-12-01 under K8). Claude-Session: https://claude.ai/code/session_01JQwxbXfgA45f3y5YpDPT5h Co-authored-by: Claude <noreply@anthropic.com>
…s the per-search function Claude-Session: https://claude.ai/code/session_01JQwxbXfgA45f3y5YpDPT5h Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JQwxbXfgA45f3y5YpDPT5h Co-authored-by: Claude <noreply@anthropic.com>
|
repo:objectstack#2 · os-warren · session_01JQwxbXfgA45f3y5YpDPT5h Contract reviewServed-tier: Delta review, rendered by an isolated review sub-agent of this seat's thread. PR #38798, card #38676 (cause 3, phase 1 of ruling 7296268226). It follows record 7290045524 (FAIL at Read:
The test files, the changeset and the docs prose were read only to judge; they are the lane seat's ACCEPT. ① Derived judgments
② Semver level
③ Boundary flagsReport 7302286394 has no open question. Its deviations:
Its out-of-scope notes:
Further checks:
④ Design judgmentNo must-fix, no should-fix.
Tried to break it; each held.
Findings of 7290045524
Findings of 7297709290
New nits N1 (nit) — the suite case reads only an adapter whose N2 (nit) — the suite holds a third store to less than the member's docblock asks.
N3 (nit) — no pin mixes, on one instance, a source that asks and fails with one that never asks ( N4 (nit) — "a search that ranks nothing" costs no embedding call in the member's docblock, §3.4 and the changeset. After the removed service case, no count pins it on the handed path. It rests on the two unchanged early returns. Also, the Implemented-by: VERDICT: PASS |
|
repo:objectstack#2 · os-warren · session_01JQwxbXfgA45f3y5YpDPT5h 席位核对ACCEPT at head
Contract review → comment 7302448873 |
…n once, and its refusals stay ahead of the embed (objectstack-ai#38812) <!-- claude-projects-attribution: {"github_login":"os-warren"} --> _Requested by **Warren** · [project thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8WwwNJsfXjR7KkaXqjQxjFx)_ Part of objectstack-ai#38676 **Update, head `a28863cef9`.** PR objectstack-ai#38809 (card objectstack-ai#38438) landed first, at 2026-12-01T03:58Z, and took the seventh and eighth `**Amended**` lines of ADR-0161. This head merges `main` into the branch (merge commit `a28863cef9`, no rebase): main's lines are kept as they are, this PR's header line follows them, and its ordinal reads "a ninth dated note". That one word is the only change to this PR's text (delta report 7300564224 on objectstack-ai#38676); the net diff against `main` is still this note alone, +17 / -0. The gate readings and the overlap paragraph further down are of the earlier head `f3cd7dba76`; the 21 derived gates were re-run at `a28863cef9`, all exit 0. This is phase 0 of the card's cause 3 and nothing else: the dated note in ADR-0161. The card stays open for phase 1, the patch round on PR objectstack-ai#38798, which waits for this note to merge. Clause-②: yes (widening) — the two optional adapter-contract members the note registers Metadata-protocol: none The two lines above are the claim's (comment `7296290387` on the card) and cover both phases. This pull request changes no contract file: the widening is what the note registers and PR objectstack-ai#38798 builds. ## 维护者速读 - 用户能看到什么变化:用户无感;只是在知识平台边界那份架构决策记录里追加一条 2026-12-01 的说明,把你当天选定的「写进约定,一次提问只转一次」和它的附带条件写成文字,不改任何代码。 - 为什么做:这是「知识检索慢」那张卡最后一项(补查时把同一个问题重复转成向量)的前置一步;平台和存储驱动之间的约定是一份封闭清单,要先在决策记录里登记这两项,已经做好的改动才能合并。 - 出错会怎样:说明里若有和你的裁决不一致的句子,接下来改代码的人会照着错的文字去做;它只是一处文档追加,可以直接撤回,不影响任何在运行的系统。 - 要你做什么:请审阅并批准这条说明;其中标了菱形记号的两处是说明自己定的写法,可以一并接受,也可以划掉。 ## What changes One file, add-only. `docs/adr/0161-knowledge-platform-boundary-platform-owns-assembly-sync-split-record-return-knowledge-source-is-a-governed-type.md` gains its ninth dated note: 17 lines added, none changed and none removed (659 lines to 676 on `main` after objectstack-ai#38809). Three commits carry it, the third being the merge of `main`, `a28863cef9`: `f00518e716`, the note, and `f3cd7dba76`, a review pass over it (Acceptance notes). **Ruling.** The maintainer chose option A for cause 3 on 2026-12-01T00:22Z: ruling record [`7296268226`](objectstack-ai#38676 (comment)) on the card, given on analysis `7290428149`. He ruled by choosing an option of a decision card, and the note quotes the card's words unchanged: the option 「写进约定,一次提问只转一次」 and the condition 「附带条件:存储驱动原本会给出的拒绝提示(比如“需要重建索引”)要保持在前面,不能被转向量的报错盖掉。」 Nothing of the ruling is opened again here. Three insertions, in the form the six earlier notes of this record use. Line numbers are at head `a28863cef9`. | Lines | Where | What is added | |---|---|---| | 27 | Header, after the `**Amended**` line of the eighth note | A ninth `**Amended**` line, dated 2026-12-01: the two members, the texts the note is read with, the ruling record, the chosen option and the condition. | | 166 | K1, under the note of 2026-11-30 on rerank | A cross-reference: the "Embedding calls" row, and "compute a vector" in the second sentence of the list, are read with the new note. | | 483 to 496 | K8, under "Rules for every member" | The note itself: an opening paragraph, nine bullets and a last paragraph. | What the note decides: - **Two optional members, and the list stays closed beyond them** (K8 rules 3 and 5). `IKnowledgeAdapter.embedQuery?(query: string)`, which answers a promise of a `number[]`, and `AdapterSearchOptions.queryVector?`. No capability flag: the method's presence is the signal. - **The type of the second member.** A function of no arguments that answers a promise of a read-only `number[]`. It is not the vector itself. For one search the knowledge service makes one such function for each adapter instance that has `embedQuery`. The first call of the function calls that instance's `embedQuery`; every later call in that search answers the same promise, a rejected one too. An adapter calls it at the point of its `search` where it embeds the query today. This is the per-search memoised provider the analysis recommends, and the one choice the ruling record leaves to the note. - **The three readings that M1 of contract review [`7290045524`](objectstack-ai#38798 (comment)) left open.** 1. The adapter still embeds, with its own embedder and query prefix. The service computes no vector: it carries one back to the instance that made it, inside one search. The "Embedding calls" row of K1, the second sentence of the list under it and item 15 of K8 stand as written. 2. One vector serves every source a search binds to that adapter instance. An adapter whose query embedding depends on the source does not implement the method. 3. A handed vector is checked by its width. The model is judged on the index fingerprint, as K7 has it. - **The condition, as an outcome.** An adapter's refusals are answered as on `main`, code, status and remedy, and no question is sent to an embedding provider for a source the adapter refuses. The ruling record's case: a source that needs a rebuild behind a failing embedder answers `KNOWLEDGE_REBUILD_REQUIRED` 409 with 0 embedder calls. The function gives this by construction, because an adapter asks for the vector only after everything it decides first. - **What the members land with.** PR objectstack-ai#38798, after this note merges: both members with their first readers in one PR and one case in the contract test suite (rule 1). Each is optional (rule 2), and an adapter without `embedQuery` is searched as before. - **Not in the note.** A vector handed by a caller of the service or by a tool argument, a memo an adapter keeps past one search, a source or context argument on `embedQuery`, and a form that embeds several questions at once. No file under `packages/`, `content/`, `skills/` or `ui/` changes, and no other ADR does. The note declares; it builds nothing. ## Why K8 rule 5 of this record: "The list is closed. A member that is not in the table needs a dated note on this record first." PR objectstack-ai#38798 built the two members before the record named them, and its contract review is FAIL on that point (M1). The ruling puts the record before the code: this note first, then the patch round on objectstack-ai#38798. ## Tests The diff touches no package, so there is no build closure to make and no package test or type-check owed. What was measured, at head `f3cd7dba76`: - **The premise holds.** Read on `main` at `0fc9eab900`, the commit this branch starts from. A refilled search still embeds the question twice: - `packages/services/service-knowledge/src/knowledge-service-search.ts:232` is the first `searchRound` call and `:245` is the refill's. - `:957`, inside `searchRound`, calls `adapter.search` once for each source. - `packages/plugins/knowledge-turso/src/turso-adapter.ts:741` and `packages/plugins/knowledge-pgvector/src/pgvector-adapter.ts:657` embed the query inside that call. - No line under `packages/`, `content/` or `docs/` names `embedQuery` or `queryVector` (`git grep` exit 1). - `origin/main` has since moved one commit, to `d97aaaea9a` (objectstack-ai#38802: one skill file, one ratchet script and a changeset). It changes none of the files read here, so each reading holds there too, and this branch merges with it cleanly. The branch was not merged with it. - **Quotations.** A script compared every quoted span of the added lines with its source, read over REST or from the ADR at the base. 9 spans in corner brackets: each is a verbatim substring of ruling record `7296268226`. 27 spans in double quotation marks: each is verbatim in that record, in analysis `7290428149`, in review `7290045524` or in the ADR at the base. 0 mismatches. (The nested title "What "capabilities" became" counts as two spans.) - **Bytes.** The added lines hold no raw control byte, no HTML comment and no model identifier. - **What an adapter decides ahead of its embed**, the list in the note's bullet on the condition, read in both stores on `main` at `0fc9eab900`: an empty organization set, a scope with no ids and a `topK` of zero answer no hits; the store and the embedder are present and the store is ready; the source has an active generation; that generation holds the searched fingerprint and the embedder's width, or the refusal is `KNOWLEDGE_REBUILD_REQUIRED` (409, with its remedy); the mode is one the adapter runs; and `keyword` never embeds. Each is ahead of the embed in `turso-adapter.ts` (lines 699 to 741) and in `pgvector-adapter.ts` (lines 581 to 657). - **PR objectstack-ai#38798 as it stands**, read at head `4561e81d0e`: `queryVector` is the vector itself there, a read-only `number[]`, and `embedQuery` has the signature the note writes. - **Anchors.** Every code citation in the note is a path with a symbol, never a line number, and `check:adr-symbol-anchors` reads all of them (its verdict line is below). No ablation: the diff changes no behaviour a test pins. ## Acceptance notes **The committed note took the function, not a plain array.** A plain array has to exist before `search` is called, so the service would have to embed ahead of every decision the adapter makes. A refused source would then cost an embedding call, and a failing embedder would answer in place of the adapter's own refusal. That is the shape review `7290045524` graded S2, and it cannot meet the condition. The function can, and the note names it as the means it takes. **The review pass, commit `f3cd7dba76`.** Two sentences of the note changed; nothing it decides moved. 1. The opening said that every statement without a diamond is the ruling record's, the analysis's, what follows from the means, or a reading of `main`. Some rest on review `7290045524`, on this record's own rules, on PR objectstack-ai#38798 at its head or on the body of the card. The sentence now lists them. 2. The signature of `embedQuery` is the one PR objectstack-ai#38798 declares at head `4561e81d0e`. The bullet on the two members now says so. **Two things are marked with a diamond, for the approver to accept with the note or strike.** - a. The means, and with it the member's type. Three points go with it and are the note's wording: the name `queryVector` is kept though the member is now a function; the service hands the function on every `search` call of that search and does not judge whether a call will embed; and a rejected promise is shared like a fulfilled one, so one failed embedding call refuses each source that asked for the vector in that search. - b. One sentence added to the third reading: a caller that reaches an adapter's `search` directly and hands the member answers for the function, and the adapter does not verify it. **Wording that is the note's and not a quotation**, each resting on a text named beside it: - The suite case is the one review `7290045524` asks for under S1, rewritten with the function in the vector's place. - "The condition has its own pin in each of the two stores": the ruling record says "a pin". Each store orders its own decisions ahead of its embed, so the note asks for the case in each. - The English beside the card's Chinese words is a reading aid. The Chinese is quoted unchanged. **Overlap with an open draft on this file.** `node scripts/pm/overlap-check.mjs --repo=objectstack-ai/objectstack`, run at `f3cd7dba76` against `origin/main` at `d97aaaea9a`, printed `VERDICT overlap exit 1`: `origin/main` merges cleanly, and draft objectstack-ai#38809 (the weekly ADR revisions, second part, opened 2026-12-01T00:50Z by another seat's thread) conflicts with this branch in this file. Both insert header lines after line 24, and both call their first line "a seventh dated note" (objectstack-ai#38809 adds a seventh under K7 and an eighth under Consequences). Its two notes and this one touch no common passage. Whichever lands second merges `main`, keeps both sets of header lines and corrects its ordinals. Which lands first is the seats' to settle; it is put as a question in the report on the card. **What the note asks of PR objectstack-ai#38798, none of it done here.** - `queryVector` changes type there, from the vector to the function, and the service stops calling `embedQuery` ahead of `search`. - One case in the contract test suite, and a pin in each of the two stores for the ruling record's case. - The docblocks cite the note and no longer say that the knowledge service embeds. **Text of ADR-0161 that the note is read beside. Listed for the seat, not changed.** - "What "capabilities" became" lists the methods whose absence is the capability signal (listing, dropping, status, the start and end of a build). `embedQuery` joins them by this note; the paragraph is left as written. - The K2 row for §3.4 of the protocol page says what the contract carries. Its last column gives the rewrite to "each card that adds a member", so objectstack-ai#38798 rewrites it with its code. **Not done here.** No changeset: `docs/adr/` is published by no package. The two earlier note pull requests on this record, objectstack-ai#38714 and objectstack-ai#38764, each carry the `skip-changeset` label, hung in the stroke that opened them. This one is opened with no label, as its dispatch order says, so that label is owed by the seat, and `Check Changeset` has no exemption until it is hung. ## Verification **Read first, by risk.** One file changes, so these are its three places of most risk. 1. Line 476, the bullet marked with a diamond, "The means, and with it the member's type". It is the one decision the note makes, and it sets what the patch round on PR objectstack-ai#38798 must build. 2. Line 480, the bullet "The condition, as an outcome". It states the maintainer's condition and what holds when the embedding call itself fails. 3. Line 479, the last two sentences of "The third reading": the note's own sentence on a caller that reaches an adapter directly. **Two-minute check.** One click: open the "Files changed" tab. Expected: one file, +17 −0, three hunks, every changed line an addition. **Landing.** `docs/adr/**` is a governed surface. This is opened as a draft. The hand-off is the seat's and the approval is the maintainer's. Nothing here requests a reviewer, marks it ready or arms auto-merge. **CI.** NOT MEASURED: the check-runs of this pull request, reason: it did not exist when this body was written. The report on the card carries the reading taken after it opened. **Gates, run locally on head `f3cd7dba76`.** `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` derived 21 commands from the diff. All 21 ran in the foreground, each exit code was captured before any pipe, and all 21 are exit 0. The reconciliation: ```text Run reconciliation — 21 derived, 21 run, 0 NOT-MEASURED, 0 UNRUN. ✓ dispatch-gates --ran: 21 derived famil(ies) accounted for — 21 run, 0 NOT-MEASURED (a DERIVED zero — all 21 recorded an exit code and none of them is 3). ``` <details> <summary>The 21 commands and their exit codes</summary> ```text node scripts/check-adr-links.mjs :: exit 0 node scripts/check-adr-links.mjs --self-test :: exit 0 node scripts/check-closing-keyword-parity.mjs :: exit 0 node scripts/check-closing-keyword-parity.mjs --self-test :: exit 0 node scripts/check-comment-mask-corpus.mjs :: exit 0 node scripts/ci/plan-test-core-shards.mjs --self-test :: exit 0 pnpm --filter @objectstack/lint run check:doc-formula-expressions :: exit 0 pnpm check:adr-anchors :: exit 0 pnpm check:adr-index :: exit 0 pnpm check:adr-symbol-anchors :: exit 0 pnpm check:ci-filter-parity :: exit 0 pnpm check:closed-ceremony-text :: exit 0 pnpm check:cross-package-test-inputs :: exit 0 pnpm check:doc-authoring :: exit 0 pnpm check:driver-memory-census :: exit 0 pnpm check:gitlink-declared :: exit 0 pnpm check:nul-bytes :: exit 0 pnpm check:pm-governed-merges :: exit 0 pnpm check:pm-prior-rulings :: exit 0 pnpm check:refd-timer-probe :: exit 0 pnpm check:watch-hint-literal :: exit 0 ``` </details> <details> <summary>Verdict lines of the gates that read the ADR</summary> ```text ✅ check-adr-links: 1284 relative link destination(s) under docs/adr/ resolve ✅ check-adr-symbol-anchors: 4608 anchors across 165 records resolve — 1727 symbol (1698 declaration, 29 literal), 2829 file-level, 52 cross-repo, 6 exempt, 132 continuation. [cut here: the rest of the line is a note on what the count is not] adr-index --report: OK — docs/adr/README.md is current, every record parsed, self-test 60 assertions green. Report-only: this line never reds the step. check-nul-bytes: OK (scanned 29077 text file(s) -- 29077 tracked, 0 untracked-not-ignored; skipped 101 binary; no raw ASCII control bytes). ✓ check-closed-ceremony-text: 6688 shipped file(s) read; none says the ownership ceremony is closed. ✓ comment-mask corpus sweep [scripts/js-comment-mask.mjs]: 24511 files, 0 disagree, 0 unparseable, 211.2s (comparator self-test: 26 cases pass). ``` </details> <details> <summary>One gate first read NOT MEASURED, then green</summary> `pnpm --filter @objectstack/lint run check:doc-formula-expressions` first answered exit 3, PREREQUISITE NOT MET: two workspace packages it imports were not built in this worktree. That is a run that measured nothing, not a red gate. The two packages were built under the shared verify lock, with the command the gate printed, and the gate was run again at the same head: ```text os-verify-lock: VERDICT command-exit 0 · held the lock 100s (1m40s) · waited 0s pnpm --filter @objectstack/lint run check:doc-formula-expressions :: exit 0 ``` </details> **Left to CI, not run locally.** The repo-wide lint, the type-check lanes, the test shards, and the families `dispatch-gates` prints outside the derived list. The commit trailer gate ran in the pre-push hook on the pushed range and is green. ## Human Minimum - [x] 1. No schema and no code changes. - [x] 2. No new name is declared in code. The two member names are the ones PR objectstack-ai#38798 and the analysis use. - [x] 3. No formatter ran. `pnpm lint` is NOT MEASURED locally: the repo-wide scan is CI's, and the diff is one Markdown file. - [x] 4. One card, one branch off `main` at `0fc9eab900`, one pull request for this phase. - [x] 5. Nothing publishes, so no changeset; both declaration lines are filled in above. - [x] 6. `packages/spec` is not touched. - [x] 7. No edit to `content/docs/references/`, to a `CHANGELOG.md` or to `content/docs/releases/`. - [x] 8. Title, body and comments are in English. The card's Chinese words are quoted unchanged, and the 维护者速读 section is in Chinese as the fleet's rule asks. - [x] The *Before Submitting* list is done for what a docs-only diff reaches; `pnpm lint` is as item 3 says. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01JQwxbXfgA45f3y5YpDPT5h <!-- signed: repo:objectstack#2 · os-warren · session_01JQwxbXfgA45f3y5YpDPT5h --> --------- Co-authored-by: Claude <noreply@anthropic.com>
Requested by Warren · project thread
Fixes #38676
Clause-②: yes (widening)
Metadata-protocol: none
维护者速读
What changes
The question of one knowledge search is embedded at most once for each adapter instance, by the adapter, and the knowledge service carries it back to every
searchcall of that search, the refill round included. Built to the ADR-0161 dated note of 2026-12-01 under K8 (ruling record 7296268226 on the card, with its condition: an adapter's own refusal stays ahead of the embed).@objectstack/spec/contracts):IKnowledgeAdaptergains an optionalembedQuery(query), which embeds a question exactly as that adapter'ssearchdoes (its embedder, its query prefix); it takes no source.AdapterSearchOptionsgains an optionalqueryVector, typed as a function of no arguments answering a promise of a read-only number array (() => Promise, answeringreadonly number[]). It is the function, not the vector. Both docblocks cite the note and no longer say the knowledge service embeds. Both members additive and optional.knowledge-service-search.ts,knowledge-service-top-level.ts):planSearchesgives every target whose adapter instance hasembedQueryone slot per instance for the whole search (SearchQuestion). The firstsearchRoundcall to that instance puts one memoised function in it (memoisedQuestion): its first call asks the instance'sembedQueryfor the query, and every later call in that search answers the same promise, a rejected one too. That one function is handed on everysearchcall to that instance in that search. The service no longer embeds ahead ofsearch, no longer judges whether a call embeds (the earlierkeywordand "round ranks nothing" guards are gone) and reads no vector. A rejection isembedQuery's own error, never wrapped.knowledge-turso,knowledge-pgvector: each calls the handed function at the exact line where itssearchembeds the query today, in place of that call, after every gate it runs first (nothing to rank, store and embedder present, ready, active generation, the fingerprint and width refusalKNOWLEDGE_REBUILD_REQUIRED,topK, the mode,keyword). Absent: it embeds as before, through its ownembedQuery. The width check is unchanged, and the answered array is never changed. A failed embed therefore fails insidesearch, where it failed onmain, withmain's code and wording (pgvector'ssearchRefusalOfincluded).@objectstack/service-knowledge/testing): an optionalimplements.embedQuerydeclaration, checked against the adapter, and one case for it (below).knowledge-tursoandknowledge-pgvectordeclare it.content/docs/protocol/knowledge.mdxis rewritten to the note: the function type, where the adapter calls it, what costs no embedding call, and the suite case.embedQuery(for exampleknowledge-memory) is handed nothing and searched exactly as before.mainmerged first (9e729ceaad). fix(service-knowledge): a host-mounted service with no embedder answers a search 503 naming the settings to save #38817's behaviour is kept: an embedder error reaches the caller unwrapped, and its test fileunconfigured-embedder-code-38775.test.tsis unchanged and green (6 of 6).Review findings closed by this round: M1 by the note (merged as
13a0d3fedf); S1 by the suite case; S2 by the new shape and its pins (a refusal ahead of the embed is answered, with 0 embedder calls); N4 by the new shape (the embed is back insidesearch, so pgvector's socket wording ismain's again). Nits of contract review 7290045524: N1 by the new shape (the function is handed on every call, so "every call" is literal); N2 by the new shape (an embedder that answers no vector is one embedding call, memoised, and the width check refuses it, where the earlier head made two); N3 by the new shape, wording kept: on the service's path the handed vector is what the adapter's own embedder answered, so "the embedder answered" stays true; a direct caller answers for its function (the note's second diamond).Tests
All pins count calls; none is wall-clock.
packages/services/service-knowledge/src/__tests__/search-question-vector.test.ts(rewritten, 11 cases, over a fake adapter shaped as the two stores): a refilled search hands both rounds one function and callsembedQueryonce; two sources of one instance, one function for four calls, one call; the function answers the same promise on every call; two instances, two functions, one call each; two searches, two functions;keywordis handed the function and embeds nothing; a source the adapter refuses behind a failing embedder answers its 409 with 0 calls; noembedQuery, nothing handed; an uncoded embed failure fails the call that asked (503 platform sentence, text to the operator line); a coded one reaches the adapter as the same error object and keeps code and message; a failed embed is shared (one call, both sources refused).packages/plugins/knowledge-turso/src/__tests__/acceptance.test.ts(one top-level describe, 6 cases, real adapter behindKnowledgeService): refilled search, one embedder call, prefixed; refilled search over two sources of one instance, one call;keyword, 0 calls; a source that needs a rebuild (embedder model changed) behind an embedder that fails answersKNOWLEDGE_REBUILD_REQUIRED409 with 0 embedder calls; the control, the same failing embedder behind a healthy source, called once and refused 503; a handed function is ranked with, a function of another width is refused.packages/plugins/knowledge-pgvector/src/__tests__/question-once.test.ts(new, 5 cases, real adapter andKnowledgeServiceover a fake pool): the same four pins as turso (the rebuild-required source is an index held under another fingerprint) and the same control.packages/plugins/knowledge-pgvector/src/__tests__/retrieval-modes.test.ts(3 cases, adapter alone):embedQueryembeds the prefixed query; a handed function is asked once and its answer is bound into the ranking statement, embedder not called, with a control; another width is refused.packages/services/service-knowledge/src/testing.ts#runKnowledgeAdapterContract, one case, run only forimplements.embedQuery: handed a function answering its ownembedQuery, a search answers what it answers without the member and makes no embedding call of its own; handed one answering a vector of another width (wider, then narrower), the search rejects. The count is a spy on the instance'sembedQuery(review 7297709290 N1), with a control (the search without the member is seen by the spy once). It asserts a rejection, not a code (N2); no code is added.packages/plugins/knowledge-pgvector/bench/instrument.test.mjs: unchanged since56feee7fa7, still one embed for a refilled search.Ablation (each through scripts/ablation-replace.mjs; landing and restore proven by blob hash, git diff HEAD empty after each)
search(the earlier head's order): service 6 failed of 11; turso 2 failed of 6 (keyword, rebuild-required); pgvector 2 failed of 5 (keyword, rebuild-required).knowledge-tursoignores the handed function: the contract case fails on both libSQL cells (2 of 2).Every pin goes red under at least one ablation. The
keywordpins also hold onmainand on the earlier head: they guard the order, not the count.Runs at e434583
pnpm --filter @objectstack/service-knowledge exec vitest run: Test Files 31 passed (31), Tests 896 passed (896).pnpm --filter @objectstack/knowledge-turso exec vitest run: Test Files 6 passed (6), Tests 335 passed (335).pnpm --filter @objectstack/knowledge-pgvector exec vitest run: Test Files 10 passed, 10 skipped (20); Tests 75 passed, 117 skipped (192). The live-PostgreSQL files skip here (no pgvector server in this container), so the contract case on pgvector is NOT MEASURED locally: CI's live cell runs it.pnpm --filter @objectstack/knowledge-memory exec vitest run src/__tests__/contract.test.ts: 54 passed (the suite change, an adapter without the member).pnpm --filter @objectstack/spec buildthencheck:generated: all 14 generated artifacts up to date.dispatch-gates.mjs --commands, 117 families): 116 exit 0, 1 NOT MEASURED (check:dual-build-cjs-loads, exit 3: needs every package built);--ran: 117 derived, 116 run, 1 NOT-MEASURED, 0 UNRUN.Acceptance notes
maineach made its own attempt (the note says so).embedQuery, so it reads an adapter whosesearchembeds the query through that method, as both stores do; one that embeds by another path fails the case's control, and the suite's docblock says so.knowledge-memoryhas noembedQueryand still embeds on every call; adding it there is outside this card.Verification
Read first, by risk:
packages/services/service-knowledge/src/knowledge-service-search.ts:memoisedQuestionand thequeryVectorlines at the top of the loop insearchRound. Risk: a call of the function there, ahead ofsearch, would undo the condition.packages/plugins/knowledge-turso/src/turso-adapter.tsandpackages/plugins/knowledge-pgvector/src/pgvector-adapter.ts: the one changed line wheresearchembeds. Risk: it must stay after every refusal above it.packages/spec/src/contracts/knowledge-adapter.ts: the two members and their docblocks (the contract text).Two-minute check:
pnpm --filter @objectstack/knowledge-turso exec vitest run src/__tests__/acceptance.test.ts -t 'embedded at most once'printsTests 6 passed; the fourth case asserts a 409 with 0 embedder calls behind a failing embedder.🤖 Generated with Claude Code
https://claude.ai/code/session_01JQwxbXfgA45f3y5YpDPT5h