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.
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.
# Core only
pip install rerankers
# Cross-encoders, T5, ColBERT
pip install "rerankers[transformers]"
# Everything
pip install "rerankers[all]"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.
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')Rank documents
Call rank() with a query and a list of documents. It returns a RankedResults object with each document's score and rank.
results = ranker.rank(
query="I love you",
docs=["I hate you", "I really like you"],
doc_ids=[0, 1],
)
print(results)Commands and code are distilled from the project's own documentation — always check the official repo for the latest.
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
How rerankers compares
rerankers alongside other open-source rerank, search & hybrid tools AI/TLDR tracks, ranked by GitHub stars.
| Tool | Stars | What it does |
|---|---|---|
| Elasticsearch | ★ 77.6k | Distributed search and analytics engine with a built-in vector database for dense/sparse embeddings and hybrid keyword-plus-semantic retrieval. |
| Meilisearch Cloud | ★ 58.7k | Managed cloud for the Meilisearch engine, combining fast full-text search with hybrid, semantic, and multimodal vector search. |
| Typesense Cloud | ★ 26.4k | Managed hosting for the Typesense search engine, offering typo-tolerant keyword search plus vector and semantic search via a simple API. |
| Tantivy | ★ 15.6k | A fast full-text search engine library in Rust that provides BM25 keyword search for the lexical half of hybrid retrieval. |
| FlagEmbedding | ★ 12k | BAAI's retrieval toolkit that provides the BGE embedding and cross-encoder reranker models used widely in RAG pipelines. |
| Vespa | ★ 7k | A search and serving engine that natively combines vector, keyword (BM25), and structured search with built-in ranking for large-scale retrieval. |
| RAGatouille | ★ 3.9k | A wrapper that makes it easy to train and use ColBERT late-interaction retrieval inside RAG pipelines. |
| rerankers | ★ 1.6k | One unified Python API for every reranking model |