On this page · 15 sections

“Retrieval Strategies: Vector Search, Keyword Search, and Hybrid Search (opens in a new tab)” ended with three questions that no ranking fixed:

  • “Our accountant needs copies of the bills automatically.” Vector search ranked the answer first; RRF, the hybrid, pushed it out of its top ten.
  • “Do I pay extra for every person I add?” Vector search ranked the answer eighth, and it didn’t fit into the budget.
  • “Who else handles our information on your behalf?” No method placed the answer in its top ten.

All three methods in Article #16 had one thing in common: they compared a question and a chunk that had been turned into numbers separately, two embeddings or two bags of words. Nothing ever read the question and the chunk together.

That’s what a reranker does. And it raises a distinction this article is about: finding candidates and choosing the best of them are different problems. A reranker can only choose among what the first stage found.

Try to Understand It This Way

A company gets a thousand applications for one job. A recruiter screens them quickly, looking at keywords and job titles, and passes ten to the hiring manager. The hiring manager reads each of the ten properly and picks the best.

Two things follow. The hiring manager can’t hire someone the recruiter didn’t pass on, however good they were. And the manager can’t read all thousand, which is why the recruiter exists.

The recruiter is the first stage: vector search, keyword search, or a hybrid. It’s fast, and it has to cover everything. The hiring manager is the reranker: slow, careful, and limited to the shortlist.

Two Stages

The vector-search first stage used in Articles #12 to #16 was a bi-encoder: the question and each chunk are embedded separately, and similarity is computed between the two vectors. That’s what makes it fast. The chunks are embedded once, ahead of time, and a question needs one embedding and some arithmetic.

A reranker reads both together. The Sentence Transformers documentation describes the usual kind, a cross-encoder: “The query and a possible document is passed simultaneously to transformer network”, and “The advantage of Cross-Encoders is the higher performance, as they perform attention across the query and the document.” The cost is the reason for two stages: “Scoring thousands or millions of (query, document)-pairs would be rather slow. Hence, we use the retriever to create a set of e.g. 100 possible candidates which are then re-ranked by the Cross-Encoder.”

The reranker in this article isn’t a trained cross-encoder. It’s the 3B chat model from the earlier articles, llama3.2:3b, asked a yes/no question:

system   You judge whether a passage from a product's documentation answers a customer's question.
         Reply with one word: Yes or No.
user     Question: ...   Passage: ...   Does this passage answer the question? Reply Yes or No.

Only the first token matters. Ollama can return the log-probabilities of the most likely tokens at each position (“Number of most likely tokens to return at each token position when logprobs are enabled”), so the score is an estimate of the log-odds of the answer:

score = log(sum of P over the "yes" tokens) - log(sum of P over the "no" tokens)
        at the first output position, counting only the 20 most likely tokens Ollama returns;
        "yes" tokens: Yes, yes, YES, " Yes", " yes"; "no" tokens: the same for No

Higher means the model leans further towards “Yes”. It’s a model-derived relevance score, not a calibrated probability that the passage answers the question, and the model can be confidently wrong.

Because only 20 alternatives come back, a variant outside them isn’t counted. A check over all 2,581 scored pairs: “Yes”, “No”, and “NO” were among the 20 every time, “yes” in 1,253 pairs, “YES” in 2,012, and the space-prefixed variants almost never. For each pair, the check bounds what all the missing variants could add on both sides: each omitted token is at most as likely as the 20th alternative, and the largest possible change is computed against the observed “yes” and “no” sums. That bound was at most 0.0025 for any pair, with a median of 0.00005. For two neighbouring candidates in a reranked list, the gap between their scores is smaller than the sum of their two bounds in only two places, both at positions 18 and 19 of a 20-candidate list, and swapping either pair changes no result.

Using a language model to rerank is an established idea: Sun et al. (2023) found that “properly instructed LLMs can deliver competitive, even superior results to state-of-the-art supervised methods on popular IR benchmarks”, with much larger models than this one. Trained rerankers go back further: Nogueira and Cho (2019) described “a simple re-implementation of BERT for query-based passage re-ranking”. This demo shows the mechanism and its costs with a small model on a laptop. It says nothing about how well a purpose-trained reranker would do.

The Experiment

The demo, 06-reranking, keeps everything from Article #16: the same five documents, the same 98 chunks with their headings, the same budgets, and the same 100 questions with their development/test split. All of them were frozen before any reranker existed.

Two first stages find the candidates: vector search, and the RRF hybrid from Article #16. Each passes on its top 10 or top 20. The reranker scores every candidate, the candidates are sorted by score, and the budget is filled from that order. A chunk that isn’t among the candidates is never used.

Implementation note: the exact setup
Machine:       Apple M4 Pro (24 GB), macOS 26.6.2
Runtime:       Ollama 0.40.16, /api/embed and /api/chat with logprobs
First stages:  vector (nomic-embed-text, ID 0a109f422b47) and RRF of vector and BM25 (k = 60),
               as in Article #16; top 10 or top 20 candidates
Reranker:      llama3.2:3b, ID a80c4f17acd5 (Q4_K_M), temperature 0, seed 1, one output token,
               top_logprobs 20. "Yes" and "No" variants (Yes, yes, YES, with and without a leading
               space) are each one token; the score is the log-sum-exp of the "yes" variants minus
               that of the "no" variants, among the 20 alternatives returned. Ties keep the
               first-stage order
Pairs:         every (question, chunk) pair in the top 20 of either first stage: 2,581,
               each scored once and reused wherever it appears
Budget:        retrieved chunks only, in Llama 3.2 tokens; 500, 1,000, and 2,000
Languages:     Python 3.12.13 and Node.js 24.16.0: the same 2,581 first tokens and prompt token
               counts, scores equal to within 2e-15, identical rankings and tables
Repeat checks: 250 pairs, seeded and shuffled, scored again after reloading the model: identical;
               all 2,581 pairs scored twice more in Python, to record which label variants were
               returned: identical
Date:          2026-11-15

The prompt, the label tokens, the candidate counts, and the scoring rule were written down before any reranking run.

The Ceiling: Candidate Recall

Before asking what the reranker chose, ask what it was allowed to choose. How often was the evidence anywhere in the candidates?

                         new questions         Article #15's questions
first stage              dev (21)  test (19)    dev (31)   test (29)
vector, top 10                 20         19          31          29
vector, top 20                 21         19          31          29
RRF, top 10                    19         18          31          29
RRF, top 20                    19         18          31          29
(all 98 chunks)                21         19          31          29

Vector search’s top 20 held the evidence for every question. RRF’s top 20 missed three, and going from 10 to 20 candidates didn’t recover them. For those three, no reranker can help, however good it is.

This table also has to come first for a second reason. A larger candidate pool can look like a reranking improvement when it’s really a recall improvement. Here, going from 10 to 20 vector candidates added exactly one question to the pool.

What Reranking Changed

All 48 test questions, by budget. “First stage” is the candidates in their original order; “reranked” is the same candidates in the reranker’s order:

first stage, candidates, order       500 tokens   1,000 tokens   2,000 tokens
vector, top 10, first stage                  41             46             48
vector, top 10, reranked                     46             48             48
vector, top 20, first stage                  41             46             48
vector, top 20, reranked                     45             47             48
RRF, top 10, first stage                     45             47             47
RRF, top 10, reranked                        44             47             47
RRF, top 20, first stage                     45             47             47
RRF, top 20, reranked                        44             46             47

Reranking vector search’s top 10 was the best combination in either article: 46 of 48 within 500 tokens, where vector search alone found 41 and Article #16’s best hybrid 45, and all 48 within 1,000 tokens.

Three things in this table are worth noticing.

Reranking helps most when the budget is small. At 2,000 tokens, the first stage’s order already fits the evidence in. Reranking is about order, and order matters when only the first few chunks fit.

More candidates weren’t better. Twenty candidates did a little worse than ten (45 against 46 at 500 tokens), although across all 100 questions the larger pool held one more answer. Ten more candidates are ten more chances for the reranker to prefer a wrong chunk.

Reranking RRF’s candidates didn’t help. RRF already ranked well where it had the evidence, so there was little to fix, and the reranker’s mistakes cost about as much as its fixes. Reranking pays off where the first stage’s order is weak.

The Three Cases

Each of Article #16’s failures tests something different:

question                                 first stage       first-stage rank   after reranking the top 20
Do I pay extra for every person I add?   vector             8                  1
Who else handles our information ...?    vector            20                  4
Our accountant needs copies ...          RRF               24                  not a candidate
  • The pricing sentence shows what a reranker is for. The chunk was a candidate, just ranked too low to fit. Read together with the question, it scored highest, and it now fits within 500 tokens.
  • The subprocessor table shows the trade-off in candidate count. At rank 20 it was the last candidate; reranking moved it to 4th. With only 10 candidates, it would never have been read.
  • The billing contact chunk shows the ceiling. RRF had pushed it to 24th, outside the top 20, so the reranker never saw it. Through vector search, where it was ranked first, it stayed first.

What It Fixed, and What It Broke

Reranking isn’t monotonic. Over all 100 questions, reranking vector search’s top 10 fixed 9 questions at 500 tokens and broke 2; with the top 20, it fixed 10 and broke 5.

A fix: “What does a 503 with the code maintenance mean?” Four of vector search’s top five were release notes. The reranker scored the API reference’s error table highest (-1.02), well above the release notes (-3.08 and lower), and moved it to first.

Two breaks, and why:

  • “Do people created through SCIM become Admins?” Vector search had the SCIM section first. The reranker scored five chunks above it, led by what happens when the Owner leaves, the audit log, and roles and permissions. Those three talk about Admins and permissions; none says what SCIM does with roles.
  • “Sign-in fails with SSO-101. How do I fix it?” The answer needs two chunks: the error code’s row, and the section on replacing the certificate. The reranker scores each chunk on its own, and it moved two other chunks between them. At 500 tokens, the second chunk no longer fit. A reranker that scores chunks one at a time doesn’t know a question needs two.

A Poor Judge, a Useful Ranker

The model answered “No” for 2,519 of the 2,581 pairs, including 73 of the 125 pairs whose chunk holds evidence. As a yes/no judge, it’s mostly wrong about the chunks that matter.

As a ranker, it’s useful anyway. The median score was -0.42 for chunks with evidence and -4.69 for the rest, and for 84 of the 100 questions, the highest-scored candidate held evidence. A reranker only has to put the right chunk above the others. Its scores don’t have to mean anything on their own, which is also why using one as a threshold would have gone badly here: dropping every chunk scored below 0 would have dropped 73 of the 125 chunks with evidence.

What It Costs

This is where reranking differs most from the first stage. In the Python run, one scoring call took a median of 166 ms (184 ms in the JavaScript run), so one after another:

vector search for one question         one embedding, about 8 ms (Article #16)
reranking the top 10                   10 calls, about 1.7 to 1.8 seconds
reranking the top 20                   20 calls, about 3.3 to 3.7 seconds

A purpose-built reranker can be much smaller and faster than a chat model, and candidates can be scored in parallel or in batches. But the shape stays: the first stage has a mostly fixed cost per question, and reranking adds scoring work for every candidate, even when the candidates are processed together in a batch. That’s why the candidate count is a cost decision as much as a quality one, and why the first stage has to be good enough to put the answer into a short list.

Under the hood: the same request, two different scores

The 50-pair timing run before the experiment scored each pair twice, and 22 of the 50 pairs came back slightly different the second time, by up to 0.017 in a follow-up probe. The temperature was 0 and the seed fixed.

The difference came from Ollama’s prompt cache. The same prompt, evaluated from scratch or after a different prompt, gave the “Yes” token a log-probability of -0.3929. Sent again right after itself, with 99 of its 100 prompt tokens served from the cache, it gave -0.3908. Reusing a cached computation is fast, and it isn’t bit-for-bit the same arithmetic.

So the full run scores every pair once. A check afterwards scored 250 sampled pairs again, in shuffled order, after reloading the model: all 250 matched exactly, and Python and JavaScript matched each other. The differences are small next to the gaps between candidates’ scores here, but a reproducible evaluation has to know they exist.

What Breaks

  • Answers outside the candidate set. A reranker can’t recover what the first stage didn’t pass on.
  • Too many candidates. Each extra candidate costs a model call and is another chance to prefer a wrong chunk.
  • Topic over answer. The reranker preferred chunks about Admins to the one that answers a question about Admins.
  • Questions that need two chunks. Scoring chunks one at a time can split the two halves of an answer.
  • Scores used as thresholds. A ranking score from an uncalibrated model doesn’t say whether a chunk answers anything.
  • Latency. Seconds per question for a chat-model reranker, against milliseconds for retrieval.
  • Cache-dependent scores. The same request can score slightly differently when part of it is served from the server’s cache.

Engineering Decisions

1. Measure candidate recall before reranking

The first stage sets the ceiling. Report how often the answer is among the candidates, for each candidate count, before reporting what reranking did with them.

2. Choose the candidate count from data, not habit

More candidates raise the ceiling and the cost, and give the reranker more ways to be wrong. Here 10 candidates beat 20.

3. Rerank where the first stage’s order is weak

Reranking helped vector search a lot and RRF not at all. Measure it on your own first stage before adding a second one.

4. Use the reranker to order, not to filter

A score that orders chunks well can still be useless as a yes/no decision. If you need to drop chunks, calibrate a threshold separately and measure it.

5. Budget the latency

A reranker adds scoring work for every candidate, on top of the first stage’s mostly fixed cost per question. Decide the latency you can afford, then the reranker and candidate count that fit it.

6. Read the questions it broke

The totals hide that reranking fixes some questions and breaks others. The broken ones show what the reranker misunderstands.

What to Take Away

  • Finding and choosing are different problems. The first stage decides what can be chosen; the reranker decides the order.
  • Reranking vector search’s top 10 found 46 of 48 test questions within 500 tokens, against 41 for vector search alone.
  • More candidates weren’t better, and reranking a strong first stage didn’t help.
  • A reranker can be a poor judge and a useful ranker: it said “No” to most right answers and still ranked them first for 84 of 100 questions.
  • It adds work for every candidate: one model call each here, seconds per question, against milliseconds for retrieval.

Think About These Use Cases

  • A support chatbot with a 2-second response target: How many candidates can you afford to rerank, and would you rerank at all?

  • A legal search with thousands of matching clauses: The first stage returns 500 candidates. What would you do before a reranker sees them?

  • Questions whose answer spans two sections: How would you stop a reranker from splitting them?

  • A team that wants to drop “irrelevant” chunks: They propose dropping anything the reranker scores below zero. What would you check first?

  • An evaluation that must be reproducible: Your reranker is a model behind an API with caching. How do you make two runs comparable?

If you want to work through one of these, take it to GPT along with this article. Ask GPT ↗️

What’s Next?

The last four articles built and measured one pipeline stage at a time: chunking, retrieval, and reranking. Each stage can fail on its own, and each one added a model call, a parameter, or a cache that behaves in ways you have to know about.

In the next article, we’ll look at Building Reliable LLM Pipelines: how to put stages like these together so that a failure in one is caught, contained, and visible.

← All articles