New Tool Radar

AI Concepts

How to Rerank RAG Candidates with a Cross-Encoder

Add a cross-encoder reranker after retrieval, so the chunks that reach the model are ordered by real relevance, not by embedding distance.

Schematic illustration with three step boxes: retrieve a wide pool, score each pair, and send the top few.

A bi-encoder, the kind behind vector search, compresses each document into one vector without seeing the question. A cross-encoder takes the question and one candidate together, joined into a single input, so every word of the question can attend to every word of the candidate. That is far more accurate and far too slow to run over a whole corpus, which is why it belongs in stage two, over 50 to 100 candidates, not stage one.

Before you start

A cross-encoder reranker model, such as a Sentence Transformers cross-encoder, and a retriever that can return 50 to 100 candidates.

Retrieve a wide candidate pool

Ask your retriever for 50 to 100 candidates, not 5. The first stage buys recall cheaply; the reranker buys precision over the small set. If the right chunk is not in the pool, no reranker can find it.

Use hybrid retrieval for the pool if you have it: BM25 plus vector search catches both exact terms and paraphrases.

Score each question-candidate pair

Send the question together with each candidate to the cross-encoder and record the score. Do not reuse the vector similarity: the cross-encoder score replaces it.

Keep the pool small enough that scoring stays fast. Scoring 60 candidates costs milliseconds per query in most setups; scoring thousands does not.

Send only the top few to the model

Take the top 5 to 10 reranked chunks into the prompt. Log the before and after order for a few queries and check that chunks which merely mention the topic drop below chunks that answer the question.

If the top chunk after reranking is still wrong, the problem is the pool, not the reranker: widen the pool or fix the first stage.

Practice check: fictional Maple Corner query: exchange without receipt

The table below is fictional practice material, worked out by hand from the stated ranks. It is the expected result for the practice query, not a run of any reranker.

Chunk Vector rank Reranked rank Verdict
Exchange policy, receipt section 4 1 Pass – now first
Receipt printing guide 1 2 Pass – demoted correctly
Gift receipt FAQ 2 4 Pass – demoted correctly
Store locations page 3 5 Pass – demoted correctly

The receipt printing guide won vector search by mentioning receipts often, but the reranker puts the exchange policy first because it answers the question. The pool held the right chunk; only the order was wrong.

Expected result. UNTESTED: the ranks in the practice table are worked out by hand, not measured by running a reranker. Retrieve a 60-candidate pool for your own query, rerank it, and check whether the chunk that answers the question moves into the top 3.

Limits

  • A reranker adds latency and one more model to run; measure it before you add it to every query.
  • Cross-encoders score pairs, so they cannot search a corpus directly and must sit behind a first-stage retriever.

Sources

See all