Embeddings & RAG
Pluggable embedders and vector stores, a retrieval tool, and a Broadway ingestion pipeline.
agentsea_embeddings pairs an Embedder with a VectorStore behind one handle. Both are behaviours, so adapters swap freely. API on HexDocs.
Index & search
{:ok, store} = AgentSea.VectorStore.Memory.start_link()
handle =
AgentSea.Embeddings.new(
store_mod: AgentSea.VectorStore.Memory,
store: store,
embedder: AgentSea.Embedder.OpenAI,
embed_opts: [api_key: System.fetch_env!("OPENAI_API_KEY")]
)
AgentSea.Embeddings.index(handle, [
%{id: "refund", text: "Refunds are accepted within 30 days."},
%{id: "hours", text: "We are open weekdays, 9 to 5."}
])
[hit | _] = AgentSea.Embeddings.search(handle, "can I get my money back?", 1)
hit.id # "refund"
hit.score # cosine similarityEmbedders
AgentSea.Embedder.Hashing— dependency-free, deterministic; great for tests/dev.AgentSea.Embedder.OpenAI/AgentSea.Embedder.Cohere— remote, over Req.AgentSea.Embedder.Bumblebee— in-process Hugging Face models via Bumblebee + Nx (ships in agentsea_bumblebee), no embedding API needed.
Vector stores
The same handle works over any of four stores:
# In-memory (default; dev/tests)
{:ok, store} = AgentSea.VectorStore.Memory.start_link()
# pgvector (Postgres + the vector extension)
{:ok, conn} = Postgrex.start_link(database: "agentsea", hostname: "localhost")
store = AgentSea.VectorStore.Postgres.store(conn, table: "embeddings", dimensions: 1536)
:ok = AgentSea.VectorStore.Postgres.ensure_table(store)
# Qdrant
store = AgentSea.VectorStore.Qdrant.store(url: "http://localhost:6333", collection: "docs")
# Pinecone
store = AgentSea.VectorStore.Pinecone.store(host: "https://my-index-xxxx.svc.pinecone.io")Give an agent retrieval
AgentSea.Embeddings.RetrievalTool is a ready-made search_knowledge tool. Add it to an agent and pass the embeddings handle in the run context — the agent retrieves on demand:
config = %AgentSea.Agent.Config{
name: :support,
model: "claude-opus-4-8",
provider: {AgentSea.Providers.Anthropic, []},
tools: [AgentSea.Embeddings.RetrievalTool]
}
{:ok, agent} = AgentSea.Agent.start_link(config)
{:ok, answer} = AgentSea.Agent.run(agent, "What's the refund policy?", %{embeddings: handle})Bulk ingestion
For documents at scale, agentsea_ingest provides a Broadway pipeline — chunk → embed → store — with batching and backpressure, writing into any of the stores above. Pair it with structured extraction and agentsea_evaluate to measure retrieval quality.
Next
Route generation across providers with the gateway, or revisit tools and memory on the Agents page.