Shaf Lab

Reranking

A second, more accurate scoring pass that reorders a shortlist of retrieved results.

Reranking is a second pass over a shortlist of retrieved results. A first stage, keyword search, vector search, or both, cheaply narrows a large corpus to a few dozen candidates. A slower, more accurate model then scores each candidate against the query and reorders them, and only the top few go on to the language model.

The idea is a funnel that spends compute where it matters. The first stage must be fast over millions of items, so it compares precomputed representations and accepts some coarseness. The reranker only sees perhaps 20 to 100 candidates, so it can afford to read the query and each passage together, which is far more precise. Most rerankers are cross-encoders; some systems use a language model as the reranker instead.

Rerankers improve precision at the top of the list, not recall. If the right passage never made the shortlist, no reranker can recover it, so tune the first stage to cast a wide enough net. Watch the added latency too: reranking 50 passages on every query adds a real step to each request, and it is worth batching and capping the shortlist size.

Add a reranker when your retrieval finds the right material but in the wrong order, which shows up as the correct passage sitting at rank 8 instead of rank 1. Measure the top-k hit rate before and after on real questions; if it does not move, skip the extra stage.

Bi-encoder

A model that encodes queries and documents into separate vectors, so documents can be embedded ahead of time.

A bi-encoder turns the query and each document into separate vectors with the same or paired encoders, then compares them with a similarity measure such as cosine similarity. Document vectors can be computed once and stored in an index, so query time only requires embedding the query and running a fast vector search. Embedding models used for vector search are bi-encoders.

The speed comes from independence, and so does the weakness. The query and document never see each other inside the model, so all the nuance of a long passage must be compressed into one vector before the query is known. That makes bi-encoders excellent for narrowing millions of documents to a shortlist, and less precise than cross-encoders for ordering that shortlist.

Cross-encoder

A model that reads a query and a document together and outputs a single relevance score.

A cross-encoder reads a query and one document together as a single input and outputs one relevance score. Because attention runs across both texts at once, the model can match specific words in the query to specific passages in the document, which makes it markedly more accurate at judging relevance than a bi-encoder.

Nothing can be precomputed, because each score depends on the pair. The model must run once for every query and candidate, so it is too slow to search a whole corpus but well suited to reranking a few dozen candidates. Most dedicated reranking models are cross-encoders.