# rerankers

> One unified Python API for every reranking model

- Category: Retrieval & Knowledge (RAG) / Rerank, Search & Hybrid
- Language: Python
- Licence: Apache-2.0
- Repository: https://github.com/AnswerDotAI/rerankers
- Canonical page: https://ai-tldr.dev/tools/rerankers/

## In short

rerankers is a small Python library that gives you one consistent way to use many different reranking models. Instead of learning a separate library and input/output format for each model, you load any supported reranker with a single line and call the same rank() method on it. It sits in the Rerank, Search & Hybrid category of the Retrieval & Knowledge (RAG) tools and is open-source, written in Python and licensed Apache-2.0.

## Overview

rerankers is a small Python library that gives you one consistent way to use many different reranking models. Instead of learning a separate library and input/output format for each model, you load any supported reranker with a single line and call the same rank() method on it. It was built by @bclavie at answer.ai.

It is aimed at developers building retrieval pipelines who want to add or swap a reranking step without rewriting code. A reranker takes a query and a list of candidate documents (usually returned by a first-stage retriever) and reorders them by relevance, which is a common second stage in RAG systems.

In the RAG and retrieval space, rerankers sits in the rerank and hybrid search layer. It supports cross-encoders, ColBERT/late-interaction models, T5 sequence-to-sequence rankers, FlashRank ONNX models, RankGPT and RankLLM, multi-modal MonoVLM models, and hosted APIs like Cohere, Jina, Pinecone, MixedBread, and Isaacus.

## What it does

- Single unified API: load any model and call ranker.rank(query, docs) regardless of the underlying architecture
- Dependency-free core install; you add only the extras for the model families you actually use
- Wide model coverage: cross-encoders, ColBERT, T5, FlashRank, RankGPT, RankLLM, LLM-layerwise, and multi-modal MonoVLM rankers
- API reranker support for Cohere, Jina, Pinecone, MixedBread, and Isaacus
- Returns a structured RankedResults object with per-document score and rank
- Extensible: add a new reranker as a class with a rank() method mapping (query, documents) to RankedResults

## Getting started

Install the core package, add the extra for the model family you want, then load a reranker and rank documents against a query.

1. Install the core package

   The core package ships with no dependencies. Install the extra that matches the models you plan to use; the transformers extra covers cross-encoders, T5, and ColBERT.

```bash
# Core only
pip install rerankers

# Cross-encoders, T5, ColBERT
pip install "rerankers[transformers]"

# Everything
pip install "rerankers[all]"
```

2. Load a reranker

   Use the Reranker factory to load any supported model in one line. Passing model_type is optional but safer than relying on name inference.

```python
from rerankers import Reranker

# Default cross-encoder
ranker = Reranker('cross-encoder')

# Or a specific model
ranker = Reranker('mixedbread-ai/mxbai-rerank-large-v1', model_type='cross-encoder')
```

3. Rank documents

   Call rank() with a query and a list of documents. It returns a RankedResults object with each document's score and rank.

```python
results = ranker.rank(
    query="I love you",
    docs=["I hate you", "I really like you"],
    doc_ids=[0, 1],
)
print(results)
```

## When to use it

- Adding a second-stage reranker to a RAG pipeline to reorder candidates from a vector or keyword search
- Benchmarking different reranking models (cross-encoder vs. ColBERT vs. an API reranker) behind the same code
- Running fast CPU reranking with FlashRank ONNX models when you cannot use a GPU
- Calling a hosted reranking API such as Cohere, Jina, or Pinecone through a consistent local interface
