Skip to main content

Reranker Module

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

Import

Quick Example

Wrapper entry points (praisonai.run, praisonai.arun, and the praisonai CLI) call register_default_adapters() for you before the agent starts, so reranker: llm (etc.) works from YAML/CLI without any Python setup. Call it explicitly only when using reranker classes directly from your own Python code (PraisonAI 4.7.9+). 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