Pipeline architecture
All Haystack pipelines in this module follow a three-stage pattern:1
Indexing stage
Load documents, generate embeddings, and store in vector database
2
Retrieval stage
Embed query, retrieve candidates, apply post-processing (reranking, filtering, diversification)
3
Generation stage (optional)
Format context, call LLM, return answer
Standard indexing pipeline
All indexing pipelines follow this pattern:Standard search pipeline
All search pipelines follow this pattern:Hybrid search pipeline pattern
Hybrid pipelines extend the standard pattern with dual retrieval and fusion:Query enhancement pipeline pattern
Query enhancement pipelines generate multiple query variants:Agentic RAG pipeline pattern
Agentic pipelines use self-reflection loops:Component composition utilities
EmbedderFactory
Creates and warms up embedders from config:RAGHelper
Creates generators and formats prompts:ConfigLoader
Loads and validates YAML configs:Production best practices
Configuration management
Use environment variables for secrets:
api_key: "${PINECONE_API_KEY}"Keep configs versioned with code
Use separate configs for dev/staging/prod environments
Error handling
All components have fallback behavior (e.g., compression returns original context on failure)
Log failures at ERROR level with context
Return partial results when possible rather than failing entirely
Performance optimization
Warm up embedders during initialization to avoid cold-start latency
Over-fetch during retrieval (2x top_k) to allow for diversification and filtering
Batch document embedding with configurable
batch_sizeUse appropriate
device setting (“cuda” for GPU, “cpu” for CPU)Monitoring
Log compression ratios for context compression
Log retrieval counts at each pipeline stage
Track quality scores in agentic pipelines
Set
LOG_LEVEL=DEBUG to see detailed prompt/response contentCommon patterns
Multi-stage retrieval
- Fast first-pass retrieval (semantic or hybrid)
- Reranking with cross-encoder
- Diversification or MMR
- Final top-k selection
Cost optimization
- Smaller candidate pool (lower top_k)
- Context compression before generation
- Cheaper model tiers for non-critical stages
Quality improvement
- Start with semantic search baseline
- Add hybrid search for keyword coverage
- Add reranking for precision
- Add query enhancement for recall
- Add agentic loop for complex queries
Next steps
Semantic search
See the standard pipeline pattern in action
Hybrid search
Learn about dual retrieval and fusion patterns
Components
Explore individual pipeline components