Table of Contents
- Overview
- Components
- Installation
- Basic Usage
- Advanced Features
- Agent Integration
- Best Practices
- API Reference
Overview
The RAG system lets you:- Process and chunk documents with configurable sizes and overlap
- Embed documents and store the vectors in a vector store (FAISS and others)
- Perform semantic search over documents with optional metadata filtering
- Generate answers by passing retrieved context to any MultiMind model
- Integrate retrieval into the agent system as a custom tool
RAG (retrieval only — you compose it with a model for generation). It is configured with a single RAGConfig object that bundles the vector store, embedding, retrieval, and document-processing settings.
Components
1. Documents
Documents are plain data objects:document_config dict on RAGConfig (min_chunk_size, max_chunk_size, chunk_overlap). Note that RAG.add_documents(process=True) only re-chunks when the document processor has a model attached; with the default configuration documents are embedded as-is.
2. Embeddings
Embedding behavior is configured withEmbeddingConfig. Supported model_type values include "openai" (e.g. text-embedding-ada-002, 1536 dimensions) and "huggingface" (e.g. sentence-transformers/all-MiniLM-L6-v2, 384 dimensions, fully local). The OpenAI embedding client does not read OPENAI_API_KEY itself; pass the key through custom_params:
3. Vector Stores
Vector stores are configured withVectorStoreConfig. FAISS (in-memory, fast similarity search) has a convenience constructor; the dimension must match your embedding model:
vector-stores extra; see multimind.vector_store for the factory and per-backend configs. Not every backend in VectorStoreType is implemented: AwaDB, BagelDB, BaiduCloud, Clarifai, ClickHouse, DashVector, Databricks Vector Search, DeepLake, DingoDB, Elastic Vector Search (legacy) and Epsilla are stubs that raise NotImplementedError, and Cassandra, Azure AI Search, Azure Cosmos DB, LLMRails and TileDB are only partially implemented. The per-backend status is in feature-status.md.
Installation
Install the RAG system with all dependencies:Basic Usage
1. Initialize the RAG System
2. Add Documents
3. Retrieve and Generate
RAG.retrieve returns a list of multimind.retrieval.RetrievalResult objects (content, score, metadata, document_id, source, chunk_id) whose score is at or above similarity_threshold; you build the prompt and generate with any model:
Advanced Features
1. Metadata Filtering
RAG.retrieve accepts a filter_criteria dict, but in 1.0.0 its entries are forwarded to the vector store as keyword arguments, so filter_criteria={"category": "documentation"} raises RetrievalError (VectorStore.search() got an unexpected keyword argument 'category'). Until that is fixed, over-fetch and filter on the result metadata:
2. Batch Queries
3. Model Switching
Retrieval is independent of the generating model, so you can pick a model per task:ModelSession in the cookbook.
4. Clearing the Store
Agent Integration
Retrieval plugs into the agent system as a custom tool (subclassBaseTool):
CalculatorTool is the only tool shipped in multimind.agents.tools; anything else is a BaseTool subclass you write.
Best Practices
-
Document Processing
- Choose appropriate chunk sizes based on your use case
- Use meaningful metadata for better filtering
- Clean and normalize text before processing
-
Embedding Models
- Use OpenAI embeddings for production applications
- Use HuggingFace models for local or cost-sensitive use cases
- Match the vector store
dimensionto your embedding model
-
Vector Stores
- Use FAISS for high-performance, in-memory applications
- Use a persistent backend (via the
vector-storesextra) when data must survive restarts - Monitor memory usage with large document collections
-
Retrieval Quality
- Set a
similarity_thresholdand refuse to answer when nothing relevant is retrieved - Consider grounding-checking generated answers — see hallucination detection
- Set a
-
Agent Integration
- Combine RAG with other tools for comprehensive solutions
- Use memory to maintain context across interactions
- Implement proper error handling and fallbacks
API Reference
RAG Class
RAGConfig
RAGConfig is a dataclass:
multimind.rag also exports BaseRAG, RAGError, GraphRetriever, PostProcessor and PostProcessingConfig; a fluent RAGPipeline lives in multimind.rag.fluent (see examples/rag/fluent_rag_example.py).
For the HTTP RAG service, see rag_api.md and the generated openapi-rag.json.