# Reranking

> The Reranking is a technique of reordering retrieved results with a more accurate model to put the most relevant first.

## What is reranking in RAG?

The second step of retrieval where a specialized model scores the found candidates against the query and reorders them. Only the best results are passed to the LLM, which improves answers and saves tokens.

- Topic: Retrieval
- Type: technique

## Example

Wrong:

```js
const hits = await search(query, { limit: 5 });
const top = await rerank(query, hits);
```

Right:

```js
const candidates = await search(query, { limit: 50 });
const scored = await rerank(query, candidates);
const top = scored.slice(0, 5);
```

Fetching more candidates first gives the reranker a real chance to find the best five.

## Common mistakes

- Reranking too few candidates, so the right document never gets a chance.

## Key points

- The first search returns more candidates than are finally sent to the model.
- The reranker scores each candidate against the query, and only the top results are kept.
- The number of candidates is limited to keep latency acceptable.

## Interview questions

### What is a cross-encoder reranker?

A model that reads the query and a document together and outputs one relevance score. It is more accurate than comparing separate embeddings, but slower.

### How many candidates should I rerank?

Often a few dozen. More can raise recall but adds latency, so measure on your own queries.

### Can an LLM be used as a reranker?

Yes. A language model can score or order candidates, but it is usually slower and costlier than a dedicated reranking model.

## Related cards

- [RAG](https://wonderium.dev/ai/rag.md)
- [Hybrid Search](https://wonderium.dev/ai/hybrid-search.md)
- [Semantic Search](https://wonderium.dev/ai/semantic-search.md)
- [Latency](https://wonderium.dev/ai/latency.md)

---

- Level: [Artificial Intelligence](https://wonderium.dev/ai.md)
- HTML version: https://wonderium.dev/ai/reranking
- Last updated: 2026-11-25
