Skip to content

@Rag

The @Rag decorator (rag/*.rag.ts) defines a knowledge base component implementing RagConnector (or extending the built-in zero-dependency SqliteFtsConnector). Agents attach knowledge bases via @Agent({ rag: [{ use: DocsRag, mode: RagMode.Tool | RagMode.Context }] }), and AGBoss automatically formats retrieved passages with [source] citations and tracks retrieval spend under rag:<name>.

Complete @Rag examples (SqliteFtsConnector and custom RagConnector)

Section titled “Complete @Rag examples (SqliteFtsConnector and custom RagConnector)”
Option Type Required Description
name string Yes Unique identifier for the knowledge base ("company_handbook"); keys cost attribution (rag:company_handbook) and generated search tool names.
description string Yes Explains what documents this knowledge base holds so the agent knows when to query it in RagMode.Tool.
topK number Yes Maximum number of passages returned per retrieval call (required, no implicit default).
prompt / promptUrls string / readonly string[] No Additional instructions guiding how the agent should query or cite passages from this knowledge base.
deps readonly Token[] No Constructor dependencies (AppEnvironment, ExecutionContext, @Injectable vector clients) verified against constructor parameters.
Related Entity Import Path Purpose
RagConnector "@agboss/core/rag" Interface implemented by @Rag classes (retrieve(query, { topK, signal }): Promise<RagRetrieval> and optional index(docs)).
SqliteFtsConnector "@agboss/core/rag" Built-in zero-dependency SQLite FTS5 BM25 connector with automatic tokenization and ranking.
RagMode (Tool, Context) "@agboss/core" Used in @Agent({ rag: [{ use: MyRag, mode }] }): RagMode.Tool exposes a search tool the model calls on demand; RagMode.Context pre-fetches top-K passages before the model call.
testRag(RagClass, options?) "@agboss/core/testing" Isolated unit runner that tests retrieve() and rag:<name> cost tracking with DI overrides without booting an agent.