Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
0c41790
wip(knowledge): adapter optional, deployment's store mark, item mount…
claude Nov 27, 2026
df7ace7
test(knowledge): pin the deployment's-store placement and the item mount
claude Nov 27, 2026
9fcd153
feat(objectql): the first knowledge_source saved with no service is t…
claude Nov 27, 2026
bae10e6
test(verify): a knowledge_source item with no adapter and no token mo…
claude Nov 27, 2026
9532bc2
Merge remote-tracking branch 'origin/main' into claude/area-o1C-37306
claude Nov 27, 2026
8e2613a
docs(knowledge): a source needs no adapter and no requires entry
claude Nov 27, 2026
910e505
chore(changeset): knowledge source adapter optional, item mounts the …
claude Nov 27, 2026
df2ed0c
docs(spec): regenerate references for the optional knowledge source a…
claude Nov 27, 2026
fa2b538
test(verify): budget the thirteenth required-providers boot
claude Nov 27, 2026
9d419f7
revert(objectql): split item 4 (the first knowledge_source saved with…
claude Nov 27, 2026
08bc42e
Merge remote-tracking branch 'origin/main' into claude/area-o1C-37306
claude Nov 27, 2026
205f667
fix(knowledge): the boot build pass places a source that names no ada…
claude Nov 27, 2026
635fb18
Merge remote-tracking branch 'origin/main' into claude/area-o1C-37306
claude Nov 27, 2026
dc55de3
docs(knowledge): leave the Settings → Knowledge bullet as main has it
claude Nov 27, 2026
aba523a
fix(runtime): the MCP draft door keeps a knowledge source refusal's o…
claude Nov 27, 2026
9fb423f
fix(spec): mountedBy carries only the collection its reader reads
claude Nov 27, 2026
503c913
Merge remote-tracking branch 'origin/main' into claude/area-o1C-37306
claude Nov 27, 2026
3275e95
docs(spec): regenerate the knowledge_source reference on the merged tree
claude Nov 27, 2026
633041b
fix(cli): the migrate boot composes what a stack's items mount, as se…
claude Nov 27, 2026
af27454
test(cli): pay the migrate composition's dynamic imports at collection
claude Nov 27, 2026
6881aa6
docs(changeset): name the migrate boot among the item-token readers
claude Nov 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .changeset/37306-knowledge-source-adapter-optional.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
'@objectstack/spec': minor
'@objectstack/core': minor
'@objectstack/service-knowledge': minor
'@objectstack/cli': minor
'@objectstack/verify': minor
'@objectstack/runtime': patch
---

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

Clause-②: yes (widening)
Metadata-protocol: added
Skills-docs: follow-up #37310 — `skills/**` teaches the optional `adapter` and the item mount after this lands

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.

- **`@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.
- **`@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.
- **`@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).
- **`@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.
- **`@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`.

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.

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.
17 changes: 9 additions & 8 deletions content/docs/ai/knowledge-rag.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ObjectStack ships a Knowledge Protocol that lets you retrieve from pluggable bac

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

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:
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:

```ts
export default defineStack({
Expand All @@ -30,22 +30,24 @@ Which store is mounted depends on the platform database:
| PostgreSQL | `@objectstack/knowledge-pgvector` | `pgvector` | the platform database, schema `os_knowledge` ([below](#self-hosted-vector-store-postgresql--pgvector)) |
| 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)) |

- **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'`).
- **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.
- **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.
- **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`.
- **The embedder** comes from Settings → AI & Embedder ([below](#configuring-the-embedder-from-settings)).
- **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.
- **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.
- **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.
- **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.
- **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`.
- **Without the token** nothing is mounted: no knowledge service, no store and no Knowledge settings page. `knowledge-memory` is never mounted for you.
- **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.
- **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.

## Writing a source

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

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

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

- **`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.
- **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.
- **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.
- **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.
- **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`.
- **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.
Expand Down
37 changes: 29 additions & 8 deletions content/docs/protocol/knowledge.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ any AI consumer.**
### 3.1 `KnowledgeSource` (the `knowledge_source` metadata type)

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

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

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

Every source binds to a named **adapter id** (e.g. `'pgvector'`, `'turso'`,
A source binds to an **adapter id** (e.g. `'pgvector'`, `'turso'`,
`'memory'`), resolved at run time to the plugin that registered itself under
that name.
that name (ADR-0161 K4):

- **Named** — that adapter. One that is not mounted is refused at index and
search, `SERVICE_UNAVAILABLE` (503), naming the adapters that are.
- **Omitted** — the deployment's adapter: the store the runtime mounted beside
the service (`pgvector` on PostgreSQL, `turso` otherwise; the runtime passes
`KnowledgeServicePlugin` its `deploymentAdapter` option when it mounts both),
else the only adapter registered. An adapter application code registers is
never the deployment's by registering. With several registered and none the
deployment's, the source is refused at registration and at its save,
`VALIDATION_ERROR` (400), naming them. The adapter is placed where it is
used, so a source registered before its store started finds it.

**What mounts the service.** A stack that ships a `knowledge_source` — any
item in its `knowledgeSources`, at the top level or in a package — is served
the knowledge service and the deployment's store, exactly as
`requires: ['knowledge']` serves them (the `mountedBy` of the `knowledge` row
in `PLATFORM_CAPABILITY_PROVIDERS`). A host that mounts
`KnowledgeServicePlugin` itself keeps its own, and the runtime adds no store.

#### How a source is loaded

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

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

#### Who may author one

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion content/docs/references/ai/knowledge-source.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const result = KnowledgeRefreshPolicySchema.parse(data);
| **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. |
| **label** | `string` | ✅ | |
| **description** | `string` | optional | |
| **adapter** | `string` | ✅ | Adapter id |
| **adapter** | `string` | optional | Adapter id; omitted means the deployment's store (pgvector on PostgreSQL, turso otherwise), else the only adapter registered |
| **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. |
| **source** | `{ kind: Enum<'object'>; object: string; content: string[]; metadataFields?: string[]; … }` | ✅ | |
| **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. |
Expand Down
Loading
Loading