Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
d4afc13
feat(spec)!: admit knowledge_source as a governed metadata type (wip:…
claude Nov 26, 2026
98cdf81
feat(spec)!: knowledge_source kit on protocol 19 (conversions, retire…
claude Nov 26, 2026
9575898
feat(service-knowledge): load knowledge_source items, one slot per (p…
claude Nov 26, 2026
8b2cabd
feat(rest): two authoring guards for knowledge_source at the metadata…
claude Nov 26, 2026
9c796bb
feat(service-knowledge): dropSource in the three adapters, source nam…
claude Nov 26, 2026
008030a
feat(objectql): say once at boot that knowledge sources have no knowl…
claude Nov 26, 2026
6d0b8af
docs(knowledge): knowledge_source as metadata — showcase source, docs…
claude Nov 26, 2026
f1fc065
chore(spec): rosters and bundles follow the knowledge_source type
claude Nov 26, 2026
deb49dc
test(knowledge): census row, collection-time imports and showcase ali…
claude Nov 26, 2026
1420f9e
Merge remote-tracking branch 'origin/main' into claude/project-thread…
claude Nov 26, 2026
aaf309b
chore(spec): after the merge of main — default declaration under majo…
claude Nov 26, 2026
15d0855
chore(changeset): name the skills follow-up card
claude Nov 26, 2026
2510f53
test(spec): pin the knowledge source's retired keys to their release;…
claude Nov 26, 2026
fdeeaf7
Merge remote-tracking branch 'origin/main' into claude/project-thread…
claude Nov 26, 2026
33d5511
chore(spec): regenerate the ai surfaces after the second merge of main
claude Nov 26, 2026
3ea6a22
test(metadata): the owner-stamp boot fixtures carry a knowledge source
claude Nov 26, 2026
e5bf42b
test: the type and tier pins in metadata, metadata-protocol and platf…
claude Nov 26, 2026
b79a979
chore(i18n): regenerate zh-Hant from its zh-Hans source for the knowl…
claude Nov 26, 2026
7dd6fdc
docs(adr): ADR-0084's type table carries the knowledge_source row its…
claude Nov 26, 2026
45ed212
test(plugin-security): platform administrator goldens carry manage_kn…
claude Nov 26, 2026
1c17182
fix(spec): a knowledge source's content refuses an empty-string member
claude Nov 27, 2026
d15de9a
fix(service-knowledge): source admission judges the fields a source's…
claude Nov 27, 2026
150c854
fix(runtime): the authoring guards of a knowledge source cover more d…
claude Nov 27, 2026
a8756eb
runtime: duplicate admits each copied knowledge source; the package g…
claude Nov 27, 2026
21142e1
Merge branch 'main' of https://github.com/objectstack-ai/objectstack …
claude Nov 27, 2026
737f443
spec: regenerate authorable-defaults after merging main
claude Nov 27, 2026
cf128e5
runtime: the package gate leaves ensure-customization alone; tests fo…
claude Nov 27, 2026
20f9299
docs: census rows name the package-door guards; changeset states the …
claude Nov 27, 2026
fafa914
Merge branch 'main' of https://github.com/objectstack-ai/objectstack …
claude Nov 27, 2026
ebc0b7c
skills: the supportKb example pays for its two renamed keys in the sa…
claude Nov 27, 2026
d92226c
Merge remote-tracking branch 'origin/main' into claude/project-thread…
claude Nov 27, 2026
2a2218d
skills ratchet: the objectstack-ai row sits at its file's measurement
claude Nov 27, 2026
e958f85
Merge remote-tracking branch 'origin/main' into claude/project-thread…
claude Nov 27, 2026
e2949f0
regen: the reference index and the ai authorable surface after mergin…
claude Nov 27, 2026
00d616e
Merge remote-tracking branch 'origin/main' into claude/project-thread…
claude Nov 27, 2026
dfcdfb8
regen: generated spec artifacts after merging main
claude Nov 27, 2026
ae2b4ac
Merge remote-tracking branch 'origin/main' into claude/project-thread…
claude Nov 27, 2026
261dc75
Merge remote-tracking branch 'origin/main' into claude/project-thread…
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
53 changes: 53 additions & 0 deletions .changeset/37304-knowledge-source-governed-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
'@objectstack/spec': minor
'@objectstack/service-knowledge': minor
'@objectstack/knowledge-memory': minor
'@objectstack/knowledge-pgvector': minor
'@objectstack/knowledge-turso': minor
'@objectstack/metadata-core': minor
'@objectstack/rest': minor
'@objectstack/runtime': minor
'@objectstack/objectql': minor
'@objectstack/core': patch
'@objectstack/metadata': patch
'@objectstack/cli': patch
'@objectstack/platform-objects': patch
'@object-ui/app-shell': minor
'@object-ui/i18n': minor
'@object-ui/fields': patch
---

feat(spec)!: a knowledge source is a governed metadata type, `knowledge_source`, loaded by the knowledge service

Clause-②: yes (narrowing)
Metadata-protocol: narrowed
Skills-docs: follow-up #37310. Here only the enumeration row: `skills/objectstack-platform/SKILL.md` lists the new top-level key `knowledgeSources`, and `skills/objectstack-ai/SKILL.md`'s compiled `supportKb` example writes `name` and `content`, because the 18 spelling no longer parses.

<!-- adr-0087: registered knowledge-source-id-to-name, knowledge-source-content-fields-to-content, knowledge-source-inert-keys-removed, knowledge-source-content-lists-fields, knowledge-source-file-http-kinds-retired, knowledge-source-inert-keys-retired, knowledge-source-registration-governed -->

ADR-0161 K4, K5, K6 and K8 item 4 (#37304).

**BREAKING.** A knowledge source written for 18 is refused at parse until it is moved. `os migrate meta --from 18` lists every edit and `--write` applies the ones it can prove.

| Wrote (18) | Write instead (19) |
|:--|:--|
| `id: 'support_kb'` | `name: 'support_kb'` (the value is unchanged, so the index is found again and nothing is rebuilt) |
| `source.contentFields: ['title', 'body']` | `source.content: ['title', 'body']` |
| `contentFields: ['*']` | `content` with every field named (a hand edit: only the author knows which fields may leave the row store) |
| `embedding`, `vectorStore`, `adapterConfig`, `refresh.cron` | delete the key: nothing read it |
| `source.kind: 'file'` or `'http'`, with `prefix`, `mimeTypes`, `urls`, `userAgent` | a source indexes the records of one object (`kind: 'object'`); a file or URL source has no replacement |
| `knowledge.indexDocument(…)`, `knowledge.deleteDocument(…)` | no call: the service builds every document from the records a source selects; `reindexSource` rebuilds a source |
| `KnowledgeServicePlugin({ sources: [{ id, … }] })`, `registerSource({ id, … })` | the same call with the 19 shape, or the source shipped as metadata in the stack's `knowledgeSources` |

What changes:

- **The type.** `knowledge_source` is registered in the metadata type registry with the one schema `KnowledgeSourceSchema`; a stack carries its sources in the new top-level collection `knowledgeSources`, in `*.knowledge-source.ts` or `.yml` files. An item can be created and changed at run time (Studio, MCP); it takes no environment overlay. Studio's menu lists the type, and the metadata form bundles carry its label in every locale. Two packages may each ship a source of one name (ADR-0150, addendum of 2026-11-25): each has its own index, and `search_knowledge` lists a package's source as `NAMESPACE-NAME` and takes that spelling in `sourceIds`.
- **The schema is strict.** An undeclared key is refused, never dropped. `content` is a non-empty list of field names; an empty-string member is refused, and `'*'` is refused with the instruction to list the fields: embedding is egress, and the wildcard sent every text field of a record to the embedder, including one added to the object later. Credential-class and `internal` fields stay unindexed even when named.
- **The loader.** `KnowledgeServicePlugin` reads the published items when it starts and follows the type while it runs: an added source is registered and built when a build is due; a changed one is registered again, and a changed `where` or `metadataFields` rebuilds inside the generation while a changed `content` or `split` builds a new one; a removed one is unregistered and its index dropped. The reap guard now follows the sources, so a retention delete on an object first indexed by a source added after boot de-indexes the row. A deployment that holds an item and mounts no knowledge service says so once at boot, naming the items.
- **`IKnowledgeAdapter.dropSource?(ctx)`** removes everything an adapter holds for a source: every generation, the one under construction included, and what it recorded about the index. `knowledge-memory`, `knowledge-pgvector` and `knowledge-turso` implement it, and the contract suite (`@objectstack/service-knowledge/testing`) takes a new `implements.dropSource` declaration. Over an adapter without it, a removed source's index is kept and the service says so once. An adapter is handed the source's index key as `ctx.source.name` (it was `ctx.source.id`): the bare name for a source no package holds, so an existing index is found under the same key.
- **A capability of its own.** New platform capability `manage_knowledge_sources`: a write of a `knowledge_source` through `/meta` (REST and the dispatcher: save, publish, rollback, delete) and through the MCP draft door needs it beside `manage_metadata`. Platform administrators hold it by default; a grant on the indexed object's records does not imply it. A caller without it is refused `403 PERMISSION_DENIED`, naming the capability. The package doors ask it too: every write to an existing package that holds a knowledge source (an item, a pending draft, or for the commit revert and the rollback a commit that touched one) needs the capability: enable, disable, publish, publish-drafts, discard-drafts, the commit revert, rollback, revert, adopt-orphans, duplicate, the manifest update and delete. A package that holds none is written as before. The install door is not asked, and neither is ensure-customization, which writes nothing of the base and creates an empty pair. For a caller without the capability the doors read the package's holding before their own request checks, so such a caller hears this `403` ahead of a `400`, `404` or `422` the door would have answered for the same request; a holding that cannot be read refuses `503` and changes nothing (a host with no metadata store holds none). A duplicate also admits each knowledge source it copies for the caller (source admission, below), and refuses the whole copy when one is refused.
- **Source admission at save.** Those same doors save a source only when its author may themselves search what it would index: an object of a disabled package, an object the API does not serve for `search`, a system object without `enable.aiReadable`, or a field the author may not query refuses the save `403`, naming the object or the field; a verdict that cannot be reached, or a knowledge service that is registered and cannot be resolved, refuses `503`. The fields judged are the ones the source serves and the ones its `where` reads, at save and at search: a source whose `where` reads a field a caller may not query is not searched for that caller. Over MCP it is the human who is judged. Where no knowledge service is mounted there is nothing to ask, and the save goes on.
- **One name, one source.** `KnowledgeServicePlugin({ sources })` and `registerSource` stay a door for the same schema and parse with it: a retired key is refused with its prescription (`400 VALIDATION_ERROR`), not converted. A source registered in code belongs to no package. It shares one slot with an environment-authored item of the same name, and the second of the two to arrive is refused `409 RESOURCE_CONFLICT`, naming both doors; a metadata item reloading its own earlier version is not a second arrival.
- **The push door leaves.** `IKnowledgeService.indexDocument` and `deleteDocument` are removed, with the `file` / `http` branches that served them. They are runtime-interface-only members with no metadata form, so the compiler reports each call (`TS2339`).
- **Removed exports**, twelve, all from `@objectstack/spec/ai`. The whole `embedding` module leaves with `embedding` and `vectorStore`, because the knowledge source was its only composer: `EmbeddingModelSchema`, `VectorStoreSchema`, `VectorStoreProviderSchema` and the types `EmbeddingModel`, `VectorStore`, `VectorStoreProvider`. The source kinds leave with `file` and `http`: `FileKnowledgeSourceSchema`, `HttpKnowledgeSourceSchema`, `KnowledgeSourceKindSchema` and the types `FileKnowledgeSource`, `HttpKnowledgeSource`, `KnowledgeSourceKind`. None has a replacement; an import of one is a compile error.
- **CLI.** `os knowledge status` prints the package that holds a source and no longer prints a source kind.
89 changes: 65 additions & 24 deletions content/docs/ai/knowledge-rag.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ 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 still written in code**: register them on the `knowledge` service from your own plugin, 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)), and name the adapter of the store your database gets (`adapter: 'turso'` or `adapter: 'pgvector'`).
- **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.
Expand All @@ -41,34 +41,75 @@ Which store is mounted depends on the platform database:
- **Without 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.

```ts
// src/ai/task-notes.knowledge-source.ts
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
source: { kind: 'object', object: 'task', content: ['title', 'notes'] },
};
```

```ts
// objectstack.config.ts
import { defineStack } from '@objectstack/spec';
import { TaskNotes } from './src/ai/task-notes.knowledge-source.js';

export default defineStack({
requires: ['knowledge'],
knowledgeSources: [TaskNotes],
// …
});
```

The knowledge service loads the source when it starts, runs its first build,
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.
- **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.

<Callout type="warn">
**Upgrading from 18.** `id` is now `name` and `source.contentFields` is `source.content` (run `os migrate meta --from 18`); a `'*'` member must be replaced with the field names; `embedding`, `vectorStore`, `adapterConfig` and `refresh.cron` are removed, as are the `file` and `http` source kinds and `indexDocument` / `deleteDocument` on the service. Each retired key is refused with what to write instead.
</Callout>

## Wiring by hand

An app that mounts the service and a store itself, instead of declaring
`requires: ['knowledge']`, keeps its own: the runtime adds neither a second
service nor a store. This is also how the in-memory store is mounted for a demo
or a test.

```ts
import { ObjectKernel } from '@objectstack/core';
// objectstack.config.ts
import { defineStack } from '@objectstack/spec';
import { KnowledgeServicePlugin } from '@objectstack/service-knowledge';
import { KnowledgeMemoryPlugin } from '@objectstack/knowledge-memory';
// or, for prod (PostgreSQL + pgvector; a libSQL file is `@objectstack/knowledge-turso`):
// import { KnowledgePgvectorPlugin } from '@objectstack/knowledge-pgvector';
import { TaskNotes } from './src/ai/task-notes.knowledge-source.js';

const kernel = new ObjectKernel();
kernel.use(new KnowledgeServicePlugin({
sources: [
{
id: 'task_notes',
label: 'Task notes',
adapter: 'memory',
source: { kind: 'object', object: 'task', contentFields: ['title', 'notes'] },
},
{
id: 'product_docs',
label: 'Product docs',
adapter: 'memory', // 'pgvector' once KnowledgePgvectorPlugin is registered below
source: { kind: 'object', object: 'product_doc', contentFields: ['title', 'body'] },
},
export default defineStack({
plugins: [
new KnowledgeServicePlugin(),
new KnowledgeMemoryPlugin(),
// new KnowledgePgvectorPlugin(),
],
}));
kernel.use(new KnowledgeMemoryPlugin());
// kernel.use(new KnowledgePgvectorPlugin());
knowledgeSources: [TaskNotes], // with `adapter: 'memory'`
// …
});
```

## Retrieving knowledge
Expand All @@ -77,7 +118,7 @@ Retrieval is a plain service call — no AI runtime required. Resolve the `knowl
service and call `search`. Hits are re-checked against the caller's
`ExecutionContext` (RLS), sorted by score, and capped at `topK` before they come
back. Because the re-check runs after ranking, for a caller other than the
system identity the service asks each object source for more hits than `topK`,
system identity the service asks each source for more hits than `topK`,
and asks once more when too few records survive, so a caller who may read few of
the matching records still gets up to `topK` hits
([the protocol](/docs/protocol/knowledge) gives the factors and the cap). A
Expand Down Expand Up @@ -128,7 +169,7 @@ installed ([Connect an MCP Client](/docs/ai/connect-mcp)).

## Searching inside chosen records

Pass `scope` to search only inside some records: the records an object source indexes, or a parent record that source reaches through a lookup it lists in `metadataFields`.
Pass `scope` to search only inside some records: the records a source indexes, or a parent record that source reaches through a lookup it lists in `metadataFields`.

```ts
// Only the clauses of one policy: the clause source lists its `policy` lookup in metadataFields.
Expand Down Expand Up @@ -191,13 +232,13 @@ const vectors = await embedder.embed(chunks.map((c) => c.content));

## Splitting documents into passages

The knowledge service cuts each document into passages once, and every adapter that takes passages (`knowledge-memory` does) indexes the same ones. An object source chooses how with `split`:
The knowledge service cuts each document into passages once, and every adapter that takes passages (`knowledge-memory` does) indexes the same ones. A source chooses how with `split`:

```ts
source: {
kind: 'object',
object: 'policy',
contentFields: ['title', 'body'],
content: ['title', 'body'],
split: { strategy: 'markdown', maxChars: 600 },
}
```
Expand Down
3 changes: 1 addition & 2 deletions content/docs/getting-started/quick-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ AI/ML capabilities - agents, skills, tools, MCP exposure, RAG, and cost tracking
| **[MCP](/docs/references/ai/mcp)** | `mcp.zod.ts` | MCPServerRef, MCPToolBinding | MCP server exposure and tool bindings |
| **[Model Registry](/docs/references/ai/model-registry)** | `model-registry.zod.ts` | ModelRegistry, ModelProvider | LLM model management |
| **[Conversation](/docs/references/ai/conversation)** | `conversation.zod.ts` | ConversationSession | Conversation management |
| **[Embedding](/docs/references/ai/embedding)** | `embedding.zod.ts` | EmbeddingModel, VectorStore | Embedding models and vector stores |
| **[Knowledge Source](/docs/references/ai/knowledge-source)** | `knowledge-source.zod.ts` | KnowledgeSource, KnowledgeRefreshPolicy | RAG ingestion sources |
| **[Knowledge Source](/docs/references/ai/knowledge-source)** | `knowledge-source.zod.ts` | KnowledgeSource, KnowledgeSplit | The `knowledge_source` metadata type: which records and fields the knowledge service indexes |
| **[Knowledge Document](/docs/references/ai/knowledge-document)** | `knowledge-document.zod.ts` | KnowledgeDocument, KnowledgeChunk | RAG documents and chunks |
| **[Usage](/docs/references/ai/usage)** | `usage.zod.ts` | AIUsageRecord, TokenUsage | AI usage and cost tracking |
| **[Solution Blueprint](/docs/references/ai/solution-blueprint)** | `solution-blueprint.zod.ts` | BlueprintObject, BlueprintApp | Blueprint format for AI app generation |
Expand Down
Loading
Loading