Reranker Module
The Reranker module provides concrete implementations for reranking search results to improve relevance.Import
Quick Example
Features
- LLM-based relevance scoring with any model
- Cross-encoder neural reranking
- Cohere Rerank API integration
- Batch processing for efficiency
- Async support
Classes
LLMReranker
Uses an LLM to score document relevance to a query.
How it works:
- Prompts the LLM to rate relevance on a 0-10 scale
- Normalizes scores to 0-1 range
- Sorts by score descending
CrossEncoderReranker
Uses sentence-transformers cross-encoder for accurate relevance scoring.
Requires
sentence-transformers package: pip install sentence-transformersCohereReranker
Uses Cohere’s rerank API for high-quality reranking.
Requires
cohere package: pip install cohereMethods
rerank(query, documents, top_k=None)
Rerank documents by relevance to query.
Parameters:
query(str): Search querydocuments(List[str]): Documents to reranktop_k(int, optional): Number of results to return
List[RerankResult] - Reranked documents with scores
arerank(query, documents, top_k=None)
Async version of rerank (calls sync internally).
Example: Full RAG Pipeline
Example: Using with Agent
Reranker Selection Guide
Environment Variables
CLI Usage
Related
- Retrieval Module - Retrieve documents
- Vector Store Module - Store documents

