Knowledge package
Store simple durable knowledge, inject pinned context, search chunks, and expose lookup/manage tools.
Use @yolk-sdk/knowledge when your app needs durable agent-readable knowledge.
Knowledge is intentionally small:
KnowledgeDocument
id
slug
title
purpose
origin
content
summary?
errorMessage?
reviewedAt?
metadata?
status: processing | ready | error
availability: pinned | searchable | archived
createdAt
updatedAtKnowledgeSource separately models File, Url, or Text ingestion origins. Construct them with
KnowledgeFileSource.make, KnowledgeUrlSource.make, and KnowledgeTextSource.make from
@yolk-sdk/knowledge/documents.
IndexedKnowledgeDocument carries that source plus indexing status and optional
title/summary/error/hash/count metadata. It is distinct from the content-oriented
KnowledgeDocument above.
Status and availability are independent:
processing: indexing, not ready for prompt/searchready: usable when availability allowserror: retained with an ingestion/indexing failurepinned: host may inject into startup context and searchsearchable: host may expose through searcharchived: retained but normally excluded
The helpers do not enforce this policy automatically. Pass only selected documents to
buildKnowledgeContext, and filter status/availability in your SearchIndexStore adapter.
Install:
pnpm add @yolk-sdk/knowledge@canary @yolk-sdk/agent@canary effect@4.2.0Use pinned knowledge as context
import { buildKnowledgeContext } from '@yolk-sdk/knowledge'
const context = buildKnowledgeContext({
documents,
maxCharacters: 6000
})Add the resulting text to your system prompt. Your app chooses which documents are pinned.
Ingest a document into search
ingestKnowledgeDocument updates an IndexedKnowledgeDocument: it upserts processing, extracts,
chunks, embeds and summarizes, replaces chunks, then marks the index record ready. It does not
update KnowledgeStore automatically.
Fragment; loadedSource and service layers are host-owned:
import { KnowledgeDocumentId, KnowledgeScopeId } from '@yolk-sdk/knowledge/documents'
import { ingestKnowledgeDocument } from '@yolk-sdk/knowledge/ingestion'
const program = ingestKnowledgeDocument({
scopeId: KnowledgeScopeId.make('workspace-docs'),
documentId: KnowledgeDocumentId.make('doc_123'),
source: loadedSource
})Provide these layers from your app:
SearchIndexStoreKnowledgeExtractorKnowledgeChunkerKnowledgeEmbedderKnowledgeSummarizer
The pipeline is not a cross-operation transaction. Your SearchIndexStore owns atomic chunk
replacement, rollback policy, and ready/error filtering. Failures retain their stage on
KnowledgeIngestionError and trigger a best-effort markDocumentError call with the message.
Search documents
import { Effect } from 'effect'
import { KnowledgeScopeId, KnowledgeSearchScope } from '@yolk-sdk/knowledge/documents'
import { searchKnowledge } from '@yolk-sdk/knowledge/search'
const results = await Effect.runPromise(
searchKnowledge({
scope: KnowledgeSearchScope.make({ id: KnowledgeScopeId.make('workspace-docs') }),
query: 'How do agent tools work?',
limit: 5,
mode: 'hybrid',
contextChunks: 1
}).pipe(Effect.provide(HostKnowledgeSearchLayer))
)The value KnowledgeSearchScope is the single-id constructor (tag KnowledgeScope).
KnowledgeSearchScopes.make({ ids }) covers multiple ids. The type KnowledgeSearchScope is the union.
Scope and document identities use distinct KnowledgeScopeId / KnowledgeDocumentId schemas
from @yolk-sdk/knowledge/documents. .make is for trusted values; Effect-decode request and
persisted IDs with Schema.decodeUnknownEffect before entering store, chunking, or ingestion
contracts. Both remain non-empty trimmed strings on the wire. Branding does not prove scope
membership or authorization.
The package defines the search contract. Your app implements the store and embedding provider.
Expose tools
import { makeKnowledgeLookupTool, makeKnowledgeManageTool } from '@yolk-sdk/knowledge/agent'
const lookupTool = makeKnowledgeLookupTool(lookupHandlers)
const manageTool = makeKnowledgeManageTool(manageHandlers)Use knowledge_lookup for search/get and knowledge_manage for explicit saves, pins, archives, renames, or deletes. Your app owns authorization and scope resolution.
Both tools declare an output schema (KnowledgeLookupOutput, KnowledgeManageOutput) and return
its JSON encoding as structuredContent next to the text, which code mode scripts receive:
- lookup:
{ operation: 'search', results }or{ operation: 'get', document }, with ISO date strings in documents; - manage:
{ operation, document }, wheredocumentis{ id, slug, title }.