Cross-Encoder Reranking: The Second Pass That Fixes Retrieval

Cross-Encoder Reranking: The Second Pass That Fixes Retrieval

Cross-encoder reranking is the second pass that turns a good retrieval result into a great one. A fast retriever first pulls a shortlist of candidate passages, then a cross-encoder reads each query-passage pair together and scores how well they match. The short answer to why this works is that the cross-encoder sees the query and the passage at the same time, so it can judge relevance in a way a retriever that encodes them separately never can.

The idea became standard after researchers applied BERT to passage ranking in 2019, notably in the work of Nogueira and Cho on passage reranking with BERT, and after Reimers and Gurevych’s Sentence-BERT paper the same year made the bi-encoder versus cross-encoder trade-off explicit. Their paper showed that finding the most similar pair among 10,000 sentences took about 65 hours with a BERT cross-encoder but only about 5 seconds with a bi-encoder. That gap is the whole reason the two-stage pipeline exists.

Key takeaways

  • A cross-encoder scores a query and a passage together, with full attention between them.
  • It is more accurate than a bi-encoder but far too slow to search a whole collection.
  • Use it as a second stage: a fast retriever shortlists candidates, the cross-encoder reranks them.
  • Reranking a shortlist of 20 to 100 passages is the usual setup in production RAG.
  • Choose the reranking depth by measuring quality against latency, not by guessing.

How cross-encoder reranking works

A cross-encoder takes the query and one candidate passage, joins them into a single input, typically in the form [CLS] query [SEP] passage [SEP], and passes the whole thing through a transformer. Every token in the query can attend to every token in the passage at every layer. The model then reads a single relevance score from the [CLS] representation.

That joint attention is the key difference from a bi-encoder. A bi-encoder compresses the query and the passage into separate vectors before they ever meet, so any detail that does not survive compression is lost. A cross-encoder never compresses either side in isolation; it compares them in full, token by token, in context.

The price is that the document side cannot be precomputed. Because the encoding of a passage depends on the query it is paired with, every candidate needs a fresh forward pass at query time. That is why cross-encoders are rerankers, not retrievers.

Best for: final ranking quality in RAG, search and question answering, where the top few passages decide the answer.

Why joint attention is more accurate

Joint attention lets the model resolve ambiguity using the other side of the pair. The word “charge” means one thing next to “battery” and another next to “credit card”, and a cross-encoder can use the query to decide which sense the passage intends. A bi-encoder must decide the meaning of each side before seeing the other, which is a harder job.

Joint attention also catches subtle mismatches. A passage may be broadly about the right topic but answer a different question, or it may contain the query’s words in a context that reverses their meaning, such as a passage explaining why a treatment does not work. A cross-encoder can spot those cases; a vector similarity score often cannot.

The Sentence-BERT paper, available at arXiv:1908.10084, sets out this trade-off clearly and remains the best reference for understanding why the two architectures exist side by side.

The two-stage pipeline

The standard pipeline has two stages. Stage one is retrieval: a fast method such as BM25, a bi-encoder or a hybrid of the two returns a shortlist, usually the top 20 to 100 passages. Stage two is reranking: the cross-encoder scores each pair and reorders the list.

Only the top few reranked passages reach the language model, so the quality of the reranking directly shapes the final answer. A strong first stage matters too, because the reranker can only reorder what it is given. If the right passage never makes the shortlist, no reranker can rescue it. That is why retrieval recall at the reranking depth is the metric to watch.

Cross-encoder reranking vs bi-encoder retrieval

Bi-encoders and cross-encoders solve different halves of the problem. The bi-encoder is fast and scalable, because document vectors are computed once and searched with approximate nearest-neighbour indexes. The cross-encoder is accurate, because it compares the pair directly. Neither can do the other’s job.

The practical consequence is that you need both. A system with only a bi-encoder will return passages that are broadly similar but not precisely relevant. A system with only a cross-encoder cannot search a collection of any size, because it would need a forward pass for every document on every query.

ColBERT sits between the two, keeping token-level vectors and comparing them late. Our guide to ColBERT retrieval explains that middle ground, and our comparison of dense retrieval vs sparse retrieval covers the first stage in more depth.

Dimension Bi-encoder retrieval Cross-encoder reranking
Input Query and document encoded separately Query and document encoded together
Attention None between query and document Full cross-attention at every layer
Document precomputation Yes, vectors stored once No, depends on the query
Speed at query time One encoding plus fast lookup One forward pass per candidate
Accuracy Good Higher, especially on close calls
Scales to Millions of documents Dozens to hundreds of candidates
Typical role First-stage retrieval Second-stage reranking

Choosing a reranking model

Most teams start with an established open model rather than training their own. The cross-encoder family based on MiniLM, fine-tuned on the MS MARCO passage ranking dataset, is a common starting point: small, fast and widely used. Larger models based on DeBERTa or similar encoders score higher but cost more latency per candidate.

Multilingual rerankers, such as the BGE reranker family, are worth considering when your collection spans languages. They are trained to score pairs across languages, which a model trained only on English cannot do reliably.

Best for: teams that want a proven reranker without training one; start with a small public model and measure before moving to a larger one.

Fine-tuning a reranker on your data

A public reranker trained on general web passages may not match your domain. If your documents use specialised terminology or your queries follow a particular pattern, fine-tuning on your own labelled pairs can help. The training data is triples of a query, a relevant passage and a hard negative, meaning a passage that looks relevant but is not.

Hard negatives matter more than the positives. A model trained only on easy negatives, random passages, will not learn to distinguish close calls. Mine hard negatives from your own retriever’s mistakes: passages it ranked highly that annotators judged irrelevant. Those are the examples that teach the model what your domain’s traps look like.

Fine-tuning is optional. Many teams never do it, because a public model is good enough once the first stage is strong. Fine-tune only when you can show that the public model’s errors follow a pattern your data could fix.

A checklist on paper with a pen and a laptop keyboard behind it
Reranking is a shortlist exercise: the cross-encoder only ever sees the candidates the first stage chose.

How deep should reranking go?

Reranking depth is the number of candidates the cross-encoder scores. Deeper means more chances to find the right passage, but also more latency and more compute per query. Common depths are 20, 50 and 100, and the right choice depends on your first stage and your latency budget.

The way to choose is to measure. Fix your first stage, then rerank at several depths and measure the quality of the top passages that reach the generator. Quality usually improves quickly up to a point and then flattens, while latency keeps growing linearly. The knee of that curve is your depth.

Latency and cost in production

Cross-encoder cost scales with candidates times passage length. Longer passages cost more, because the transformer processes more tokens per pair. Shorter chunks therefore make reranking cheaper as well as more focused, which is another reason to keep chunks tight.

Batching helps. Scoring candidates one at a time wastes the parallelism a GPU offers; batching the shortlist into a single call is much faster. Caching helps too, though less than in retrieval, because the score depends on the query and the cache hit rate for exact query-passage pairs is low.

For latency-sensitive systems, a small reranker over 50 candidates often beats a large reranker over 20. Measure both configurations on your own queries rather than assuming bigger is better.

Setting up cross-encoder reranking in RAG

A typical RAG setup retrieves the top 50 passages with a hybrid retriever, reranks them with a cross-encoder, and passes the top five to the language model. That pipeline is simple to build with standard libraries, and it is the configuration most teams should start from.

Monitor the pipeline at each stage. Log the first-stage recall, the reranker’s effect on the top five, and the generator’s use of the passages. When answers go wrong, check whether the right passage was retrieved, whether the reranker promoted it, and whether the generator used it. Each failure points to a different fix.

Our guide to RAG reranking models covers the wider set of second-stage options, and RAG retrieval latency explains where the time goes across the whole pipeline.

Setup checklist

  • Pick a first-stage retriever and measure its recall at your reranking depth.
  • Start with a small public cross-encoder, such as a MiniLM model fine-tuned on MS MARCO.
  • Rerank 50 candidates to begin with, then test 20 and 100 and compare quality and latency.
  • Batch the shortlist into as few model calls as possible.
  • Pass only the top reranked passages to the generator; do not pass the whole shortlist.
  • Log stage-by-stage results so failures can be traced to retrieval, reranking or generation.
  • Revisit the setup when your documents, queries or latency budget change.

Common mistakes to avoid

The most common mistake is reranking too few candidates. If the first stage is weak, the right passage may sit at rank 40, and reranking only the top 10 will never find it. Depth is cheap compared with a wrong answer, so err on the side of a deeper shortlist until measurements say otherwise.

The second mistake is judging the reranker by the generator’s answers. A good generator can answer from its own knowledge when retrieval fails, hiding the problem. Measure the reranker’s effect on the ranking itself, with labelled relevance data.

Frequently asked questions

What is cross-encoder reranking?

Cross-encoder reranking is a second retrieval stage in which a transformer reads each query-passage pair together and scores their relevance. It reorders a shortlist from a fast first-stage retriever so the best passages reach the generator.

Why not use a cross-encoder for the whole search?

Because it cannot precompute document representations. Every query would need a forward pass for every document, which is far too slow for a large collection. It is practical only on a shortlist.

How many candidates should a cross-encoder rerank?

Common depths are 20 to 100. Start at 50, then measure quality and latency at other depths on your own queries and pick the point where quality stops improving.

Is a cross-encoder always better than a bi-encoder?

On ranking accuracy, usually yes, because joint attention captures finer distinctions. On speed and scalability, no. That is why the two are used together rather than one replacing the other.

Do I need to fine-tune a reranker?

Usually not at first. Public models fine-tuned on MS MARCO work well across many domains. Fine-tune only when you can show domain-specific errors that your own labelled data could fix.

What is the difference between reranking and retrieval?

Retrieval searches the whole collection and returns a shortlist; reranking reorders that shortlist. Retrieval optimises for recall, making sure the right passages are present, while reranking optimises for precision, putting the best ones first.

Latest articles

Scroll to Top