Skip to content

API Reference

Run the full retrieval pipeline. Returns a RetrievalBundle.

const bundle = await retrieve({
store: CorpusStore, // required
roleId: string, // required
taskText: string, // required
overlay: RoleOverlay | null, // null = shared corpus only
packetContextSummary?: string,
lexicalOnly?: boolean, // skip semantic search
embeddingModel?: string, // Ollama model (default: nomic-embed-text)
ollamaUrl?: string, // default: http://localhost:11434
});

SQLite-backed document and chunk storage.

const store = new CorpusStore(":memory:"); // or file path
store.insertDocument(doc);
store.insertChunk(chunk);
store.searchFTS(query, limit);
store.insertEmbedding(chunkId, vector, model);
store.close();

Load a JSON corpus file into a store. Returns { documents_ingested, chunks_ingested, errors }.

Same as above but accepts parsed JSON directly.

Validate a role overlay JSON against the schema. Returns { valid, errors }.

Validate a retrieval bundle JSON against the schema. Returns { valid, errors }.

These are used internally by retrieve() but are exported for testing and custom pipelines.

FunctionPurpose
buildQuery(taskText, overlay, context?)Overlay-aware query expansion
lexicalSearch(store, ftsQuery, limit?)BM25 via FTS5
semanticSearch(store, queryText, limit?, model?, url?)Embedding similarity
mergeCandidates(lexical, semantic)Union + deduplicate
metadataFilter(candidates, overlay)Apply governance rules
rerank(candidates, overlay)Weighted scoring + diversity
assembleBundle(input)Produce final RetrievalBundle

The governed output of every retrieval operation.

FieldTypeDescription
version"1.0"Schema version
role_idstringWhich role this was retrieved for
queryQueryTraceFull audit trail of query construction
summaryRetrievalSummaryAggregate stats
selectedRetrievedChunk[]Top evidence with scores
rejectedRejectedCandidate[]Why candidates were excluded
provenanceProvenanceSummaryTrust and freshness posture
warningsRetrievalWarning[]Degradation signals
diagnosticsRetrievalDiagnosticsPerformance stats

Declarative per-role retrieval configuration.

FieldTypeDescription
role_idstringRole identifier
missionstringWhat this role retrieves for
anti_goalsstring[]What it must NOT drift into
vocabularyRoleVocabularyBoost/suppress terms
source_policySourcePolicyPreferred/forbidden sources
retrieval_policyRetrievalPolicyWeights and limits
synthesis_policySynthesisPolicyOutput guidance
eval_profileEvalProfileGolden set for testing
StateActionWhen
healthycontinueNormal operation
no_overlaycontinueShared corpus only
no_strong_matchwarnBundle is empty or weak
stale_dominantwarnMajority of evidence is outdated
forbidden_hitcontinueForbidden sources removed
conflictingwarnHigh-trust sources disagree