Skip to main content
The components directory contains reusable, self-contained Haystack pipeline building blocks that implement specific retrieval and generation sub-tasks. Feature pipelines compose these components rather than reimplementing the same logic.

Component overview

AgenticRouter

LLM-based decision-making for agentic RAG with tool selection and self-reflection

ContextCompressor

Reduces retrieved context using abstractive, extractive, or relevance filtering

QueryEnhancer

Multi-query, HyDE, and step-back query expansion

ResultMerger

RRF and weighted fusion for hybrid search results

AgenticRouter

An LLM-based decision-making component for agentic RAG pipelines.

Capabilities

  • Tool selection: Given a query, selects the appropriate processing path ("retrieval", "web_search", "calculation", or "reasoning")
  • Answer quality evaluation: Sends the query, draft answer, and retrieved context to the LLM and receives a JSON-structured assessment
  • Refinement decision: Computes whether the average quality score falls below a threshold
  • Answer refinement: Given issues and suggestions from evaluation, sends a targeted revision request to the LLM
  • Self-reflection loop: Orchestrates the full evaluate-refine cycle for up to max_iterations rounds

Implementation

src/vectordb/haystack/components/agentic_router.py

Usage

ContextCompressor

Reduces retrieved context to query-relevant fragments before generation.

Compression strategies

  • Abstractive: LLM generates a focused summary of the context relevant to the query
  • Extractive: LLM selects the N most relevant sentences from the original text
  • Relevance filtering: LLM evaluates each paragraph and drops those below a threshold
All methods fall back to returning the original context unchanged on LLM failure.

Implementation

src/vectordb/haystack/components/context_compressor.py

Usage

QueryEnhancer

Generates improved retrieval queries from the user’s original input.

Enhancement strategies

  • Multi-query: Generates N alternative phrasings of the original query (default N=3)
  • HyDE: Generates M hypothetical documents that would answer the query (default M=3)
  • Step-back: Generates a broader, more abstract version of the query

Implementation

src/vectordb/haystack/components/query_enhancer.py

Usage

ResultMerger

Fuses results from multiple retrieval sources into a single ranked list.

Fusion strategies

  • RRF (Reciprocal Rank Fusion): Combines rankings using 1 / (k + rank) without requiring score normalization
  • Weighted fusion: Weights inverse-rank scores by explicit weights

Usage

See the Hybrid search page for detailed implementation examples.

LLM configuration

All LLM-based components use the Groq API via Haystack’s OpenAIChatGenerator:
Set the GROQ_API_KEY environment variable or pass api_key directly.

When to use components directly

  • Building a custom pipeline that does not fit existing feature module templates
  • Experimenting with one pipeline stage at a time
  • Combining components from different feature modules into a novel configuration

Common pitfalls

Over-composing before baseline validation: Build and validate the simplest pipeline first. Add components incrementally and measure the impact of each addition.
Inconsistent interfaces between custom stages: If you extend these components, maintain the same input/output conventions (Haystack Document objects, standard config dicts).
No tracing at component boundaries: Each component logs at INFO level. Set LOG_LEVEL=DEBUG to see detailed prompt and response content.

Next steps

Pipelines

Learn how to compose components into full pipelines

Semantic search

See components in action in semantic search pipelines