Ultralytics YOLO27: Join the waitlist.
License YOLO
Back to Ultralytics Glossary

Reranker

A reranker re-scores a retriever's shortlist with a slower, more accurate model, such as a cross-encoder, before results reach a user or an LLM.

A reranker is a model that takes a short list of candidates from a fast first-stage retriever, scores each candidate against the query more carefully, and reorders the list. Search engines, retrieval-augmented generation (RAG) pipelines, and recommendation systems use the pattern because the most accurate relevance models are too slow to run over millions of documents but fast enough for the top few dozen to few hundred. In text search the standard reranker is a cross-encoder, a transformer that reads the query and one candidate together and outputs a single relevance score. Nogueira and Cho (2019) fine-tuned BERT this way and topped the MS MARCO passage ranking leaderboard with an MRR@10 27% higher, in relative terms, than the previous best.

How Retrieve-then-Rerank Works#

The first stage favors recall: keyword matching with BM25, vector search over precomputed embeddings, or both, pulls a few hundred plausible candidates from the whole collection in milliseconds. The reranker favors precision: it spends a full model pass on every query-candidate pair, and only its top few results go to the user or into an LLM's context window. The Ultralytics VisualAISearch solution is a first-stage retriever of this kind, embedding a folder of images with CLIP ViT-B/32, ranking them by cosine similarity to a text query, and returning up to 30 matches above a 0.1 similarity threshold by default.

Cross-Encoders and Bi-Encoders#

A bi-encoder, the usual retriever, embeds the query and each document separately, so document vectors can be computed once and stored in a vector database. That independence is also its limit: the document vector is fixed before the query is known. A cross-encoder concatenates query and document into one input, so self-attention can compare every query word with every document word, at the cost of a full forward pass for every pair at query time. ColBERT sits between the two, storing one vector per document token and matching query tokens against them with late interaction. The Sentence Transformers CrossEncoder class runs a reranker such as ms-marco-MiniLM-L6-v2, trained on MS MARCO search queries:

from sentence_transformers import CrossEncoder

query = "When was the transformer architecture introduced?"
# Shortlist returned by a fast first-stage retriever, in its original order
candidates = [
    "Transformer models such as GPT and BERT are widely used in natural language processing.",
    "An electrical transformer changes the voltage of an alternating current.",
    "Convolutional neural networks became popular after AlexNet won ImageNet in 2012.",
    "The transformer was introduced in the 2017 paper Attention Is All You Need.",
]

# The cross-encoder reads the query and each candidate together and scores their relevance
reranker = CrossEncoder("cross-encoder/ms-marco-MiniLM-L6-v2")
ranked = reranker.rank(query, candidates)

for hit in ranked:
    print(f"{hit['score']:6.2f}  {candidates[hit['corpus_id']]}")

The passage that answers the question moves from last place to first with a score of 6.97, far ahead of the next candidate at -4.48. The electrical transformer sentence shares the query's key word but scores -5.29.

Types of Rerankers#

  • Cross-encoders: Compact transformers fine-tuned on relevance labels, such as the MS MARCO MiniLM models and BAAI's bge-reranker family, also offered as hosted reranking APIs.
  • LLM rerankers: A large language model (LLM) is prompted to score candidates or sort a whole list at once. RankGPT showed that ChatGPT and GPT-4 can rerank passages by writing out a sorted list, and distilled ChatGPT's rankings into a small dedicated reranker.
  • Learning-to-rank models: Recommendation and e-commerce systems rerank candidates with models such as gradient-boosted trees over features like click history, price, and freshness, trained with ranking objectives such as LambdaMART, available in LightGBM and XGBoost.
  • Semantic search: Search by meaning, usually with a bi-encoder retriever. A reranker is an optional second stage on top of it.
  • Hybrid search: Merges keyword and vector result lists, often with reciprocal rank fusion, which combines ranks without reading the content again. A reranker often runs on the merged list.
  • Knowledge distillation: Trains a fast retriever to imitate a slow reranker's scores, moving some reranking quality into the first stage.
  • Two-stage object detectors: Follow the same pattern for images, with a region proposal stage suggesting candidate boxes and a second stage re-scoring and refining each one before non-maximum suppression (NMS) removes overlapping duplicates.

Explore solutions

Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Turn drone and aerial imagery into real-time insights for agriculture, aquaculture, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Apply computer vision in aerospace with Ultralytics YOLO for aircraft inspection, runway FOD detection, airport ground operations, and composite defect detection.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more

Let's build the future of AI together!

Begin your journey with the future of machine learning