Skip to content

Commit dbe0716

Browse files
feat(knowledge): a knowledge source needs no adapter and no requires entry; it binds to the deployment's store (#38026)
repo:objectstack#1 · os-elon-musk · session_016WV4cwPhGV4g9p1BGQaZbP Fixes #37306 Clause-②: yes (widening) Metadata-protocol: added Skills-docs: follow-up #37310 — `skills/**` teaches the optional `adapter` and the item mount after this lands ## 维护者速读 - 用户能看到什么变化:应用作者写知识源时不必再指定存储,也不必在应用里声明需要知识服务;在本机开发(SQLite)、PostgreSQL 和自带存储的部署上,同一个知识源无需修改即可建索引和检索。 - 为什么做:知识库检索专题(按调用者权限过滤的知识检索)中“知识源可移植”的一行,替写知识源的应用作者和 AI 解决“换个数据库就要改知识源”的问题。 - 出错会怎样:最坏是同时注册了两个以上存储、且都不是部署自带的那个时,未写存储的知识源在保存时被明确拒绝并列出可选项;改动可直接撤回。 - 要你做什么:无(“运行中首次保存、部署未装知识服务时怎么办”已拆成单独的待裁决卡)。 ## What changes **Mechanism (the deployment's-store mark).** It is a service option, not a contract member: `KnowledgeServicePlugin` / `KnowledgeService` take `deploymentAdapter?: string`, which the runtime sets to the adapter id of the store it mounted (`resolveCapabilityArgument('knowledge', …)` answers `{ deploymentAdapter: resolveKnowledgeStore(input).store.adapterId }`, the same resolution `resolveCapabilityExtras` mounts from). `IKnowledgeAdapter` and `registerAdapter` are unchanged, so an adapter that application code registers is never the deployment's by registering. 1. **`adapter` optional** (`@objectstack/spec`, ADR-0161 K4 / K8 item 11). `KnowledgeSourceSchema.adapter` is `z.string().optional()`. Omitted, the source is held by the marked store, else the only adapter registered. Several registered and none the deployment's ⇒ refused at registration on both doors (`registerSource`, the `knowledge_source` loader) and at save (`admitAuthoredSource`), `400 VALIDATION_ERROR`, naming the choices. A source registered first and left unplaceable by adapters that came later answers the same refusal at index and search, and `reportUnmountedAdapters` names it once at boot. No adapter at all ⇒ `503 SERVICE_UNAVAILABLE`, naming the marked store. 2. **Placement is resolved where it is used** (`adapterIdFor` / `adapterFor` / `boundAdapterId`), so a code-door source registered at init finds a store plugin that registers in `start()`. Every `getAdapter(source.adapter)` call site (reindex, index state, record sync, delete, search planning, reap guard, `dropMetadataSource`) now goes through it. `index_status` reports the adapter a source is placed on. 3. **An item mounts the service** (K8 item 12). `PlatformCapabilityProvider` gains optional `mountedBy: { collection }`; the `knowledge` row of `PLATFORM_CAPABILITY_PROVIDERS` carries `{ collection: 'knowledgeSources' }`. (Review S1, record 7224273377: the earlier `type` member had no reader and repeated what the spelling map owns, so it is dropped.) `@objectstack/core` adds `stackItemCapabilities(stack)` (top level, then each package body), and `resolveServedCapabilities(…, { itemTokens })` serves them as declared tokens, reported in a new `byItems` set. `os serve` / `os dev` / `os start` and verify's `bootStack` read it and pass `database` to the argument resolver. `os migrate plan` / `apply` compose the same set: `stackItemCapabilities` is a composition step of both boots in `boot-preparation-parity.test.ts`. This answers CI's Test Core red at aba523a and the review's N3. 4. **Item 4 is split to #37983 (seat ruling).** The first `knowledge_source` saved at run time on a deployment with no knowledge service behaves exactly as on main: row 3a's boot line and behaviour are unchanged. The built item-4 code is kept on `claude/area-o1C-37306-item4` (fa2b538). 5. **Docs**: `content/docs/ai/knowledge-rag.mdx`, `content/docs/protocol/knowledge.mdx`; references regenerated (`gen:docs`). What a 19.0.0-next.1 stack sees: one that ships a source without `requires: ['knowledge']` held an inert item with a boot warning. It is now indexed: the service mounts, the boot pass builds the index, and the content fields are sent to the configured embedder (ADR-0161 K5: embedding is egress). The changeset says the same. Unchanged: a named adapter that is not mounted answers `SERVICE_UNAVAILABLE` as before (#37102); a host that mounts `KnowledgeServicePlugin` itself gets no store and no mark from the runtime; without a source or the token nothing is mounted. Out of scope as fenced: `skills/**` (#37310), the Studio form (#37309), hosted/EE mounts, #37479's unmounted-adapter reporting. ### Deviations (declared) - **`@objectstack/runtime`, MCP draft door** (`packages/runtime/src/domains/mcp-authoring.ts`, `itemSaveRefusal`): a finding from the dev of card #37983, carried here. The door spelled every refusal that was not a 403 as `SERVICE_UNAVAILABLE`, so the new `400 VALIDATION_ERROR` from `admitAuthoredSource` arrived over MCP as `SERVICE_UNAVAILABLE` with status 400. Now a 403 stays `PERMISSION_DENIED` and any other verdict keeps its own code, as the REST door already does. It carries a pin in `mcp-authoring.test.ts` and a `@objectstack/runtime` patch entry in the changeset. Outside the claimed file surface. - **`@objectstack/cli`, the migrate boot** (`schema-migration-plugins.ts`, `composeServedPlatform`): it reads the item tokens as `serve` does. The step pin and a behaviour pin cover it: an item-only stack composes `KnowledgeServicePlugin`, and the control does not. - **Two semantic conflicts with main**: main's new readers of the `adapter` field this change makes optional. Both now read the store a source is placed on (`boundAdapterId`), each with a pin. - The boot build pass (main's first-build pass at boot), in 205f667. - The reconcile's no-`listDocuments` check (main's scheduled reconcile), in merge 635fb18. - **Accepted overlaps (seat ruling)**: - #37963: one hunk in `knowledge-service.ts`. That PR absorbs the merge after this lands. - #38015: the generated `content/docs/references/ai/knowledge-source.mdx`. #38015 has landed. This head merges main and regenerates the page on the merged tree (`gen:schema` + `gen:docs`). File surface beyond the claim, declared: `packages/runtime/src/domains/mcp-authoring.ts` and its test, `packages/cli/src/utils/schema-migration-plugins.ts` and its test plus `boot-preparation-parity.test.ts` (above), the `knowledgeSources` describe in `packages/spec/src/stack.zod.ts`, `service-knowledge` plugin options, `knowledge-build-actions.ts`, `knowledge-reap-guard.ts`, `packages/verify/src/required-providers.ts`, `packages/core/src/capability-providers.ts` (comments only). Read first (by risk): 1. `packages/services/service-knowledge/src/knowledge-service.ts`: `adapterIdFor` and `refuseUnplacedSource`, where the refusal and placement rules live. 2. `packages/core/src/capability-composition.ts`: `stackItemCapabilities` and the `knowledge` branch of `resolveCapabilityArgument`. 3. `packages/spec/src/kernel/platform-capabilities.ts`: the `mountedBy` row field, the public surface this adds. Two-minute verification: `pnpm --filter @objectstack/verify exec vitest run src/harness.required-providers.test.ts -t "an item, no adapter, no token"` should print one passing case: a stack with a `knowledge_source` that names no adapter and no `requires: ['knowledge']` boots `KnowledgeServicePlugin` + `KnowledgeTursoPlugin`, places the source on `turso` beside an app adapter, and finds the Chinese row for `住宿标准 报销`. ## Tests Local, under the shared verify lock, at 633041b (the last commit, af27454, adds only module-top imports to one cli test file; that file was re-run, see below). <details><summary>Suites and typecheck</summary> - `@objectstack/spec` (whole package): 909 files / 28749 passed (+1 todo). - `@objectstack/core` `capability-composition.test.ts`: 25/25. - `@objectstack/service-knowledge`: 18 files / 563 tests. - `@objectstack/verify` `harness.required-providers.test.ts`: 16/16. - `@objectstack/cli` `boot-preparation-parity.test.ts` + `schema-migration-plugins.test.ts`: 2 files / 93 tests, at 633041b and again at af27454 (cli typecheck exit 0 at both). - `@objectstack/runtime` `mcp-authoring.test.ts`: 73/73, at aba523a; runtime is unchanged since. - Typecheck exit 0: spec, core, service-knowledge, verify, cli, runtime. </details> <details><summary>Ablations (each restored; blob == HEAD, `git diff HEAD` empty)</summary> | Pin | Mutation | Result | | --- | --- | --- | | A1 | the deployment's mark in `adapterIdFor` | 2 failed | | A2 | the registration refusal | 1 failed | | A3 | the item tokens in `resolveServedCapabilities` | 1 failed | | A4 | the `knowledge` capability argument | 1 failed | | A6 | `adapter` optional, redone as `z.string().min(0)` (the first try was a no-op) | 1 failed | | A7b | `stackItemCapabilities`, core dist | verify case fails: the knowledge service is not found | | A8 | the mark argument, core dist | verify case fails: source refused, then a TypeError | | A9 | boot pass reads the named adapter | the boot pin fails | | A10 | reconcile reads the named adapter | the reconcile pin fails | | A11 | MCP door respells non-403 as `SERVICE_UNAVAILABLE` | the pin fails: `SERVICE_UNAVAILABLE` where `VALIDATION_ERROR` was expected | | A12 | the migrate boot passes no item tokens | the behaviour pin fails: `KnowledgeServicePlugin` is not composed | A5 left with item 4. </details> ## Acceptance notes - PostgreSQL (pgvector) acceptance is NOT MEASURED end to end, locally or in CI. - CI's `capability-mount.live-postgres.test.ts` names `adapter: 'pgvector'` and `requires: ['knowledge']`, so it exercises neither the omitted adapter nor the item mount (review N2). - What pins the card's PostgreSQL line is two unit pins, composed: - `resolveCapabilityArgument('knowledge', postgres)` answers `{ deploymentAdapter: 'pgvector' }`, the store `resolveCapabilityExtras` mounts for the same database (core). - A source with no adapter binds to the marked store (service-knowledge). - Follow-up: #38040 drops `adapter` and `requires` from the live case. - Known gap, both boots alike: `os serve --artifact-fallback` (no config, the stack synthesized from the artifact JSON) reads items from a config that carries no `knowledgeSources`. The artifact result surfaces `requires` but no item collection, so an artifact-only stack's sources do not mount the service there. Follow-up: #38039; not built here. - Item 4 and its Acceptance line moved to #37983 (seat ruling). ## Verification <details><summary>Container run (os dev, scratch app; at fa2b538, items 1-3 unchanged since)</summary> The scratch app held one `knowledge_source`, with no `adapter` and no `requires`. The embedder was a local bigram fake. 1. `os dev --fresh` booted `KnowledgeServicePlugin` and `KnowledgeTursoPlugin`. 2. Three Chinese rows were POSTed (201 ×3). 3. `os knowledge rebuild kbx-kbx_policies` ended `done`: 3 rows read, 3 written. 4. `os knowledge status` showed `adapter turso`, `index: current`. 5. MCP `search_knowledge '住宿标准 报销'` ranked `差旅住宿标准` first (score 0.436). </details> <details><summary>Gates</summary> - `dispatch-gates --commands` at 633041b derives 129 families. - NOT MEASURED locally: - `check:type-check-debt`: its closure build needs the shared lock (CI ran `Type Check · debt ledger` green at aba523a). - `check:skill-examples` and `check:dual-build-cjs-loads`: they exit 3 on prerequisites outside this diff (the client-react, studio and scenarios dists are not built). - Exit 0: every other family, the ones that read built output re-run after the build. That includes `check:generated` ("All 14 generated artifacts are up to date"), `check:api-surface`, `check:dts-closure`, `check:i18n*`, `check:docs-transcript-drift` and `check:nul-bytes`. - `check:test-source-alias` failed once, on the edited cli test file. The test now pays its dynamic imports at module top, and the gate exits 0. - overlap-check at af27454 exits 1 against #37963 only (accepted). Clean: origin/main, #38038, #38037, #38033, #38013, #37982, #37929. </details> --- 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent c151c49 commit dbe0716

26 files changed

Lines changed: 728 additions & 78 deletions
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
'@objectstack/spec': minor
3+
'@objectstack/core': minor
4+
'@objectstack/service-knowledge': minor
5+
'@objectstack/cli': minor
6+
'@objectstack/verify': minor
7+
'@objectstack/runtime': patch
8+
---
9+
10+
feat(knowledge): a knowledge source needs no `adapter` and no `requires: ['knowledge']` — it binds to the deployment's store, and shipping one mounts the service
11+
12+
Clause-②: yes (widening)
13+
Metadata-protocol: added
14+
Skills-docs: follow-up #37310 — `skills/**` teaches the optional `adapter` and the item mount after this lands
15+
16+
A `knowledge_source` may leave out `adapter` (ADR-0161 K4), and a stack that ships one in `knowledgeSources` is served the knowledge service and one vector store without listing `knowledge` under `requires` (ADR-0161 K8, item 12). One source written as metadata now builds on SQLite under `os dev` (the `turso` store, a libSQL file), on PostgreSQL (`pgvector`) and on a host that mounts its own store, with no change to the source.
17+
18+
- **`@objectstack/spec`.** `KnowledgeSourceSchema.adapter` is optional. Omitted, the source is held by the deployment's adapter: the store the runtime mounted beside the knowledge service, else the only adapter registered. A named adapter is kept as written. `PlatformCapabilityProvider` gains an optional `mountedBy: { collection }`, set on the `knowledge` row of `PLATFORM_CAPABILITY_PROVIDERS` (`knowledgeSources`): a stack holding an item of that collection is served the capability as its token serves it.
19+
- **`@objectstack/core`.** `stackItemCapabilities(stack)` answers the tokens a stack's items mount (top level, then each package body), and `resolveServedCapabilities` takes them as `itemTokens`: appended after the declared tokens, read as declared (a provider that cannot be built fails the boot as for `requires`), and reported in a new `byItems` set. `resolveCapabilityArgument('knowledge', …)` now answers `{ deploymentAdapter }`, the adapter id of the store `resolveCapabilityExtras` mounts for the same database.
20+
- **`@objectstack/cli` and `@objectstack/verify`.** `os serve` / `os dev` / `os start` and `bootStack` read the item tokens, and hand the knowledge service the deployment's store (`pgvector` on PostgreSQL, `turso` otherwise). `os migrate plan` / `apply` read them too, so an item-only stack's migrate run composes the knowledge service as `os serve` mounts it (init only: no store, build or embedder call).
21+
- **`@objectstack/service-knowledge`.** `KnowledgeServicePlugin` and `KnowledgeService` take a `deploymentAdapter` option: the runtime's mark of the store it mounted. It is a service option, not an adapter-contract member, and `registerAdapter` is unchanged: an adapter application code registers is never the deployment's by registering. A source that names no adapter is placed where it is used (`adapterIdFor`, `adapterFor`), so one registered in code before its store started finds it. With several adapters registered and none the deployment's, such a source is refused at registration (both doors) and at its save, `400 VALIDATION_ERROR`, naming the adapters; registered first and left unplaceable by adapters that came later, it answers the same refusal at index and search, and the boot names it once at `error`. With no adapter registered it answers `503 SERVICE_UNAVAILABLE`, naming the deployment's store when one was marked. The `index_status` action reports the adapter a source is placed on.
22+
- **`@objectstack/runtime`.** The MCP draft door (`save_metadata_draft`) carries the knowledge service's refusal code through: a source refused `400 VALIDATION_ERROR` arrived over MCP as `SERVICE_UNAVAILABLE` with status 400, and now arrives as `VALIDATION_ERROR`, as on the REST door. A `403` is still `PERMISSION_DENIED`.
23+
24+
Unchanged: a source that names an adapter that is not mounted answers `SERVICE_UNAVAILABLE` as before; a host that mounts `KnowledgeServicePlugin` itself keeps its own, gets no store from the runtime and no deployment's mark; without a source or the token nothing is mounted; an item saved at run time on a deployment that mounted no knowledge service is reported at boot exactly as before.
25+
26+
What to do: nothing to change, with one behaviour to know. A stack on 19.0.0-next.1 that ships a source without `requires: ['knowledge']` held it inert, with a boot warning; it is now indexed: the service mounts, the boot pass builds the source's index, and its content fields are sent to the configured embedder (ADR-0161 K5: embedding is egress). A source that names `adapter: 'turso'` or `adapter: 'pgvector'` keeps working; drop the key to let the deployment choose, and drop `knowledge` from `requires` in an app that ships its sources.

‎content/docs/ai/knowledge-rag.mdx‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ ObjectStack ships a Knowledge Protocol that lets you retrieve from pluggable bac
1414

1515
## Turning it on: `requires: ['knowledge']`
1616

17-
Add `knowledge` to your app's `requires`, and `os dev`, `os serve` and `os start` mount the knowledge service and one vector store for you — and in an app's tests, `bootStack` from `@objectstack/verify` mounts the same:
17+
Ship a knowledge source in your app ([below](#writing-a-source)), or add `knowledge` to its `requires`, and `os dev`, `os serve` and `os start` mount the knowledge service and one vector store for you — and in an app's tests, `bootStack` from `@objectstack/verify` mounts the same. A source in the app's `knowledgeSources` is enough on its own; the token is for an app that ships none and authors its sources at run time:
1818

1919
```ts
2020
export default defineStack({
@@ -30,22 +30,24 @@ Which store is mounted depends on the platform database:
3030
| PostgreSQL | `@objectstack/knowledge-pgvector` | `pgvector` | the platform database, schema `os_knowledge` ([below](#self-hosted-vector-store-postgresql--pgvector)) |
3131
| anything else (SQLite under `os dev`, libSQL, MySQL, MongoDB) | `@objectstack/knowledge-turso` | `turso` | `knowledge.db` in the directory of the default database and never its file: `.objectstack/data/`, or `<OS_HOME>/data/` when `OS_HOME` is set ([below](#local-vector-store-a-libsql-file)) |
3232

33-
- **Sources are metadata**: list them under `knowledgeSources` ([below](#writing-a-source)), and name the adapter of the store your database gets (`adapter: 'turso'` or `adapter: 'pgvector'`).
33+
- **Sources are metadata**: list them under `knowledgeSources` ([below](#writing-a-source)). A source needs no `adapter`: one left out is held by the store in this table — the deployment's store — so the same source builds on SQLite under `os dev`, on PostgreSQL and on a hosted environment. Name an adapter only to place a source on another store you mounted.
34+
- **Two stores and none the deployment's** (a host that mounts the service and two adapters itself): a source that names no adapter is refused when it is registered or saved — `VALIDATION_ERROR` (400), naming the adapters to choose from.
3435
- **A source naming a store that is not mounted** does not stop the boot: the server logs one error naming the source and the stores that are mounted, and indexing or searching that source answers `SERVICE_UNAVAILABLE` (503) with the same choices; `search_knowledge` lists it in `refused`.
3536
- **The embedder** comes from Settings → AI & Embedder ([below](#configuring-the-embedder-from-settings)).
3637
- **Another libSQL store** for the `turso` case: save its URL as `turso_url` (and `turso_auth_token` for a managed `libsql://` database) in Settings → Knowledge, then restart. A `file:` URL saved there must name a file inside that same data directory, and a URL carrying a NUL byte or another control character, written out or percent-encoded (`%00`), is refused, as is a token carrying one (a pasted line break counts); either way the store answers `SERVICE_UNAVAILABLE` saying why, and the boot goes on.
3738
- **Where the file is**: `os start --home` and `OS_HOME` move it with the default database, so on a container put `OS_HOME` on a volume and the index survives a redeploy. A database named by URL (`OS_DATABASE_URL`) does not move it.
3839
- **Settings → Knowledge** holds only what the service and its store read: `turso_url` and `turso_auth_token`, which `@objectstack/knowledge-turso` adds to the page where it is the store and reads them (on PostgreSQL the page shows neither), and `chunk_target`, the longest passage the splitter cuts. The page names no adapter: a source's store is the one its own `adapter` names, and `os knowledge status` reports it per source. Every search re-checks each hit as the asking user, and no setting turns that off.
3940
- **More than one replica** on MySQL, MongoDB or a remote libSQL database: each replica keeps its own local `knowledge.db` and indexes only the record writes that replica itself handles, so replicas answer from indexes that differ. Give them one store: save a shared `libsql://` URL in `turso_url`, or run on PostgreSQL, where the vectors live in the one database.
4041
- **An install without the libSQL client**: `@objectstack/knowledge-turso` is an optional dependency of the CLI, because its client is a native module. Where it could not be installed the server warns at boot that the store was not mounted, and sources naming `turso` answer `SERVICE_UNAVAILABLE`.
41-
- **Without the token** nothing is mounted: no knowledge service, no store and no Knowledge settings page. `knowledge-memory` is never mounted for you.
42+
- **Without a source or the token** nothing is mounted: no knowledge service, no store and no Knowledge settings page. `knowledge-memory` is never mounted for you.
4243
- **Mounting it yourself** still works: an app whose `plugins` already hold `KnowledgeServicePlugin` keeps its own, and the runtime adds neither a second service nor a store.
4344

4445
## Writing a source
4546

4647
A knowledge source is a metadata item: a `*.knowledge-source.ts` file in your
4748
app, listed under `knowledgeSources`. It says which object's records to
48-
index, which fields become searchable text, and which adapter holds the index.
49+
index and which fields become searchable text; the deployment's store holds the
50+
index unless the source names another.
4951

5052
```ts
5153
// src/ai/task-notes.knowledge-source.ts
@@ -54,7 +56,7 @@ import type { KnowledgeSource } from '@objectstack/spec/ai';
5456
export const TaskNotes: KnowledgeSource = {
5557
name: 'task_notes',
5658
label: 'Task notes',
57-
adapter: 'turso', // 'pgvector' when the platform database is PostgreSQL
59+
// No `adapter`: the deployment's store (turso, or pgvector on PostgreSQL).
5860
source: { kind: 'object', object: 'task', content: ['title', 'notes'] },
5961
};
6062
```
@@ -65,8 +67,7 @@ import { defineStack } from '@objectstack/spec';
6567
import { TaskNotes } from './src/ai/task-notes.knowledge-source.js';
6668

6769
export default defineStack({
68-
requires: ['knowledge'],
69-
knowledgeSources: [TaskNotes],
70+
knowledgeSources: [TaskNotes], // mounts the knowledge service: no `requires` entry
7071
// …
7172
});
7273
```
@@ -76,7 +77,7 @@ and keeps the index in step with the records. There is no registration call
7677
to write.
7778

7879
- **`content` lists its fields by name.** What is listed is what leaves the row store: the text of those fields is sent to the embedder and kept in the index. `'*'` is refused, and a field added to the object later is not indexed until you add it here.
79-
- **A source can also be created or changed at run time**, in Studio or through MCP, with no restart: a new source is loaded and built, a changed one is reloaded (and rebuilt when what it indexes changed), and a removed one has its index dropped.
80+
- **A source can also be created or changed at run time**, in Studio or through MCP, with no restart where the knowledge service is mounted (above): a new source is loaded and built, a changed one is reloaded (and rebuilt when what it indexes changed), and a removed one has its index dropped.
8081
- **Authoring one needs `manage_knowledge_sources`** beside `manage_metadata` — platform administrators hold it by default — and the author must themselves be allowed to search the object and query every listed field and every field `where` reads, or the save is refused naming what they may not read. A write to a package that holds a source (publish its drafts, roll it back, duplicate, disable or delete it) needs the same capability.
8182
- **Two packages may each ship a source of the same name.** `search_knowledge` lists a package's source as `NAMESPACE-NAME` and takes that spelling in `sourceIds`.
8283
- **Registering in code still works**: `new KnowledgeServicePlugin({ sources: [TaskNotes] })` or `knowledge.registerSource(TaskNotes)` takes the same shape. A source registered in code and an item saved under the same name are one name: the second to arrive is refused.

‎content/docs/protocol/knowledge.mdx‎

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ any AI consumer.**
109109
### 3.1 `KnowledgeSource` (the `knowledge_source` metadata type)
110110

111111
A knowledge source says *which records* to index, *which of their fields*
112-
become searchable text, and *which adapter* holds the index. It is a governed
112+
become searchable text, and, when it is not the deployment's store, *which
113+
adapter* holds the index. It is a governed
113114
metadata type, `knowledge_source` (ADR-0161 K4): a package ships it as a
114115
`*.knowledge-source.ts` (or `.yml`) file under the stack's `knowledgeSources`
115116
collection, and an administrator creates or changes one at run time in Studio
@@ -122,7 +123,7 @@ import type { KnowledgeSource } from '@objectstack/spec/ai';
122123
export const KbArticles: KnowledgeSource = {
123124
name: 'kb_articles', // snake_case; with its package, the source's identity
124125
label: 'Knowledge base',
125-
adapter: 'pgvector', // the adapter id a plugin registered
126+
// adapter: 'pgvector', // optional; omitted ⇒ the deployment's store
126127
source: {
127128
kind: 'object', // the one kind
128129
object: 'kb_article',
@@ -133,7 +134,7 @@ export const KbArticles: KnowledgeSource = {
133134
},
134135
};
135136

136-
// objectstack.config.ts
137+
// objectstack.config.ts — the source mounts the knowledge service: no `requires` entry
137138
defineStack({ knowledgeSources: [KbArticles], /* … */ });
138139
```
139140

@@ -161,9 +162,27 @@ write instead, and `os migrate meta --from 18` converts the mechanical ones:
161162
| `refresh.cron` | removed: nothing scheduled it |
162163
| `source.kind: 'file'` / `'http'` with `prefix`, `mimeTypes`, `urls`, `userAgent` | removed: a source indexes an object's records |
163164

164-
Every source binds to a named **adapter id** (e.g. `'pgvector'`, `'turso'`,
165+
A source binds to an **adapter id** (e.g. `'pgvector'`, `'turso'`,
165166
`'memory'`), resolved at run time to the plugin that registered itself under
166-
that name.
167+
that name (ADR-0161 K4):
168+
169+
- **Named** — that adapter. One that is not mounted is refused at index and
170+
search, `SERVICE_UNAVAILABLE` (503), naming the adapters that are.
171+
- **Omitted** — the deployment's adapter: the store the runtime mounted beside
172+
the service (`pgvector` on PostgreSQL, `turso` otherwise; the runtime passes
173+
`KnowledgeServicePlugin` its `deploymentAdapter` option when it mounts both),
174+
else the only adapter registered. An adapter application code registers is
175+
never the deployment's by registering. With several registered and none the
176+
deployment's, the source is refused at registration and at its save,
177+
`VALIDATION_ERROR` (400), naming them. The adapter is placed where it is
178+
used, so a source registered before its store started finds it.
179+
180+
**What mounts the service.** A stack that ships a `knowledge_source` — any
181+
item in its `knowledgeSources`, at the top level or in a package — is served
182+
the knowledge service and the deployment's store, exactly as
183+
`requires: ['knowledge']` serves them (the `mountedBy` of the `knowledge` row
184+
in `PLATFORM_CAPABILITY_PROVIDERS`). A host that mounts
185+
`KnowledgeServicePlugin` itself keeps its own, and the runtime adds no store.
167186

168187
#### How a source is loaded
169188

@@ -181,7 +200,9 @@ starts and follows the type from then on, with no restart:
181200

182201
A deployment that holds a `knowledge_source` item but mounts no knowledge
183202
service says so once at boot, naming the items: nothing loads, indexes or
184-
searches them until `KnowledgeServicePlugin` and an adapter are mounted.
203+
searches them until `KnowledgeServicePlugin` and an adapter are mounted. Such
204+
an item is one the stack does not ship — saved at run time or installed in a
205+
package after the boot — since a shipped one mounts the service.
185206

186207
#### Who may author one
187208

@@ -606,8 +627,8 @@ Each plugin:
606627
3. Owns its own dependencies (SDK, fetch client, embedder).
607628
4. Owns its own lifecycle / health checks.
608629

609-
Multiple adapters can co-exist; sources pick which one to use via the
610-
`adapter` field.
630+
Multiple adapters can co-exist; a source picks one with its `adapter` field,
631+
or leaves it out for the deployment's store (§3.1).
611632

612633
### 4.1 `knowledge-pgvector` — the open vector store on PostgreSQL
613634

‎content/docs/references/ai/knowledge-source.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const result = KnowledgeRefreshPolicySchema.parse(data);
5454
| **id** | `never` | optional | [REMOVED] `knowledge_source.id` was removed in @objectstack/spec 19.0.0 (ADR-0161 K6) — a knowledge source is a metadata item, and an item is identified by `name`; use `name`. Rename the key; the value is unchanged, so the source's index is found again and is not rebuilt. 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. |
5555
| **label** | `string` | ✅ | |
5656
| **description** | `string` | optional | |
57-
| **adapter** | `string` | ✅ | Adapter id |
57+
| **adapter** | `string` | optional | Adapter id; omitted means the deployment's store (pgvector on PostgreSQL, turso otherwise), else the only adapter registered |
5858
| **adapterConfig** | `never` | optional | [REMOVED] `knowledge_source.adapterConfig` was removed in @objectstack/spec 19.0.0 (ADR-0161 K6) — no adapter read it: its one reader was the retired RAGFlow adapter. Delete the key. An adapter takes its settings as options of the plugin that mounts it. 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. |
5959
| **source** | `{ kind: Enum<'object'>; object: string; content: string[]; metadataFields?: string[]; … }` | ✅ | |
6060
| **embedding** | `never` | optional | [REMOVED] `knowledge_source.embedding` was removed in @objectstack/spec 19.0.0 (ADR-0161 K6) — it was never read: no service and no adapter chose a model from it. Delete the key. The embedder is configured once for the deployment, and every source is embedded by it. 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. |

0 commit comments

Comments
 (0)