You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit f576dee
Browse filesBrowse the repository at this point in the historyBrowse files
feat(spec): a knowledge source declares its retrieval mode; an adapter reports the modes it runs (#38720)
<!-- 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-②: yes (widening)
Metadata-protocol: added
Skills-docs: follow-up #38732 (the `source.retrieval.mode` row of the
objectstack-ai skill lands there; `skills/` is a governed path and takes
its own PR)
## 维护者速读
- 知识源作者可以选择检索方式(按意思、按字词、两者结合),不选则沿用存储默认;本单只定义写法与驱动上报,用户暂无可见变化。
- 属于知识管理专题「一期 a:检索方式」,解决条款类问答被语义检索漏掉的问题。
- 出错只会是新写法被误拒或误收;未写此项的知识源行为不变,可直接撤回。
- 无。
## Stack
Base: `main`. First of the phase-1a series; the adapter PRs and the
service PR build on it. The ruling it builds on is on `main`: ADR-0161,
the dated note of 2026-11-30 under K8 (phase 0, merged as 95ffacc);
this branch has `main` merged in.
**Lands together with #38722, right after it.** This PR adds the key and
both contract members with their suite cases, but no reader: the
service's reader is #38722, and the two adapters that declare
`implements.retrieval` are #38721 and #38745. That splits K8 rule 1 and
K4 ("lands with its first reader, in the same PR") across stacked PRs,
because the stack bases force it. Until #38722 lands, a declared mode is
carried and ignored, and the `planned` liveness row warns an author so
(`authorWarn` and `authorHint`; #38722 drops both when it flips the row
to `live`). So #38720 is not merged or released without #38722, which
merges right after it.
## What changes
- `knowledge_source.source.retrieval?: { mode?: 'vector' | 'keyword' |
'hybrid' }`, strict from birth; `retrieval: {}` is accepted and declares
nothing. Not part of the index fingerprint or the recipe hash.
- `IKnowledgeAdapter.capabilities.retrieval?: { modes, default }`
(`AdapterRetrievalCapability`) and `AdapterSearchOptions.retrieval?: {
mode }`, optional as every search member is (K8 rule 2); omitted means
the adapter's default.
- Contract suite (`runKnowledgeAdapterContract`):
`implements.retrieval`; a declared report must be valid, and one seeded
fixture is searched under each listed mode (`vector` leaves the
keyword-only clause out, `keyword` answers it alone, the default handed
explicitly equals no member).
- ADR-0161 K2 row and protocol doc §7.1 rewritten (see Acceptance
notes); the contract doc names the refusal code.
- Studio form row for the mode (static three options; PR 4 of the series
makes it list the store's modes), liveness row `planned` (flipped to
`live` by the service PR), protocol doc §3.4, generated baselines.
## Tests
- `packages/spec`: new knowledge-source cases (three modes parse, `{}`
accepted, an invalid mode's message,
`vectorWeight`/`keywordWeight`/`fusion` refused as unknown keys, JSON
Schema enum + `additionalProperties: false`).
- `service-knowledge`: index-fingerprint test pins that neither hash
moves for `{}` or any mode.
- Contract suite exercised by the turso and live-pgvector adapter PRs.
## Acceptance notes
- `AdapterSearchOptions.retrieval` is optional, as built (`retrieval?`,
omitted means the adapter's default, as K8 rule 2 has every search
member): the maintainer ruled it on #38692 (comment 7272337479,
2026-11-30 07:57Z), the question the phase-0 contract review
(7271729439) escalated.
- Per-search refusal code (point 4), proposed: `SERVICE_UNAVAILABLE`
(503), reused rather than added. It is an ADR-0112 standard catalog code
(`packages/spec/src/api/error-code-ledger.zod.ts`, the standard map), so
no new ledger entry; it is the code a source whose adapter is not
mounted already carries in `refused`, since in both cases the deployment
cannot serve the source as written. It is #38722's to write and the
maintainer's to confirm (open question C): the contract doc of
`AdapterSearchOptions.retrieval` here names no code. The save refuses
with `VALIDATION_ERROR` (400), as the ruling fixes.
- ADR-0161's K2 row (adapter surface) is rewritten as the row asks of
each PR that adds a member: it no longer says "no hybrid toggle";
protocol doc §7.1 likewise. This makes the PR Tier H (an ADR file is
touched).
- Phase 1b (`vectorWeight`) is not built; the strict shape refuses it
today.
## Verification
- Two-minute check: `pnpm --filter @objectstack/spec exec vitest run
src/ai/knowledge-source.test.ts` → all pass, including the retrieval
describe.
- Local gates from `dispatch-gates.mjs --commands`: all measured gates
green (`check:spec-parsed-alias` found a missing isomorphism pin, fixed
in e805371); not measured in this container (exit 3 or unbuilt closure,
no verdict): `check-plugin-teardown-shape --self-test` (shallow clone),
`check:skill-examples`, `check:dual-build-cjs-loads`, `check:i18n`,
`check:dts-closure`.
## 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>
feat(spec): a knowledge source may declare its retrieval mode, `source.retrieval.mode` (`vector`, `keyword` or `hybrid`), and a knowledge adapter reports the modes it runs
8
+
9
+
Clause-②: yes (widening)
10
+
Metadata-protocol: added
11
+
12
+
A `knowledge_source` may now declare how it is searched: `source: { …, retrieval: { mode: 'vector' } }`. `vector` runs only the vector leg (ranking passages by meaning), `keyword` only the keyword leg (ranking passages by the words they hold, with no call to the embedder), and `hybrid` both, merged by the store's fusion. Leaving `mode` out, or writing `retrieval: {}`, keeps the store's default, which is today's behaviour. The key is read on every search and by no build, so it enters neither the index fingerprint nor the recipe hash: changing it rebuilds nothing. The parse refuses a mode outside the three, and any other key under `retrieval`, each with the fix. Studio's knowledge source form offers the key as a "Retrieval mode" select under "Search".
13
+
14
+
`IKnowledgeAdapter` gains two optional members. `capabilities.retrieval: { modes, default }` is the adapter's report of the modes it runs and the one it runs when a source declares none; it is a report, not configuration. `AdapterSearchOptions.retrieval: { mode }` carries the mode a search runs, a per-request parameter like `topK`. An adapter that reports no modes keeps working unchanged; a source that names it may only leave `mode` out.
15
+
16
+
The adapter contract suite (`@objectstack/service-knowledge/testing`) takes a new optional declaration, `implements.retrieval`: it checks the adapter's report (each mode one of the three, none twice, the default listed), searches a fixed set of passages under each listed mode (`vector` leaves out the passage only the keyword leg ranks, `keyword` answers that passage alone and nothing for a query with no word any passage holds), and checks that the default mode handed explicitly answers exactly what a search without the member answers. An adapter that does not declare it is checked to report no modes.
17
+
18
+
The Studio metadata-form translations (`@objectstack/platform-objects`) name the "Search" group and the "Retrieval mode" select and its three choices in every locale.
19
+
20
+
The knowledge service's reading of the mode (and its refusal of a mode the source's store does not run) and the turso and pgvector stores' support for it ship as separate changes.
const result =KnowledgeAffinityCallerSchema.parse(data);
@@ -76,6 +76,28 @@ const result = KnowledgeAffinityCallerSchema.parse(data);
76
76
|**cron**|`never`| optional |[REMOVED]`knowledge_source.refresh.cron` was removed in @objectstack/spec 19.0.0 (ADR-0161 K6) — it was parsed and reached no engine: nothing ever scheduled a reindex from it. Delete the key. To rebuild on a schedule, call `reindexSource` from a flow or a job; keeping the index correct between events is the service's reconcile pass. A source registered in code (`KnowledgeServicePlugin({ sources })`, `registerSource`) is in no stack collection, so `os migrate meta` lists no edit for it: make this edit in the registration itself. Run `os migrate meta --from 18` to list the mechanical edits for existing sources; `--write` applies the ones it can prove, and you apply the rest by hand. |
77
77
78
78
79
+
---
80
+
81
+
## KnowledgeRetrieval
82
+
83
+
### Properties
84
+
85
+
| Property | Type | Required | Description |
86
+
| :--- | :--- | :--- | :--- |
87
+
|**mode**|`Enum<'vector' \| 'keyword' \| 'hybrid'>`| optional | Which legs a search runs: vector, keyword or hybrid; omitted means the store's default |
88
+
89
+
90
+
---
91
+
92
+
## KnowledgeRetrievalMode
93
+
94
+
### Allowed Values
95
+
96
+
*`vector`
97
+
*`keyword`
98
+
*`hybrid`
99
+
100
+
79
101
---
80
102
81
103
## KnowledgeSource
@@ -116,6 +138,7 @@ const result = KnowledgeAffinityCallerSchema.parse(data);
116
138
|**where**|`Record<string, any>`| optional ||
117
139
|**split**|`{ strategy: Enum<'whole' \| 'recursive' \| 'markdown'>; maxChars?: integer; minChars?: integer }`| optional | How the service cuts this object's documents into passages; omitted means recursive |
118
140
|**affinity**|`{ field: string; caller: Enum<'user' \| 'business_unit'>; mode: Enum<'boost' \| 'nearest'>; places?: integer }[]`| optional | How this source's hits are ordered for the caller: boost (by places) or nearest (own business unit first), by position, never by score |
141
+
|**retrieval**|`{ mode?: Enum<'vector' \| 'keyword' \| 'hybrid'> }`| optional | How this source is searched: mode vector, keyword or hybrid; omitted means the store's default, and changing it rebuilds nothing |
119
142
120
143
### Nested Shape: `KnowledgeSource.refresh`
121
144
@@ -166,6 +189,7 @@ const result = KnowledgeAffinityCallerSchema.parse(data);
166
189
|**where**|`Record<string, any>`| optional ||
167
190
|**split**|`{ strategy: Enum<'whole' \| 'recursive' \| 'markdown'>; maxChars?: integer; minChars?: integer }`| optional | How the service cuts this object's documents into passages; omitted means recursive |
168
191
|**affinity**|`{ field: string; caller: Enum<'user' \| 'business_unit'>; mode: Enum<'boost' \| 'nearest'>; places?: integer }[]`| optional | How this source's hits are ordered for the caller: boost (by places) or nearest (own business unit first), by position, never by score |
192
+
|**retrieval**|`{ mode?: Enum<'vector' \| 'keyword' \| 'hybrid'> }`| optional | How this source is searched: mode vector, keyword or hybrid; omitted means the store's default, and changing it rebuilds nothing |
169
193
170
194
### Nested Shape: `ObjectKnowledgeSource.split`
171
195
@@ -184,6 +208,12 @@ const result = KnowledgeAffinityCallerSchema.parse(data);
184
208
|**mode**|`Enum<'boost' \| 'nearest'>`| ✅ | boost lifts a match by places; nearest puts the caller's own unit first, then its parents |
185
209
|**places**|`integer`| optional | boost only: how many non-matching hits a match may pass, 1 to 20 |
|**mode**|`Enum<'vector' \| 'keyword' \| 'hybrid'>`| optional | Which legs a search runs: vector, keyword or hybrid; omitted means the store's default |
|[Automation Protocol](/docs/references/automation)| 16 | 82 | Flows and their nodes, approvals, ETL pipelines, webhooks, state machines, execution records. |
28
28
|[Data Protocol](/docs/references/data)| 35 | 197 | Objects, fields, queries, filters, datasources and drivers — the ObjectQL layer. |
@@ -36,13 +36,13 @@ counts are sums of the rows they head. Regenerate with
36
36
|[Studio Protocol](https://github.com/objectstack-ai/objectstack/tree/main/packages/spec/docs/references/studio)| 3 | 35 | Studio designer metadata — the authoring surfaces for the protocols above. |
37
37
|[System Protocol](https://github.com/objectstack-ai/objectstack/tree/main/packages/spec/docs/references/system)| 40 | 298 | The runtime environment — logging, jobs, cache, metrics, notifications, i18n and compliance. |
38
38
|[UI Protocol](/docs/references/ui)| 17 | 188 | Apps, pages, views, dashboards, reports, actions and themes — the ObjectUI layer. |
Copy file name to clipboardExpand all lines: docs/adr/0161-knowledge-platform-boundary-platform-owns-assembly-sync-split-record-return-knowledge-source-is-a-governed-type.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -172,7 +172,7 @@ Each text below states the old position. The left column quotes it as it reads a
172
172
| Same file, §1: "We have nothing distinctive to add to those layers." and "The protocol scopes the framework's responsibility to (1)–(4) and delegates the rest to plugins." | The framework's list grows by the four of K1; what is delegated is the adapter's four. |#37096|
173
173
| Same file, §3.1: a source "is stored as metadata (versioned, environment-scoped) just like a view or a flow", against the schema note on `packages/spec/src/ai/knowledge-source.zod.ts#KnowledgeSourceSchema`: "the shape of a **runtime registration**, ⛔ not a governed metadata type". | The two agree: a source is a `knowledge_source` item (K4). Until row 3 lands, the schema note is the true one. | row 3 |
174
174
| Same file, §3.2: "The framework does **not** chunk; adapters do." | The framework splits; adapters index the passages. |#37098 (row 6) |
175
-
| Same file, §3.4, and the note on `packages/spec/src/contracts/knowledge-adapter.ts#IKnowledgeAdapter`: "The surface is **deliberately minimal**: no chunk strategy, no embedding configuration, no rerank toggles." | The contract grows by K8's list. It carries what an adapter reports about its embedder and still no configuration, no rerank and no hybrid toggle. |#37096, then each card that adds a member |
175
+
| Same file, §3.4, and the note on `packages/spec/src/contracts/knowledge-adapter.ts#IKnowledgeAdapter`: "The surface is **deliberately minimal**: no chunk strategy, no embedding configuration, no rerank toggles." | The contract grows by K8's list. It carries what an adapter reports about its embedder and the retrieval modes it runs (`capabilities.retrieval`), and the mode a search runs in (`AdapterSearchOptions.retrieval`): the source's declaration, else the adapter's default; still no configuration and no rerank. |#37096, then each card that adds a member (#38692 phase 1a: the retrieval mode)|
176
176
| Same file, §6: "that surface stays unbuilt until a real `object` source calls for it." | The enumeration surface is built (K8, item 1); reconcile covers application-level predicate writes. |#37096 and row 15 |
177
177
| Same file, §7 and §8: `knowledge-pgvector` as "Phase 3", and "a `KnowledgeSource.embedding` field". |`knowledge-pgvector` is an open adapter of this repository (cloud ADR-0119 D5); `embedding` is removed (K6). |#37100, row 3 |
178
178
|`packages/spec/src/ai/embedding.zod.ts`, file note: "NOT in scope (these belong to application code, not the platform): Chunking strategies (fixed/semantic/recursive/markdown)." and "These were removed in v1 because they describe one specific way to build a RAG application". | Structural splitting is a platform capability of the knowledge service. It does not return as the pipeline vocabulary that was removed. Retrieval pipelines, document loaders and end-to-end orchestration stay out of scope. |#37098|
helpText: "Optional. Lists entries that move hits related to the person asking up the answer, for example [{\"field\": \"business_unit\", \"caller\": \"business_unit\", \"mode\": \"nearest\"}] puts their own unit first, then its parent units, then the rest, and [{\"field\": \"owner\", \"caller\": \"user\", \"mode\": \"boost\", \"places\": 3}] lets a hit they own pass up to 3 others (1 to 20). Each field must be in Filter fields and point at users (caller user) or business units (caller business_unit); at most one nearest. Nothing is dropped or scored differently, and setting it rebuilds nothing."
3571
3571
},
3572
+
"source.retrieval": {
3573
+
label: "البحث",
3574
+
helpText: "كيف يعثر البحث في هذا المصدر على المقاطع. اتركه فارغًا لاستخدام الوضع الافتراضي للمخزن. تغييره لا يعيد بناء أي شيء."
3575
+
},
3576
+
"source.retrieval.mode": {
3577
+
label: "وضع الاسترجاع",
3578
+
helpText: "فارغ: الوضع الافتراضي للمخزن (هجين في turso وpgvector). المتجه يرتّب المقاطع حسب المعنى؛ والكلمات المفتاحية حسب الكلمات التي تحتويها، دون استدعاء مزوّد التضمين، وهو ما يناسب أرقام المستندات أو البنود؛ والهجين يدمج الاثنين. يُرفض عند الحفظ أي وضع لا يشغّله المخزن.",
3579
+
options: {
3580
+
vector: "المتجه فقط (حسب المعنى)",
3581
+
keyword: "الكلمات المفتاحية فقط (حسب الكلمات)",
3582
+
hybrid: "هجين (كلاهما)"
3583
+
}
3584
+
},
3572
3585
"source.where": {
3573
3586
label: "Records to index",
3574
3587
helpText: "An ObjectQL filter on the object, for example {\"status\": {\"$ne\": \"done\"}}. Only the records it matches are indexed. Blank: every record."
0 commit comments