ObjectStackObjectStack

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

PropertyTypeRequiredDescription
idstring✅
documentIdstring✅
indexinteger✅
contentstring✅
headingPathstring[]optionalHeadings the chunk sits under, outermost first (markdown strategy)
metadataneveroptional[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

PropertyTypeRequiredDescription
idstring✅Document id
sourceIdstring✅Index key of the owning knowledge source
sourceRecordIdstringoptional
contentstring✅
titlestringoptional
metadataRecord<string, any>optional (default: {})
permissionsstring[]optional
organizationIdstringoptionalOrganization of the record the document was assembled from; set by the knowledge service under a walled tenancy posture
docHashstringoptionalService-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; … }[]optionalService-cut passages of the document, handed to an adapter that declares capabilities.chunks

Nested Shape: KnowledgeDocument.chunks[number]

PropertyTypeRequiredDescription
idstring✅
documentIdstring✅
indexinteger✅
contentstring✅
headingPathstring[]optionalHeadings the chunk sits under, outermost first (markdown strategy)
metadataneveroptional[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

PropertyTypeRequiredDescription
chunkIdstring✅
documentIdstring✅
sourceIdstring✅
sourceRecordIdstringoptional
scorenumber✅
snippetstring✅
titlestringoptional
metadataRecord<string, any>optional (default: {})
docHashstringoptionalStored docHash of the hit's document, returned as stored by the adapter
headingPathstring[]optionalHeadings the hit's chunk sits under, outermost first

On this page