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

Available components

AgenticRouter

LLM-based decision-making for agentic RAG pipelines

ContextCompressor

LLM-based context compression for token optimization

QueryEnhancer

Multi-query, HyDE, and step-back prompting

AgenticRouter

An LLM-based decision-making component for agentic RAG pipelines. Uses ChatGroq and LangChain’s PromptTemplate for structured decision-making.

State machine

The router implements a three-state state machine:
  • search: Retrieve more documents from the vector store. Selected when no documents have been retrieved yet or when reflection identified information gaps.
  • reflect: Evaluate and improve the current answer. Selected when documents exist but the answer’s quality, completeness, or grounding is uncertain.
  • generate: Produce the final answer. Selected when sufficient information has been gathered or when max_iterations is reached (forced fallback).

Implementation

src/vectordb/langchain/components/agentic_router.py

Usage

QueryEnhancer

Generates improved retrieval queries from the user’s original input using ChatGroq and PromptTemplate.

Strategies

Generates 5 alternative phrasings of the original query. Returns a list of up to 5 query strings. The original query is NOT included.Best for: Simple factual queries where different phrasings might match different documents.
Generates a hypothetical 2-3 sentence document answer. Returns [original_query, hypothetical_answer].Best for: Very short queries or when query/document distributions differ significantly.
Generates 3 broader context questions. Returns [step_back_1, step_back_2, step_back_3, original_query].Best for: Complex questions requiring background knowledge.

Implementation

src/vectordb/langchain/components/query_enhancer.py

Usage

LLM configuration

All LangChain components use ChatGroq from langchain-groq. Recommended settings:
Set the GROQ_API_KEY environment variable or pass api_key directly to ChatGroq.

When to use components directly

  • When building a custom pipeline that does not match the existing feature module templates
  • When experimenting with one pipeline stage (testing different compression strategies with a fixed retriever)
  • When combining components from different feature modules into a custom pipeline

Common pitfalls

Over-composing before baseline validation: Build and validate the simplest pipeline first, then add components.
Inconsistent LLM temperature: Use low temperature (0.0) for routing decisions and higher (0.3-0.7) for creative tasks like query generation.
Not logging routing decisions: All components log at INFO level. Set LOG_LEVEL=DEBUG to see full prompts and responses for debugging routing and compression behavior.

Next steps

Agentic RAG

See AgenticRouter in action with the full agentic RAG pipeline

Semantic search

Build your first semantic search pipeline

Hybrid search

Combine dense and sparse retrieval with ResultMerger