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. Built-in retriever implementations are in pkg/retriever/weaviate and pkg/retriever/pgvector. Bring your own by implementing interfaces.Retriever. Infrastructure setup (local dev):
# Weaviate
docker run --rm -p 8080:8080 -p 50051:50051 cr.weaviate.io/semitechnologies/weaviate:latest

# pgvector (Postgres with pgvector extension)
docker run --rm -p 5432:5432 -e POSTGRES_PASSWORD=pass pgvector/pgvector:pg16

Enable

import "github.com/agenticenv/agent-sdk-go/pkg/retriever/weaviate"

r, err := weaviate.NewRetriever("product_knowledge",
    weaviate.WithHost("localhost:8080"),
    weaviate.WithClassName("ProductDocs"),
)
if err != nil {
    return err
}

a, err := agent.NewAgent(
    agent.WithLLMClient(llmClient),
    agent.WithRetrievers(r),
    agent.WithRetrieverMode(agent.RetrieverModeAgentic), // default
)
Pass multiple retrievers — each must have a unique Name():
agent.WithRetrievers(productRetriever, supportRetriever)

Retriever modes

Set with WithRetrieverMode:
ModeBehaviorBest for
RetrieverModeAgentic (default)LLM calls the retriever as a tool when it decides to searchMulti-step agents where retrieval is not always needed
RetrieverModePrefetchContext injected before every LLM call — no retriever tools exposedAlways-grounded Q&A, enterprise knowledge bases
RetrieverModeHybridPrefetch context plus retriever exposed as a toolGrounded defaults with on-demand deeper search
agent.WithRetrieverMode(agent.RetrieverModeAgentic)
agent.WithRetrieverMode(agent.RetrieverModePrefetch)
agent.WithRetrieverMode(agent.RetrieverModeHybrid)
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.

Backends

Weaviate

r, err := weaviate.NewRetriever("product_knowledge",
    weaviate.WithHost("localhost:8080"),
    weaviate.WithClassName("ProductDocs"),
)
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:
import "github.com/agenticenv/agent-sdk-go/pkg/retriever/pgvector"

r, err := pgvector.NewRetriever("support_knowledge", embedFn,
    pgvector.WithDSN("postgres://user:pass@localhost:5432/mydb"),
    pgvector.WithTable("documents"),
)

Custom retriever

Implement interfaces.Retriever:
type Retriever interface {
    Name() string
    Search(ctx context.Context, query string) ([]interfaces.Document, error)
}
Register with WithRetrievers. In agentic and hybrid modes, the retriever becomes a callable tool — Name() is the tool name the LLM uses.

Example

Retrieval

Agentic, prefetch, and hybrid RAG

Memory

User-scoped long-term memory

Hooks

Query rewriting and document filtering

Tools

How retriever tools merge with other tools

Configuration

WithRetrievers and WithRetrieverMode