# Reranking

> Reranking is a second retrieval step in which a more precise model rescores the top results from a first, faster search and reorders them by relevance to the query, so the best passages reach the user or language model first.

Also called: re-ranking, reranker, cross-encoder, second-stage retrieval. Category: Data and retrieval. Source: https://aibuildindex.com/glossary/reranking

## In the index

- Search over internal documents: median $2,150, middle half $300 to $8,800, 918 priced briefs (https://aibuildindex.com/cost/document-search-rag)
- RAG: median $3,860, middle half $500 to $14,400, 586 priced briefs (https://aibuildindex.com/skills/rag)

A fast search over thousands or millions of passages has to cut corners to return results in milliseconds. Reranking adds a second, slower but more careful pass over just the top candidates, typically the first few dozen, and puts them in a better order. In a [RAG](https://aibuildindex.com/glossary/retrieval-augmented-generation) system, where only a handful of passages are passed to the model, getting the right passage into that handful is often the single largest improvement in answer quality.

## How it works

First-stage retrieval, whether keyword, semantic or [hybrid search](https://aibuildindex.com/glossary/hybrid-search), compares the query with pre-computed representations of each document. It never reads the query and passage together. A reranker does: it takes each query and passage pair and scores how well the passage answers the query. The common design is a cross-encoder model trained for exactly this task, offered by several providers as an API and available as open models. Some builds use a general language model as the reranker instead, which is more flexible but slower and costlier.

An example: an employee asks "Can I carry unused leave into next year?". The first search returns twenty passages about leave, including policies on sick leave and parental leave. The reranker reads each one against the question and moves the paragraph on carry-over to the top, so the model answering the question sees it first.

## What it means for cost

Reranking is usually a modest addition to a retrieval build: one extra API call or model per query and some tuning of how many candidates to rerank. It adds [latency](https://aibuildindex.com/glossary/latency), since every candidate has to be scored, and a per-query running cost when a hosted reranker is used. In return it often allows fewer passages to be sent to the language model, which can lower generation costs.

Ask a builder whether reranking is included, how many candidates are rescored, and what measured difference it made on a test set of real questions; see [evals](https://aibuildindex.com/glossary/evals). If the retrieval results are already good on that test set, reranking may not be needed. Live figures are on the [document search and RAG cost page](https://aibuildindex.com/cost/document-search-rag).

## Common questions

### Why not use the reranker for the whole search?

Because it is too slow. A reranker reads every query and passage pair together, which is fine for fifty candidates and impractical for a million. The fast first stage narrows the field, and the reranker sorts the shortlist.

### Does reranking help if retrieval misses the right passage?

No. Reranking can only reorder what the first stage returns. If the correct passage is not among the candidates, the fix lies earlier, in [chunking](https://aibuildindex.com/glossary/chunking), the embedding model or adding keyword search.

## Related terms

- [Semantic search](https://aibuildindex.com/glossary/semantic-search): Semantic search is search that matches by meaning rather than exact words, typically by comparing embeddings, so a query such as "how do I get my money back" can find a page titled "Refund policy".
- [Hybrid search](https://aibuildindex.com/glossary/hybrid-search): Hybrid search combines keyword search and semantic vector search in one query and merges their results, so a system finds both exact matches such as product codes and passages that match by meaning.
- [Retrieval-augmented generation (RAG)](https://aibuildindex.com/glossary/retrieval-augmented-generation): Retrieval-augmented generation is a way of answering questions with a language model that first looks up relevant passages in your own documents, then writes an answer grounded in what it found.
- [Vector database](https://aibuildindex.com/glossary/vector-database): A vector database is a data store built to save embeddings, the numeric representations of text, images or audio, and to find the stored items most similar in meaning to a query, which makes it the usual search layer behind RAG systems.
- [Latency](https://aibuildindex.com/glossary/latency): Latency is the delay between sending a request to an AI system and receiving its response, which determines whether a feature feels instant, acceptable or too slow for its users.
- [Evals (AI evaluation)](https://aibuildindex.com/glossary/evals): Evals are structured tests that measure how well an AI system performs on a fixed set of realistic inputs, scoring its outputs so that changes to prompts, models or data can be judged by evidence rather than impression.
