Skip to content

Commit d316627

Browse files
feat(service-knowledge): read a source's retrieval mode and refuse a mode its store does not run (#38722)
<!-- claude-projects-attribution: {"github_login":"os-warren"} --> _Requested by **Warren** · [project thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8QCBjsNDZa4iwo35VN5fKKg)_ Part of #38692 Clause-②: no Metadata-protocol: none ## 维护者速读 - 知识源声明了检索方式后,搜索就按它执行;没声明的按存储默认。存储不支持所声明的方式时,保存时直接报错并列出可选方式,启动后记一次错误日志,每次搜索都把它列为未检索,绝不悄悄换成别的方式。 - 属于知识管理专题「一期 a:检索方式」。 - 出错会是本该能搜的知识源被拒;未声明方式的知识源行为不变,可直接撤回。 - 无。 ## Stack Base: `main`. #38700 (the facade split) has merged and `main` is merged in. The spec PR #38720 merged as f576dee and `main` is merged in, so this diff is the service's own 15 files. The phase-0 ADR note (#38714) is merged too. Independent of the adapter PRs. The Studio form PR stacks on this one. ## What changes - New `knowledge-retrieval-mode.ts`: the effective mode is the source's `source.retrieval.mode`, else the adapter's `capabilities.retrieval.default`; an adapter reporting no modes is never told one. - The four refusal points for a declared mode the adapter does not list, never searched another way: 1. save (`admitAuthoredSource`): `400 VALIDATION_ERROR`, listing the modes the store runs; 2. registration in code (`registerSource`): the same refusal, only when the adapter already resolves (startup registry reads). A published item (`registerMetadataSource`, the loader) is not refused there: the loader runs after every store has started, so a refusal would drop it whole; it is registered and indexed, and points 3 and 4 refuse it (review M1); 3. once after boot (`reportUnsupportedRetrieval`, called at `kernel:bootstrapped` beside `reportUnmountedAdapters`), at `error`; 4. every search (`planSearches`): listed in `refused` with `SERVICE_UNAVAILABLE` (503), the code an unmounted adapter's source already carries. - Every search hands the store `AdapterSearchOptions.retrieval` and logs the mode and its origin at `debug`; the caller's answer carries neither. - `index_status` entries carry `retrieval` (declared, effective mode, origin, the store's modes, refused), and the answer lists each mounted store's modes (`details.adapters`) and the store a source naming none binds to (`details.defaultAdapter`), the data the Studio form PR reads. New service member `describeRetrieval`. - Contract suite: service-level cases for every adapter (a listed mode is handed through; an unlisted one is refused at registration in code and at every search, and still indexes; a published item loaded after its store started is registered, indexes, is named by the boot reading and is refused on every search). - Liveness row flips to `live`; protocol doc §3.1 and the save guard; patch changeset. ## Tests - New `retrieval-mode-38692.test.ts` (16 cases): resolution, refusal text, each refusal point, debug log and its absence from the answer, still indexes, the loader path (a published item with its store already started), plugin hook, `index_status`. - `service-knowledge`: 861 passed (26 files, at 1a7ba24); typecheck clean. `knowledge-memory` 70 passed and `knowledge-turso` contract 110 passed against this head's suite. `knowledge-memory` contract 54 passed; `knowledge-turso` 110 contract passed; live pgvector contract 55 passed. - With each adapter PR merged in locally: turso 326 passed, pgvector against live PostgreSQL 133 passed. ## Acceptance notes - The per-search refusal code is reused rather than added: `SERVICE_UNAVAILABLE` (503), the code an unmounted adapter's source already carries. The ruling and the phase-0 note say only "with its code"; open question C, confirmed by Warren on 2026-11-30 at 12:40Z (「同意」): the refusal stays 503. - Declared `Metadata-protocol: none`: what an author can write was added by the spec PR; this PR reads it. The save refusal of a mode the store does not run is the shape the ruling gives the key from birth, in the same release. - Facade gate: `knowledge-service.ts` 1681 lines of 1758; both new members are one-call delegations. ## Verification - Two-minute check: `pnpm --filter @objectstack/service-knowledge exec vitest run src/__tests__/retrieval-mode-38692.test.ts` → 16 passed. - Related local gates (26 of `dispatch-gates.mjs --commands`: docs, liveness, changeset, facade, error-code, ledger): all green. ## 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. - [x] 6. `packages/spec` touched: its generated artifacts are regenerated and committed. - [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>
1 parent 59faf74 commit d316627

15 files changed

Lines changed: 876 additions & 23 deletions
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
'@objectstack/service-knowledge': patch
3+
'@objectstack/spec': patch
4+
---
5+
6+
feat(service-knowledge): the knowledge service reads a source's retrieval mode
7+
8+
A search of a knowledge source now runs in its effective retrieval mode: the
9+
mode the source declares (`source.retrieval.mode`), else its store's default
10+
(`capabilities.retrieval.default`). The mode is handed to the store on every
11+
search and logged at `debug` with where it came from; it is not in what a
12+
search answers the caller. `index_status` carries each source's `retrieval`
13+
(the mode, its origin, the store's modes, a refusal) and each mounted store's
14+
modes.
15+
16+
A source that declares a mode its store does not run is never searched
17+
another way. It is refused at its save (`400 VALIDATION_ERROR`, listing the
18+
modes the store runs), at registration in code (`registerSource`) when its
19+
store is already registered,
20+
once after boot at `error` (`reportUnsupportedRetrieval`), and on every search,
21+
where it is listed in `refused` with `SERVICE_UNAVAILABLE` (503). It still
22+
builds and syncs its index: a published item (a package install, the stack's
23+
`knowledgeSources`) meets no save and is registered and indexed as usual, and
24+
the boot's reading and every search refuse it. A store that reports no modes (knowledge-memory)
25+
takes only a source that leaves the mode out.
26+
27+
Clause-②: no
28+
Metadata-protocol: none

‎content/docs/protocol/knowledge.mdx‎

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,32 @@ that name (ADR-0161 K4):
182182
used, so a source registered before its store started finds it.
183183

184184
**How a source is searched: `source.retrieval.mode`** (ADR-0161, the dated
185-
note of 2026-11-30 under K8). `'vector'` ranks by meaning alone, `'keyword'`
186-
by the question's words alone (the embedder is never called), `'hybrid'` runs
185+
note of 2026-11-30 under K8). `'vector'` ranks by meaning alone, `'keyword'` by
186+
the question's words alone (the embedder is never called), `'hybrid'` runs
187187
both and merges them; omitted (or `retrieval: {}`), the adapter's default
188-
(`capabilities.retrieval.default`, `'hybrid'` on `turso` and `pgvector`). The
189-
mode is read by search alone: it enters neither the index fingerprint nor the
190-
recipe hash, so changing it rebuilds nothing.
188+
(`capabilities.retrieval.default`, `'hybrid'` on `turso` and `pgvector`).
189+
That is the effective mode, handed to the adapter on every search and logged
190+
at `debug` with where it came from; it is not in what a search answers the
191+
caller, and an administrator reads it in the source's `index_status`. A
192+
source is never searched in a mode other than the one it declares, so a mode
193+
its adapter does not list (an adapter that reports none, such as `memory`,
194+
lists none) is refused at four points:
195+
196+
1. its save (Studio, `/meta`, an MCP draft): `VALIDATION_ERROR` (400),
197+
listing the modes the store runs;
198+
2. its registration in code (`registerSource`), when its adapter is already
199+
registered: the same refusal. A store registers in its own `start()`,
200+
after a source registered at `init()`, so "not registered yet" is no
201+
verdict. A published item (a package install, the stack's
202+
`knowledgeSources`) meets no save and is not refused by the loader: it is
203+
registered and indexed, and the next two points hold it;
204+
3. once after boot, at `error`, naming the source and the modes;
205+
4. every search: the source is listed in `refused`, `SERVICE_UNAVAILABLE`
206+
(503), as a source whose adapter is not mounted is.
207+
208+
The mode is read by search alone: it enters neither the index fingerprint nor
209+
the recipe hash, so changing it rebuilds nothing, and a refused source still
210+
builds and syncs its index.
191211

192212
**What mounts the service.** A stack that ships a `knowledge_source` — any
193213
item in its `knowledgeSources`, at the top level or in a package — is served
@@ -260,7 +280,8 @@ and the MCP draft door:
260280
serve for `search`, a system object without `enable.aiReadable`, or a field
261281
the author may not query refuses the save `403`, naming the object or the
262282
field; an `adapter` naming no mounted store refuses it `400`, naming the
263-
source, the adapter and the mounted ones. The fields judged are the ones the source serves (`content`,
283+
source, the adapter and the mounted ones, and so does a
284+
`source.retrieval.mode` the store does not run, listing the ones it does. The fields judged are the ones the source serves (`content`,
264285
`metadataFields`, the title field) and the ones its `where` reads. A
265286
verdict that cannot be reached, or a knowledge service that is registered
266287
and cannot be resolved, refuses `503`; nothing is written.

0 commit comments

Comments
 (0)