Sub topic 12
Reranking: choosing the best passages
This chapter assumes you know the earlier stages: a prompt is expanded by query fan-out, each sub-query is run against a lexical, semantic or hybrid index, documents are split into passages, and the result lists are merged. Reranking comes next. It decides which of the merged candidates the answer-writing step will see.
Why a second ranking step exists
The first retrieval stage has to be fast. It compares a query against millions or billions of passages, so it uses cheap comparisons, such as keyword statistics or precomputed embedding vectors. These comparisons are approximate. A passage can match the right words and still not answer the question.
The merged list can also hold dozens or hundreds of candidates. The model that writes the answer can only read a limited amount of text. Sending everything would be slow and costly, and irrelevant text can distract the model. So systems commonly add a more careful scoring pass over a short list and keep only the top few passages.
How a reranker differs from first-stage retrieval
The most common design in the research literature is the cross-encoder. First-stage semantic retrieval typically uses a bi-encoder, which turns the query and each passage into vectors separately and then compares them. A cross-encoder reads the query and one passage together and outputs a relevance score. Because it sees both at once, it can notice things the vectors blur: negation, a qualifier like "under 100 dollars", or a passage that discusses the topic without answering the question.
That accuracy costs time. A cross-encoder must run once per query and passage pair, which is why it only runs on the short list.
| Property | First-stage retrieval | Reranking |
|---|---|---|
| Input | Query, searched against a whole index | Query plus one candidate passage at a time |
| Candidates handled | Millions or more | Tens to hundreds |
| Typical method | Keyword scoring, embedding similarity, or both | Often a trained model reading both texts together |
| Main goal | Do not miss relevant passages (recall) | Put the best passages first (precision) |
| Cost per candidate | Very low | Much higher |
Large language models can also be prompted to judge or order passages, and some commercial search APIs offer rerankers as a service. Which method a particular AI search product uses is not publicly documented. Treat the cross-encoder as the standard published pattern and not as a description of any one product.
What else may influence the final selection
Relevance scores are probably not the only input. The following signals are plausible, and each is inferred from general search practice. None is confirmed for specific AI search products.
- Freshness. For queries about news, prices or recent releases, newer passages may be favoured.
- Source diversity. A system may avoid filling every slot with passages from one site, so that the answer can draw on several sources.
- Redundancy. If two passages say the same thing, keeping both wastes space. A selection step may drop the near-duplicate.
- Source quality and safety. Quality signals borrowed from classic search, and filters for sensitive topics, may apply.
- Language and region. Passages that match the user's language or location may rank higher.
A toy reranker
The sketch below is not a real model. It shows two ideas in plain code: each passage is scored against the query, and a selection step limits how many passages come from one page. The score is simple keyword overlap, standing in for a trained model.
def toy_rerank(query, candidates, top_k=2, max_per_page=1):
"""Score each passage, then pick the best while limiting passages per page."""
query_terms = set(query.lower().split())
def score(passage):
words = set(passage.lower().split())
return len(query_terms & words) / len(query_terms)
scored = sorted(
((score(c["text"]), c) for c in candidates),
key=lambda pair: pair[0],
reverse=True,
)
chosen, per_page = [], {}
for s, c in scored:
if per_page.get(c["page"], 0) >= max_per_page:
continue
per_page[c["page"]] = per_page.get(c["page"], 0) + 1
chosen.append((c["page"], round(s, 2)))
if len(chosen) == top_k:
break
return chosen
candidates = [
{"page": "page_a", "text": "Stability shoes add support for overpronation, while motion control shoes are stiffer."},
{"page": "page_a", "text": "Our brand story began in 1998."},
{"page": "page_b", "text": "Motion control shoes suit severe overpronation."},
{"page": "page_b", "text": "Stability shoes suit mild overpronation."},
{"page": "page_c", "text": "Shoes shoes shoes best shoes buy shoes now"},
]
print(toy_rerank("stability vs motion control shoes", candidates))The output is [('page_a', 0.8), ('page_b', 0.6)]. Page C's keyword-stuffed passage scores low, and the per-page limit stops page B's second passage from taking a slot. A real reranker would also see that page A's first passage compares the two shoe types, which is what the query asks for.
What rerankers tend to reward
A reranker scores a passage on its own, next to the query. That has practical consequences for content. These are inferences from how such models are built and evaluated, not guarantees.
- Direct answers. A passage that states the answer to a specific question in its first sentence tends to score better than one that circles the topic.
- Self-contained text. A chunk that begins "As mentioned above, this option is better" has lost its referent once it is cut out of the page. Name the subject in the passage itself.
- Matching specificity. If the sub-query is "running shoes for flat feet under 100 dollars", a passage with a price and a shoe category matches better than a general buying guide.
- Substance over repetition. Repeating the keyword adds no information. A model that reads the whole passage can tell when the text says little.
- Clean passage boundaries. Headings that match the question, short paragraphs, and one claim per paragraph make it likelier that a chunk is complete when it is retrieved.
Common errors in reasoning about reranking
- Assuming the first-stage rank carries through. A page that ranks first in a classic search can lose its slot after reranking if its passages answer the question less directly than a lower-ranked page's passages.
- Optimising for one named reranker. Models differ between products and change over time. Write for the question, not for a model you cannot inspect.
- Treating the score as a quality grade. A relevance score says how well a passage fits this query. The same passage can score high for one sub-query and near zero for another.
- Believing that more text helps. A longer passage may be cut at a chunk boundary or may dilute its main point.
Practical takeaways
Reranking is the point where a passage competes directly against others for a few slots. To prepare for it, check each important passage on your page for four things. It should answer a specific question, make sense without the text around it, include the concrete details a narrower query would ask for, and add something the other passages on the page do not. The next chapter covers what happens to the selected passages: how the answer is written and which sources it cites.
Exercise
A page ranks first in the merged list for the sub-query "stability vs motion control shoes", but the reranker drops it. Its only relevant paragraph begins, "That is why this option works better for most runners." Give two likely reasons and one fix.
Show answer
The paragraph is not self-contained: once it is cut from the page, "this option" has no referent, so a model scoring the query and passage pair cannot tell which shoe type is meant. It also does not directly answer the comparison, because it states a conclusion without naming either shoe type or the difference between them. A fix is to rewrite the paragraph so it opens with the subject and the comparison, for example "Stability shoes suit mild overpronation, while motion control shoes suit severe overpronation," and then give the reason.
Exercise
In the toy reranker, set maxperpage to 2 and top_k to 3. Which passages are chosen and why does the result change?
Show answer
The result is [('pagea', 0.8), ('pageb', 0.6), ('page_b', 0.4)]. With a limit of two per page, page B's second passage (overlap 0.4) is allowed, and it scores higher than page C's stuffed passage (0.2). With the original limit of one per page, it was skipped. This shows how a diversity limit can change the final set even when the scores stay the same.