Skip to content
Navigation

Retrieval framework for Exo agents: embeddings, vector stores, chunkers, parsers, and a full RAG pipeline with agentic retrieval, knowledge graph expansion, hybrid search, query rewriting, and reranking.

Installation

Part of the exo-ai monorepo:

bash
git clone https://github.com/Midsphere-AI/exo-ai.git && cd exo-ai
uv sync

Optional backends can be enabled with extras from the packages/exo-retrieval directory:

bash
uv sync --extra chroma      # ChromaDB vector store
uv sync --extra pgvector    # PostgreSQL/pgvector vector store
uv sync --extra pdf         # PDF parsing

Module path

python
import exo.retrieval

Package exports

ExportModuleDescription
Documentexo.retrieval.typesA document stored in a retrieval system
Chunkexo.retrieval.typesAn immutable slice of a document for retrieval
RetrievalResultexo.retrieval.typesA scored chunk returned from a retrieval query
RetrievalErrorexo.retrieval.typesRaised when a retrieval operation fails
Embeddingsexo.retrieval.embeddingsAbstract base class for embedding providers
OpenAIEmbeddingsexo.retrieval.openai_embeddingsOpenAI embeddings API provider
VertexEmbeddingsexo.retrieval.vertex_embeddingsGoogle Vertex AI embeddings provider
HTTPEmbeddingsexo.retrieval.http_embeddingsGeneric HTTP endpoint embeddings provider
VectorStoreexo.retrieval.vector_storeAbstract base class for vector stores
InMemoryVectorStoreexo.retrieval.vector_storeIn-memory vector store using cosine similarity
ChromaVectorStoreexo.retrieval.backends.chromaChromaDB vector store backend
PgVectorStoreexo.retrieval.backends.pgvectorPostgreSQL/pgvector vector store backend
Chunkerexo.retrieval.chunkerAbstract base class for text chunkers
CharacterChunkerexo.retrieval.chunkerFixed character-count windows with overlap
ParagraphChunkerexo.retrieval.chunkerSplits at paragraph boundaries
TokenChunkerexo.retrieval.chunkerSplits by token count (uses tiktoken)
Parserexo.retrieval.parsersAbstract base class for document parsers
TextParserexo.retrieval.parsersPassthrough parser for plain text
MarkdownParserexo.retrieval.parsersStrips Markdown formatting, preserves structure
JSONParserexo.retrieval.parsersFlattens JSON to readable text with key paths
PDFParserexo.retrieval.parsersExtracts text from PDFs (requires pymupdf)
Retrieverexo.retrieval.retrieverAbstract base class for retrievers
VectorRetrieverexo.retrieval.retrieverDense vector retriever using embeddings + vector store
SparseRetrieverexo.retrieval.sparse_retrieverBM25 keyword-based sparse retriever
HybridRetrieverexo.retrieval.hybrid_retrieverFuses dense and sparse results via Reciprocal Rank Fusion
AgenticRetrieverexo.retrieval.agentic_retrieverMulti-round LLM-driven retriever with query refinement
GraphRetrieverexo.retrieval.graph_retrieverExpands results via knowledge graph traversal
QueryRewriterexo.retrieval.query_rewriterLLM-based query rewriting for improved retrieval
Rerankerexo.retrieval.rerankerAbstract base class for rerankers
LLMRerankerexo.retrieval.rerankerLLM-based passage relevance reranking
Tripleexo.retrieval.triple_extractorSubject-predicate-object triple for knowledge graphs
TripleExtractorexo.retrieval.triple_extractorLLM-based knowledge graph triple extraction
retrieve_toolexo.retrieval.toolsFactory that wraps a retriever as an agent tool
index_toolexo.retrieval.toolsFactory that wraps an indexing pipeline as an agent tool

Submodules

  • Embeddings — Embeddings ABC, OpenAIEmbeddings, VertexEmbeddings, HTTPEmbeddings
  • Vector Stores — VectorStore ABC, InMemoryVectorStore, ChromaVectorStore, PgVectorStore
  • Chunkers — Chunker ABC, CharacterChunker, ParagraphChunker, TokenChunker
  • Retrievers — Retriever ABC, VectorRetriever, SparseRetriever, HybridRetriever, AgenticRetriever, GraphRetriever, QueryRewriter, Reranker

Quick example

python
import asyncio
from exo.retrieval import (
    CharacterChunker,
    Document,
    InMemoryVectorStore,
    OpenAIEmbeddings,
    VectorRetriever,
    retrieve_tool,
)
from exo import Agent, run

# Set up the RAG pipeline
embeddings = OpenAIEmbeddings(api_key="sk-...")
store = InMemoryVectorStore()
retriever = VectorRetriever(embeddings, store)

# Index a document
doc = Document(id="readme", content="Exo is a modular multi-agent framework...")
chunker = CharacterChunker(chunk_size=500, chunk_overlap=50)
chunks = chunker.chunk(doc)

async def main():
    vecs = await embeddings.embed_batch([c.content for c in chunks])
    await store.add(chunks, vecs)

    # Give an agent the retrieve tool
    agent = Agent(
        name="assistant",
        model="openai:gpt-4o",
        tools=[retrieve_tool(retriever)],
    )
    result = await run(agent, "What is Exo?")
    print(result.output)

asyncio.run(main())