Dev tools

Reranking in RAG: Why Retrieval Needs a Second Pass

Reranking re-scores retrieved documents so the best ones reach the LLM. Learn how cross encoder rerankers work, when to use them and how many to rerank.

By OmniAI Editorial · Nov 20, 2026 · 9 min read

Reranking is a second step in search and retrieval: after a fast first search pulls back a list of candidate documents, a slower, more accurate model re-scores those candidates and puts the best ones on top. In RAG systems, where an LLM answers questions using retrieved text, reranking is one of the most effective ways to improve answer quality, because the LLM can only use what you put in front of it.

This guide explains why the first retrieval pass isn't enough, how cross-encoder rerankers work, what reranking looks like in code, which kinds of reranker models exist, and when reranking isn't worth the extra time.

What Is Reranking?

Think of hiring. You don't interview every applicant. You first skim hundreds of CVs quickly and shortlist twenty, then interview those twenty carefully. The skim is fast but rough; the interview is slow but accurate.

Search works the same way:

  1. First pass (retrieval): a fast method, such as vector search, keyword search or both, scans the whole collection and returns, say, the top 50 candidates.
  2. Second pass (reranking): a more powerful model reads the query together with each of those 50 candidates, scores how relevant each one really is, and re-sorts them.
  3. Use the top few: only the best handful, often 3 to 10, go to the LLM or the user.

The first pass is about recall: making sure the right documents are somewhere in the shortlist. Reranking is about precision: making sure the right documents end up at the very top.

Why the First Retrieval Pass Isn't Enough

Most RAG systems retrieve with embeddings. Each document chunk is turned into a vector once, ahead of time. At query time, the question becomes a vector too, and the nearest document vectors are returned.

That's fast, but it has a built-in weakness: each document is summarised into a single vector without knowing what question will be asked. All the meaning of a paragraph is squeezed into one fixed list of numbers. Fine details get blurred, such as negations, exact numbers, or whether a passage actually answers the question or just talks about the same topic.

So vector search often returns documents that are about the right subject but don't contain the answer, ranked above the one that does. Keyword search has its own blind spots. Combining both with hybrid search improves recall, but the order of the final list can still be rough.

That matters because LLMs pay most attention to the most relevant-looking context, and you can only fit so many chunks into a prompt. If the chunk with the answer sits at position 23, the LLM never sees it.

Bi-Encoder vs Cross-Encoder

The difference between first-pass retrieval and reranking comes down to two model designs.

A bi-encoder encodes the query and each document separately into vectors, then compares the vectors. Because documents are encoded ahead of time, searching millions of them is fast. This is how embedding models work.

A cross encoder (often written cross-encoder) reads the query and one document together, as a single input, and outputs one relevance score. Because the model sees both texts at once, every word of the question can be compared directly with every word of the document. It's far more accurate, but nothing can be computed ahead of time: you have to run the model once for every query–document pair.

Bi-encoder (embedding model)Cross-encoder (reranker model)
InputQuery and document encoded separatelyQuery and document read together
OutputOne vector per textOne relevance score per pair
Pre-compute documents?Yes, stored in a vector indexNo, scored at query time
SpeedSearches millions of documents fastPractical for tens to hundreds of candidates
AccuracyGoodBetter, especially on subtle relevance
RoleFirst-pass retrievalReranking the shortlist

That's why the two are combined: the bi-encoder narrows millions of chunks down to a shortlist cheaply, and the cross-encoder spends its expensive attention only on that shortlist.

Split by a dotted divider: on the left, two grey cards each feeding its own ink arrow into separate grey circles; on the right, two grey cards side by side feeding one shared arrow into a single orange circle.
A bi-encoder handles query and document separately; a cross-encoder reads them together.

How Reranking Works in a RAG Pipeline

A typical RAG pipeline with reranking looks like this:

  1. User asks a question.
  2. Retrieve candidates: run vector search, keyword search or hybrid search and take the top 25 to 100 chunks.
  3. Rerank: score each candidate against the question with a reranker model.
  4. Keep the best: take the top 3 to 10 after reranking. Optionally drop anything below a score threshold.
  5. Generate: put those chunks into the prompt and let the LLM answer.

Reranking doesn't replace retrieval. It only re-orders what retrieval found. If the right chunk isn't in the candidate list at all, no reranker can bring it back. Our guide to what RAG is covers the rest of the pipeline.

Reranking in Code

Here's a minimal example with the open-source sentence-transformers library and a small public cross-encoder model, following the library's documentation:

from sentence_transformers import CrossEncoder

model = CrossEncoder("cross-encoder/ms-marco-MiniLM-L6-v2")

query = "How many people live in Berlin?"
candidates = [
    "Berlin is well known for its museums.",
    "Berlin had a population of 3,520,031 registered inhabitants.",
    "The city of Paris had a population of 2,165,423 people.",
]

ranks = model.rank(query, candidates)
for r in ranks:
    print(f"{r['score']:.2f}  {candidates[r['corpus_id']]}")

rank returns the candidates sorted from most to least relevant, each with a score and its position in the original list (corpus_id). In a real pipeline, candidates would be the chunks your retriever returned, and you'd keep only the first few results. Hosted reranking APIs work the same way: you send a query and a list of documents and get back relevance scores.

Types of Reranker Models

There are four main families:

  • Open-source cross-encoders: models such as the BGE reranker family from BAAI and the MS MARCO cross-encoders you can run yourself. Good when data must stay in-house or you want no per-call fees.
  • Hosted reranking APIs: services such as Cohere Rerank, Voyage AI and Jina AI offer rerankers behind an API. Easy to add, with no GPU to manage, but you pay per request and send your text to a third party.
  • Late-interaction models (ColBERT-style): a middle ground. They store one vector per token instead of one per document, which keeps more detail than a bi-encoder while staying faster than a full cross-encoder.
  • LLM rerankers: an LLM is asked to judge or sort the candidates. They can be very accurate on complex questions but are slower and more expensive than dedicated rerankers.

Reranker models are updated often, so compare current versions on your own data rather than relying on general leaderboards. Check multilingual support if your documents aren't in English, and the maximum input length: long chunks may be cut off before the reranker sees the relevant part.

An ink funnel shape, wide at the top with many small grey squares entering it and narrow at the bottom with one orange square leaving it.
Retrieval casts a wide net; reranking narrows it to the few best results.

How Many Documents Should You Rerank?

There's a trade-off. Reranking more candidates improves the chance that the right one is in the list, but every extra candidate adds latency and cost.

Practical starting points:

  • Retrieve 25 to 100 candidates for reranking, then keep 3 to 10.
  • Measure recall at your candidate depth. Using a small test set of real questions, check how often the right chunk appears in the top 25, 50 or 100 before reranking. Pick the smallest depth that usually contains it.
  • Watch latency. If reranking slows answers too much, rerank fewer candidates, use a smaller model or run the reranker on a GPU.
  • Use score thresholds carefully. Dropping low-scoring chunks reduces noise, but scores from different models aren't on the same scale, so tune the cut-off on your own data.

When Reranking Isn't Worth It

Reranking adds a model call and extra delay to every query. Skip or postpone it when:

  • Your retrieval already puts the answer in the top few results for nearly all test questions.
  • Your collection is tiny, so you could send every candidate to the LLM anyway.
  • Latency is critical, such as instant autocomplete or voice assistants with tight response budgets.
  • Retrieval itself is failing. If the right chunk isn't in the top 100, fix chunking, embeddings or add keyword search first.

For most production RAG systems, though, reranking in RAG is one of the highest-value additions you can make: a few lines of code that often noticeably improve which context the LLM sees.

FAQ

What is reranking in RAG?

Reranking in RAG is a second retrieval step. After vector or keyword search returns a list of candidate chunks, a reranker model scores how relevant each one is to the question and re-orders them. Only the top results go into the LLM's prompt, so it answers from the most relevant context.

Reranker vs embedding model: what's the difference?

An embedding model (a bi-encoder) turns the query and each document into separate vectors and compares them, which is fast enough to search millions of documents. A reranker, usually a cross encoder, reads the query and a document together and outputs a relevance score. It's more accurate but too slow to run on a whole collection, so it reranks a shortlist. In the reranker vs embedding question, the answer is to use both: embeddings to retrieve, a reranker to sort.

Does reranking improve RAG answers?

Usually, yes. Reranking pushes the chunks that actually answer the question to the top, so the LLM sees better context and is less likely to miss the answer or rely on loosely related text. It can't help if retrieval never found the right chunk.

How many documents should I rerank?

A common starting point is retrieving 25 to 100 candidates, reranking them, and keeping the top 3 to 10. Test on your own questions: retrieve enough that the right chunk is usually in the candidate list, but no more than your latency budget allows.

Can an LLM be used as a reranker?

Yes. You can ask an LLM to score or sort retrieved passages by relevance. It can be very accurate, especially for complex questions, but it's slower and more expensive than a dedicated reranker model, so it's often used only on a short list.

All articles

Read next

Language

EnglishEnglish · en TürkçeTurkish · tr DeutschGerman · de العربيةArabic · ar

Account

Enter your email. We’ll send you a sign-in link and a 6-digit code. No password needed.

Sign in

Theme

Language

Show our email address

To keep spam out of our inbox, please confirm your own email first. We will send you a 6-digit code.

We send codes only to these providers: gmail.com, googlemail.com, outlook.com, hotmail.com, live.com, msn.com, proton.me, protonmail.com, pm.me, icloud.com, me.com, mac.com, yahoo.com, aol.com, gmx.de, gmx.net, web.de, t-online.de, yandex.com, omniai.blog