RAG
Retrieval-augmented generation (RAG) lets an agent answer from your own documents: you load files, split them into chunks, index the chunks in a vector store, and give the agent a search tool. Use it when answers depend on a corpus the model hasn’t seen, such as internal docs, policies or reports.
Loomflow ships its own loader and vector-store stack, so you can build
retrieval-augmented agents without pulling in LangChain. Everything is
async-first and typed, and the retriever is an ordinary @tool that
an Agent already knows how to call.
from loomflow import Agent, tool
from loomflow.memory.embedder import OpenAIEmbedder
from loomflow.vectorstore import ChromaVectorStore
from loomflow.loader import load, RecursiveChunker
# 1. Load + chunk
doc = load("research.pdf")
chunks = RecursiveChunker(chunk_size=600).split(doc.content, source="research.pdf")
# 2. Embed + store
store = ChromaVectorStore(OpenAIEmbedder(), persist_directory="./chroma-db")
await store.add(chunks)
# 3. Retriever as a tool
@tool
async def search_docs(query: str) -> str:
"""Search the indexed PDFs."""
hits = await store.search(query, k=4)
return "\n\n---\n\n".join(h.chunk.content for h in hits)
# 4. Agent uses the tool
agent = Agent(
"Answer using the indexed docs. Cite the source filename.",
model="claude-opus-4-7",
tools=[search_docs],
)
result = await agent.run("What's our retention metric definition?")Three layers, one pipeline
Document(content=<markdown>).ChunkersRecursive · Markdown · Sentence · Token. Strategy depends on the source format.Vector storesInMemory / Chroma / Postgres / FAISS. Async surface, MMR diversity, hybrid search, Mongo-style filters.End-to-end tutorialBuild a RAG agent over a folder of PDFs from scratch.Optional dependencies
The RAG primitives are gated behind extras so the base install stays lean:
pip install 'loomflow[loader]' # all loaders (unstructured for PDF)
pip install 'loomflow[loader-pdf]' # unstructured[pdf]
pip install 'loomflow[loader-pdf-docling]' # docling (alternative PDF backend)
pip install 'loomflow[loader-docx]' # python-docx
pip install 'loomflow[loader-excel]' # openpyxl
pip install 'loomflow[loader-html]' # beautifulsoup4
pip install 'loomflow[vectorstore]' # all vector stores
pip install 'loomflow[vectorstore-chroma]' # chromadb
pip install 'loomflow[vectorstore-postgres]'# asyncpg + pgvector
pip install 'loomflow[vectorstore-faiss]' # faiss-cpu + numpyEach loader and store raises a helpful ImportError if its dependency
isn’t installed.
Memory vs Vector stores. Memory (the memory= kwarg on
Agent) is for conversational state: episodes, working blocks,
and Facts extracted from chats. VectorStore is for document
corpora: the things your agent retrieves from but doesn’t build
up. They’re separate primitives with separate backends.