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
Name():
Retriever modes
Set withWithRetrieverMode:
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
pgvector
Postgres with pgvector extension — requires an embed function:Custom retriever
Implementinterfaces.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
Related
Memory
User-scoped long-term memory
Hooks
Query rewriting and document filtering