Knowledge Document — AI Protocol reference
Knowledge Document / Chunk / Hit — canonical shapes shared by every IKnowledgeAdapter implementation.
Knowledge Document / Chunk / Hit — canonical shapes shared by every
IKnowledgeAdapter implementation.
The knowledge service owns the structural split (ADR-0161 K1): it cuts a
document into passages once, by the source's split key, and hands the
passages to every adapter that declares capabilities.chunks as the
document's chunks. An adapter that does not declare it receives whole
documents and splits them itself. The framework never sees a vector.
See content/docs/protocol/knowledge.mdx for the full design.
Source: packages/spec/src/ai/knowledge-document.zod.ts
TypeScript Usage
import { KnowledgeChunkSchema, KnowledgeDocumentSchema, KnowledgeHitSchema } from '@objectstack/spec/ai';
import type { KnowledgeChunk, KnowledgeDocument, KnowledgeHit } from '@objectstack/spec/ai';
// Validate data
const result = KnowledgeChunkSchema.parse(data);KnowledgeChunk
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| id | string | ✅ | |
| documentId | string | ✅ | |
| index | integer | ✅ | |
| content | string | ✅ | |
| headingPath | string[] | optional | Headings the chunk sits under, outermost first (markdown strategy) |
| metadata | never | optional | [REMOVED] KnowledgeChunk.metadata was removed in @objectstack/spec 18 (ADR-0049, ADR-0161 K8) — nothing ever wrote or read it: the knowledge service cuts the passages and sets no per-passage metadata, and no adapter consulted one. Delete the key. A passage takes its document's metadata (KnowledgeDocument.metadata), which is what adapters filter on. |
KnowledgeDocument
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| id | string | ✅ | Document id |
| sourceId | string | ✅ | Index key of the owning knowledge source |
| sourceRecordId | string | optional | |
| content | string | ✅ | |
| title | string | optional | |
| metadata | Record<string, any> | optional (default: {}) | |
| permissions | string[] | optional | |
| organizationId | string | optional | Organization of the record the document was assembled from; set by the knowledge service under a walled tenancy posture |
| docHash | string | optional | Service-computed hash of the assembled document (content, title, metadata, and organizationId when set); stored and returned as stored by the adapter |
| chunks | { id: string; documentId: string; index: integer; content: string; … }[] | optional | Service-cut passages of the document, handed to an adapter that declares capabilities.chunks |
Nested Shape: KnowledgeDocument.chunks[number]
| Property | Type | Required | Description |
|---|---|---|---|
| id | string | ✅ | |
| documentId | string | ✅ | |
| index | integer | ✅ | |
| content | string | ✅ | |
| headingPath | string[] | optional | Headings the chunk sits under, outermost first (markdown strategy) |
| metadata | never | optional | [REMOVED] KnowledgeChunk.metadata was removed in @objectstack/spec 18 (ADR-0049, ADR-0161 K8) — nothing ever wrote or read it: the knowledge service cuts the passages and sets no per-passage metadata, and no adapter consulted one. Delete the key. A passage takes its document's metadata (KnowledgeDocument.metadata), which is what adapters filter on. |
KnowledgeHit
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| chunkId | string | ✅ | |
| documentId | string | ✅ | |
| sourceId | string | ✅ | |
| sourceRecordId | string | optional | |
| score | number | ✅ | |
| snippet | string | ✅ | |
| title | string | optional | |
| metadata | Record<string, any> | optional (default: {}) | |
| docHash | string | optional | Stored docHash of the hit's document, returned as stored by the adapter |
| headingPath | string[] | optional | Headings the hit's chunk sits under, outermost first |