Retrieval Strategy Overview
Retrieval modes determine how documents are searched and ranked:- DEFAULT - Standard semantic similarity search using embeddings
- HYBRID - Combines semantic and keyword search
- SPARSE - Keyword-based search (e.g., BM25)
- MMR - Maximum Marginal Relevance for diverse results
- SEMANTIC_HYBRID - Provider-specific semantic hybrid (e.g., Azure AI Search)
Vector Store Query Modes
Default Similarity Search
Standard semantic search using vector embeddings:Hybrid Search
Combines semantic similarity with keyword matching (requires vector store support):Maximum Marginal Relevance (MMR)
MMR balances relevance with diversity to avoid redundant results:Semantic vs Keyword Search
Semantic Search
Uses embeddings to find conceptually similar content:- Understands synonyms and related concepts
- Works across languages
- Captures semantic meaning
- May miss exact keyword matches
- Requires quality embeddings
- More computationally expensive
Keyword Search (BM25)
Traditional keyword-based retrieval using BM25 algorithm:- Excellent for exact matches
- Fast and efficient
- No embedding required
- Good for technical terms and proper nouns
- Doesn’t understand synonyms
- Language-dependent
- Misses semantic relationships
Hybrid Approach
Combine both for best results:Custom Retrievers
Create custom retrieval logic by extendingBaseRetriever:
Multi-Stage Retrieval
Retrieve many candidates, then rerank:Retrieval with Filters
Combine retrieval modes with metadata filtering:Comparing Retrieval Modes
BM25 Retriever Example
Standalone BM25 retriever for keyword search:Best Practices
- Start with Default: Begin with semantic search, then experiment
- Use Hybrid for Production: Combines strengths of both approaches
- Tune Top-K: Retrieve more candidates (20-50) then rerank
- Apply Filters: Use metadata filters to narrow search space
- Monitor Performance: Track retrieval quality and latency
- Consider Domain: Technical docs may benefit from keyword search
Related Resources
- Vector Store Retrievers - Vector-based retrieval details
- VectorStoreIndex - Building vector indices
- Node Postprocessors - Reranking and filtering