Yolk SDK
Knowledge

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
  updatedAt

KnowledgeSource 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/search
  • ready: usable when availability allows
  • error: retained with an ingestion/indexing failure
  • pinned: host may inject into startup context and search
  • searchable: host may expose through search
  • archived: 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.0

Use 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.

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:

  • SearchIndexStore
  • KnowledgeExtractor
  • KnowledgeChunker
  • KnowledgeEmbedder
  • KnowledgeSummarizer

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 }, where document is { id, slug, title }.

On this page