Skip to main content
Haystack pipelines provide a composable architecture for building RAG systems. This page covers pipeline design patterns, component composition, and production best practices.

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_size
Use 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 content

Common patterns

Multi-stage retrieval

  1. Fast first-pass retrieval (semantic or hybrid)
  2. Reranking with cross-encoder
  3. Diversification or MMR
  4. Final top-k selection

Cost optimization

  1. Smaller candidate pool (lower top_k)
  2. Context compression before generation
  3. Cheaper model tiers for non-critical stages

Quality improvement

  1. Start with semantic search baseline
  2. Add hybrid search for keyword coverage
  3. Add reranking for precision
  4. Add query enhancement for recall
  5. 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