Skip to main content
Retrieval-Augmented Generation (RAG) lets agents query external knowledge bases and ground responses in up-to-date or domain-specific content — without hardcoding it into the prompt. When a retrieval fires, the SDK calls Search(ctx, query) on your retriever, collects the returned []Document, and injects the document content into the LLM request — either as a labeled “Relevant Context” message ahead of conversation history (prefetch) or as a tool result the model requested (agentic). The system prompt itself is never modified. The LLM then sees the retrieved text alongside the user prompt when generating its response. Built-in retriever implementations are in pkg/retriever/weaviate and pkg/retriever/pgvector. Bring your own by implementing interfaces.Retriever. Infrastructure setup (local dev):

Enable

Pass multiple retrievers — each must have a unique Name():

Retriever modes

Set with WithRetrieverMode:
Choosing a mode: use Agentic when retrieval is optional — the model decides when to search. Use Prefetch when every LLM call must be grounded (Q&A bots, customer support). Use Hybrid when you want a baseline of context on every turn but also want the model to be able to search deeper on-demand.
In agentic and hybrid modes, each retriever is registered as a tool the LLM can invoke. Its name must be unique across all tool sources. Use BeforeRetrieveHook to rewrite the query and AfterRetrieveHook to filter or re-rank results — see Hooks.

Backends

Weaviate

Local Docker, zero auth for development. The first argument is the retriever’s tool name — must be unique.

pgvector

Postgres with pgvector extension — requires an embed function:

Custom retriever

Implement interfaces.Retriever:
Name() doubles as the tool name in agentic and hybrid modes — keep it short and descriptive since the LLM uses it to decide when to call. Search receives the raw query string and returns documents whose Content field is injected into the prompt. Register with WithRetrievers.

Example

Retrieval

Agentic, prefetch, and hybrid RAG

Memory

User-scoped long-term memory

Hooks

Query rewriting and document filtering