# Cross-Encoder vs Bi-Encoder Rerankers?

> Cross-encoders and bi-encoders explained for beginners: how each reads a question and a chunk, and why teams rerank a shortlist, for your AI interview.

**In short:** A bi-encoder turns the question and each document into separate vectors, so it can search a huge library fast. A cross-encoder reads the question and one document together and scores them more carefully, but it is too slow for everything, so it reranks a short list.

AI and LLM interview question Q126, Retrieval-augmented generation (RAG). Intermediate, very common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/cross-encoder-vs-bi-encoder-rerankers

## Say it in 30 seconds

A bi-encoder turns the question and each chunk into vectors separately. The chunk vectors are stored ahead of time, so search stays fast over millions of chunks. A cross-encoder reads the question and one chunk together. It is more accurate, but it runs once per pair, so I only use it to rerank the top hundred results. Search finds the candidates, and the reranker puts the best ones first.

## Say it in 2 minutes

Search for an AI assistant usually has two steps. The first step is a fast search over the whole library, and it often uses a bi-encoder. A bi-encoder turns the question and each chunk into a list of numbers, and the chunk lists were stored in advance, so a new question only needs one encoding and a quick comparison.

The second step is a reranker, and a cross-encoder is a common choice. It reads the question and one chunk together, as a single input, and gives one relevance score. It is more careful, because the model can look at both texts at once. It is also expensive, because every pair needs a full pass through the model and nothing can be stored ahead of time. So I never run it on the whole library.

The pattern is to find a shortlist of about 100 with the fast step, rerank that shortlist with the cross-encoder, and send the best few to the model. Anthropic's tests found that passing 20 chunks worked better than passing 10 or 5, so the number is something to measure, not a rule. The trade-off is delay and cost against recall (how many of the right chunks the search finds), so I measure both on real questions before I pick the shortlist size. A bigger shortlist finds more right answers, but each question waits longer.

## What is a reranker, in plain words?

A reranker sorts a shortlist again, more carefully. In a RAG app (retrieval-augmented generation, where the model answers from your own documents), the first search often pulls out a lot of chunks, sometimes hundreds, that might help. The reranker then puts those chunks in order of real usefulness, and only the top few go into the model's prompt.

Think of a law firm's junior associate. They pull 100 possibly relevant cases from a 40,000-file archive using keyword matching and a quick relevance check. A senior lawyer then reads those 100 properly and picks the best 10. The associate is fast and wide, and the senior is slow and careful. An AI reranker plays the senior's part, and a bi-encoder or keyword search plays the associate's. In a bank's support assistant, that means 100 candidate chunks come from 2 million, and the reranker keeps the few that answer a card fee question.

- **Chunk:** A piece of a document, often a few paragraphs, stored so search can find it.
- **Embedding:** A list of numbers, also called a vector, that stands for the meaning of a piece of text.
- **Bi-encoder:** A model that encodes the question and each chunk separately, then compares the two lists.
- **Cross-encoder:** A model that reads the question and one chunk together and gives one relevance score.
- **Shortlist:** The top candidates from the first search, handed to the reranker.

## How does a cross-encoder differ from a bi-encoder?

Both models turn text into numbers that carry meaning. The difference is when the two texts meet. A bi-encoder encodes them apart, so each chunk's vector is computed once and stored. A cross-encoder joins them, so the model reads both together, and it has to run again for every pair.

- **Bi-encoder: Read apart, compared fast.** Each chunk is encoded once, when it is indexed. A new question is encoded once, then compared with the stored vectors. Cheap per chunk, so it can search millions.
- **Cross-encoder: Read together, scored carefully.** The question and one chunk go through the model as one input, which gives one score for that pair. Nothing can be stored ahead of time, so every pair costs a full pass.
- **Why it matters: Better order costs time.** Use the bi-encoder to find candidates and the cross-encoder to order them. Azure's semantic ranker does the same: it rescores the results of a first pass.

*Diagram, Two ways to score a question against a chunk: The upper section is the bi-encoder: the question and each chunk are encoded alone, then their vectors are compared. The lower section is the cross-encoder: the pair is read together and scored, one pass per pair. The lower path is the slow one.*
1. The question is encoded alone, into one list of numbers.
2. Each chunk was encoded alone earlier, so its numbers are stored.
3. The two lists of numbers are compared, which is quick.
4. The question and one chunk are joined and read as one input.
5. The model reads the pair and gives one score: the slow step.

The 2019 Sentence-BERT paper explains the cost of reading pairs. Its authors say that BERT "requires that both sentences are fed into the network", and they measured the cost of finding the most similar pair in 10,000 sentences:

> "it requires that both sentences are fed into the network, which causes a massive computational overhead" (Reimers and Gurevych, Sentence-BERT (2019))
>
> "derive semantically meaningful sentence embeddings that can be compared using cosine-similarity" (Reimers and Gurevych, Sentence-BERT (2019))

Their abstract makes the point: "Finding the most similar pair in a collection of 10,000 sentences requires about 50 million inference computations (~65 hours) with BERT." Their fix, SBERT, makes sentence vectors that can be compared directly by cosine similarity, a standard score for how closely two lists of numbers point the same way.

## How do teams use both in one search?

One common design is two stages. Nogueira and Cho describe the same pattern in their paper, Passage Re-ranking with BERT: a first search uses "a standard mechanism, such as BM25" (a classic keyword-scoring method), then in the second stage, "passage re-ranking, each of these documents is scored and re-ranked by a more computationally-intensive method."

1. **Find candidates fast:** A bi-encoder search or keyword search pulls the top 100 chunks from the whole library.
2. **Rerank the shortlist:** A cross-encoder scores each question and candidate pair, and the list is sorted by that score.
3. **Send only the best:** The best few go into the model's prompt. Fewer chunks means less for the model to read, so each answer costs less to produce.

*Diagram, Search first, then rerank a shortlist: Two stages: a fast search over the whole library, then a careful reranker over only the 100 best candidates. The model sees only the best few, so the slow step runs 100 times, not 2 million.*
1. The question goes into the fast search.
2. The search returns its 100 best candidates.
3. The shortlist goes to the cross-encoder, one question and chunk pair at a time.
4. The best few chunks go to the model.

A worked example. A mid-size bank keeps 2 million chunks of product rules, fee tables and complaint procedures. Its support assistant gets a question about a card fee. The bi-encoder compares the question with the stored vectors, which is cheap, and returns 100 candidates. The cross-encoder then scores those 100 pairs. Scoring all 2 million with a cross-encoder would mean 2 million full model passes for one question, and no support team can wait for that.

```python
# A made-up bank: 2 million policy chunks. We count model passes for one customer question.
CHUNKS = 2_000_000
SHORTLIST = 100

def two_stage():
    # Stage 1, bi-encoder: embed the question once, compare it with stored vectors (a plain scan; a vector index checks far fewer).
    stage1 = {"question embeddings": 1, "vector comparisons": CHUNKS}
    # Stage 2, cross-encoder: one full model pass per shortlisted pair.
    stage2 = {"cross-encoder passes": SHORTLIST}
    return stage1, stage2

def whole_library():
    # No shortlist: the cross-encoder reads the question with every chunk.
    return {"cross-encoder passes": CHUNKS}

s1, s2 = two_stage()
print("Stage 1:", s1)
print("Stage 2:", s2)
print("Cross-encoder on the whole library:", whole_library())
```

Output:

```text
Stage 1: {'question embeddings': 1, 'vector comparisons': 2000000}
Stage 2: {'cross-encoder passes': 100}
Cross-encoder on the whole library: {'cross-encoder passes': 2000000}
```

> "Reranking is a commonly used filtering technique to ensure that only the most relevant chunks are passed to the model." (Anthropic, contextual retrieval)
>
> "The results are scored using BM25 or RRF scoring, and then rescored by semantic ranker." (Microsoft, Azure AI Search semantic ranker)

RRF (reciprocal rank fusion) is a way of merging ranked lists before the semantic rescoring.

## What are the trade-offs and limits?

Reranking is not free. Anthropic's own write-up puts the cost plainly: "Because reranking adds an extra step at runtime, it inevitably adds a small amount of latency, even though the reranker scores all the chunks in parallel." (Latency means delay.)

- **More candidates, more cost:** Anthropic names the trade-off: reranking more chunks gives better performance, but reranking fewer gives lower latency and cost.
- **The reranker only sorts:** It can't rescue a chunk the first search missed. If the right answer is not in the shortlist, it is gone.
- **Vectors can blur detail:** A bi-encoder packs a whole chunk into one list of numbers, so fine detail can blur. ColBERT, a 2020 model, sits between the two: it encodes the question and the document separately, then runs a cheap interaction step that matches them in fine detail.
- **Test on your own data:** Anthropic's experiments used a Cohere reranker, and they advise: "We recommend experimenting with different settings on your specific use case to find the right balance."

> **Tip:** Asked which to use? Say a bi-encoder or keyword search gives recall (it finds most of the right chunks in the whole library), and a cross-encoder gives precision (it puts the right chunks at the top of a shortlist). Name the shortlist size, and measure it on real questions.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] A plain definition: a reranker orders a shortlist with a more careful model.
- [ ] Bi-encoder versus cross-encoder, and why a cross-encoder pass costs more.
- [ ] Two stages in production: a fast search finds candidates, then a careful model puts them in order.
- [ ] The shortlist limit: the reranker can't rescue a chunk the search missed.
- [ ] The trade-off: delay and cost rise with the shortlist, so measure it.
- [ ] A real case at scale, such as a support or claims assistant.

**Common traps**

- Trap: "A reranker replaces the search." Better: It sorts what search finds. Without search there is nothing to sort.
- Trap: "A cross-encoder is most accurate, so use it for everything." Better: Every pair costs a full model pass. It only fits on a shortlist.
- Trap: "A bigger embedding model turns the bi-encoder into a reranker." Better: Bigger vectors still compare apart. Precise ordering needs the second pass.

## Can you spot the design problem?

**Spot the design:** A claims team has 2 million chunks and needs fast answers. Which search loop would you ship?

A. for chunk in all_chunks: score = cross_encoder(question, chunk)
B. candidates = index.search(embed(question), k=100); ranked = rerank(question, candidates)
C. ranked = rerank(question, random.sample(all_chunks, 100))
D. vectors = [embed(c) for c in all_chunks]  # run again for each question

**Answer:** B. The bi-encoder finds 100 candidates from stored vectors, so the cross-encoder runs only 100 times. The other three run the slow model on the whole library, pick chunks by chance, or re-encode 2 million chunks on every question.

**Quick check:** A support bot's right answer was missing from the top 100 candidates. What fixes it?

A. Use a bigger cross-encoder on the same 100
B. Retrieve more candidates in the first stage, then rerank
C. Make the system prompt longer
D. Lower the shortlist threshold to zero

**Answer:** B. The reranker only reorders what the first search hands it. A chunk missing from the shortlist can't reach the top, so widen the first stage and let the reranker sort.

## Can you answer these from memory?

**Flash cards**

- **What does a bi-encoder do?** Encodes the question and each chunk apart, then compares vectors. Chunks are stored ahead.
- **What does a cross-encoder do?** Reads the question and one chunk together, and gives one relevance score for the pair.
- **Why not cross-encode everything?** Every pair needs a full model pass, so the cost grows with the library. Rerank a shortlist.
- **Where does a reranker sit?** After the first search. It reorders the candidates before the model answers.
- **Can a reranker find a missed chunk?** No. It only sorts what it gets, so widen the first search.
- **What is ColBERT?** A middle option: text is encoded apart, then matched piece by piece for detail.

## Likely follow-up questions

- Q123 What is hybrid search (BM25 + vectors)? https://designervenkat.online/interview/ai/what-is-hybrid-search
- Q118 Cosine vs dot product vs Euclidean distance? https://designervenkat.online/interview/ai/cosine-vs-dot-product-vs-euclidean-distance
- Q119 What is approximate nearest-neighbour search? https://designervenkat.online/interview/ai/what-is-approximate-nearest-neighbour-search
- Q127 What are query rewriting and expansion? https://designervenkat.online/interview/ai/what-are-query-rewriting-and-expansion
- Q131 Retrieval metrics: recall@k, MRR, nDCG? https://designervenkat.online/interview/ai/retrieval-metrics-recall-at-k-mrr-ndcg

## Learn it in depth

- [From question to context](https://designervenkat.online/learn/ai-engineering/retrieval-process)
