Retrieval & RAGPatternProven

Reranking

Also called: cross-encoder reranking, two-stage retrieval

Reranking retrieves a generous set of candidates cheaply, then reorders them with a slower, more accurate model before any of it reaches the context. It buys precision at the top of the list without paying that cost across the whole corpus.

James Phoenix
Understanding Data Updated July 26, 2026

Vector search is fast because it compares pre-computed embeddings. The document and the query are embedded separately and never seen together, which is exactly why it is quick and also why it is imprecise: nothing ever read the query and the passage side by side.

Reranking adds a second stage that does. Retrieve 50 candidates cheaply, then score each one against the query with a model that reads both, and keep the best 5.

The shape

TypeScript
// stage 1: cheap and generous
const candidates = await vectorSearch(query, { limit: 50 })

// stage 2: expensive and accurate, on 50 items rather than 50,000
const scored = await rerank(query, candidates)   // reads query + passage together
const context = scored.slice(0, 5)

The economics only work because stage 2 runs on a shortlist. A cross-encoder over your entire corpus would be unaffordable; over 50 candidates it is a rounding error.

Why it matters more than it sounds

  • Recall and precision are different problems. Stage 1 optimises for not missing anything. Stage 2 optimises for putting the right thing first. Trying to do both in one step gets you neither.
  • Position matters inside the window. Because of lost in the middle, the *order* you pass passages in changes the answer. Reranking is how you decide that order on purpose.
  • You can retrieve more, not less. Reranking makes a wide stage-1 net safe, which is what makes hybrid search practical.

Choosing the cut

Two numbers to tune: how many candidates you fetch, and how many survive. Fetching more improves the ceiling on quality and costs stage-2 latency. Keeping more fills the window with lower-confidence material. The common failure is keeping too many because the window has room, which pushes your best passage into the middle where the model attends to it least.

Note
An LLM can serve as the reranker: ask it to score each passage's relevance from 0 to 10 and sort. It is slower and pricier than a purpose-built cross-encoder, but it needs no extra infrastructure and is a reasonable first version. This is the same machinery as LLM-as-judge, pointed at relevance instead of quality.

Related terms

Engineering context for real systems?

Getting the right information into the window at the right time is most of the job. If you want that thinking applied to your product, that is what I do.

See how I can help