AgenticRouter
Route queries to search, reflect, or generate actions using LLM reasoning for agentic RAG patterns.Constructor
ChatGroq LLM instance for routing decisions. Should be configured with low temperature (0.0-0.3) for consistent routing
Methods
route
Route a query to the appropriate action based on current pipeline state.The user’s original query text
Indicates whether documents have already been retrieved in previous iterations
The answer generated so far, if any. Used to assess whether reflection or generation is appropriate
Current iteration number (1-indexed). Used to track progress and enforce iteration limits
Maximum number of routing iterations allowed. Prevents infinite loops
One of ‘search’, ‘reflect’, or ‘generate’
Human-readable explanation of the routing decision
ContextCompressor
Compress retrieved context using reranking or LLM-based extraction to reduce token usage.Constructor
Compression mode: “reranking” or “llm_extraction”
ChatGroq instance for LLM extraction mode. Required when mode is “llm_extraction”
HuggingFaceCrossEncoder instance for reranking mode. Required when mode is “reranking”
Methods
compress
Compress documents using the configured compression strategy.The user’s query text. Used to determine relevance
List of LangChain Document objects to compress
Number of documents to return (only used in reranking mode)
Compressed list of documents. Structure depends on mode:
- reranking: List of top_k Document objects, sorted by relevance
- llm_extraction: List containing single synthesized Document
compress_reranking
Compress documents using cross-encoder reranking.Query text for relevance scoring
Documents to rerank
Number of top documents to return
Top-k documents sorted by relevance score (highest first)
compress_llm_extraction
Compress documents using LLM-based passage extraction.Query text to guide extraction
Documents to extract from
List containing a single Document with extracted passages. Metadata includes ‘source’: ‘compressed’ and ‘original_doc_count’
QueryEnhancer
Enhance queries using multi-query generation, HyDE (Hypothetical Document Embeddings), and step-back techniques.Constructor
ChatGroq LLM instance for query enhancement
Methods
generate_multi_queries
Generate multiple query variations for better retrieval coverage.Original query
Number of query variations to generate
List of query variations including the original query
generate_hyde_document
Generate a hypothetical document that would answer the query.Query to generate hypothetical document for
Hypothetical document text that can be embedded and used for retrieval
generate_step_back_query
Generate a step-back query that asks a more general question.Specific query to generalize
More general query useful for retrieving background context
MMRHelper
Maximal Marginal Relevance utilities for diversity-optimized retrieval.Methods
mmr_rerank
Rerank documents using MMR algorithm to balance relevance and diversity.Documents to rerank
Document embeddings corresponding to documents list
Query embedding vector
Number of documents to return
Balance parameter between relevance (1.0) and diversity (0.0). Default 0.5 balances both
Reranked documents optimized for relevance and diversity