Skip to main content

Reranker Module

The Reranker module provides concrete implementations for reranking search results to improve relevance.

Import

Quick Example

For reranker registry lookups, call register_default_adapters() once at startup — importing reranker classes no longer auto-registers them (PraisonAI 4.6.156+). See Registering the built-in adapters.

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.
Parameters: How it works:
  1. Prompts the LLM to rate relevance on a 0-10 scale
  2. Normalizes scores to 0-1 range
  3. Sorts by score descending

CrossEncoderReranker

Uses sentence-transformers cross-encoder for accurate relevance scoring.
Parameters:
Requires sentence-transformers package: pip install sentence-transformers

CohereReranker

Uses Cohere’s rerank API for high-quality reranking.
Parameters:
Requires cohere package: pip install cohere

Methods

rerank(query, documents, top_k=None)

Rerank documents by relevance to query. Parameters:
  • query (str): Search query
  • documents (List[str]): Documents to rerank
  • top_k (int, optional): Number of results to return
Returns: List[RerankResult] - Reranked documents with scores

arerank(query, documents, top_k=None)

Async reranking that offloads the blocking body via asyncio.to_thread(...), so calling it from an event loop no longer freezes it. Authors of custom rerankers on a natively-async provider should override arerank and await the native call directly — see Native async in custom retrievers / rerankers.

Example: Full RAG Pipeline

Example: Using with Agent

Reranker Selection Guide

Environment Variables

CLI Usage