BM
Bashar ModallalSOFTWARE · AI · SYSTEMS
← All field notes

AI

When Does Reranking Improve RAG?

A ferry refund and an Arabic product question reveal when changing the order of search results helps a RAG answer, and when the index needs repair.

A query card and the card at the top of a stack share an orange circle. Other cards carry different marks.

A customer asks whether the booking fee will be refunded if the ferry operator cancels the sailing. Search finds the refund policy. The assistant answers that the fee is nonrefundable and points to a real paragraph. Halfway down the search results, a different paragraph says the operator refunds the full payment when it cancels. The first paragraph described a passenger cancelling a ticket. The answer had a citation and still got the decision wrong.

That is a good case for trying a reranker. In retrieval-augmented generation (RAG), the first search gathers passages that might help answer a question. The generator only reads the passages that make it into its context. A reranker earns its place when the right evidence regularly enters the candidate list but loses those few seats. Finding out whether that happens takes a list of passage IDs and a handful of well-chosen questions. You can do it before buying or training another model.

Follow the passage through both cuts

Think of two numbers. N is the number of candidates available to rank. K is the number of passages you can afford to send to the generator. In the diagram below the search returns twenty passages and the generator has room for three. These are example settings. A system with long passages might run out of tokens before it fills three places.

Reader’s question
       ↓
Search permitted, current documents → 20 candidate passages
       ↓
Score the question alongside each candidate
       ↓
Select 3 passages within the context budget
       ↓
Generate an answer with passage-level citations

The first cut determines which evidence is reachable. The second determines which evidence the writer can see. A common implementation uses embeddings or keyword search to gather candidates quickly. A cross-encoder then reads the question and one candidate together. It can weigh relationships such as who performed an action, which product a condition applies to, or whether a passage answers an exception. It spends that extra computation on the shortlist. The Sentence Transformers guide illustrates the two stages, and Nogueira and Cho describe an early passage-ranking experiment with BERT. Sentence Transformers guide · Passage Re-ranking with BERT

Keep the original passage ID, section heading, revision and document link attached through both cuts. Suppose a reviewer sees that the generator cited a current ticket rule but answered from an earlier revision. With IDs for the candidate list, selected context and final citation, the reviewer can tell where the old text entered. Without them, the three stages can look like a single bad answer.

A refund question where a new order helps

Consider a fictional ferry operator with room for two passages in its answer prompt. Its first search produces the following list for the question “Do I get the booking fee back if you cancel my sailing?”

Initial rank Passage What the passage establishes
1 Passenger cancellation A passenger who cancels loses the booking fee.
2 How to request a refund The passenger can submit a request online.
3 Fare components The booking fee appears as a separate line item.
4 Cancellation by the operator The operator refunds the fare and the booking fee when it cancels.

The first passage repeats almost every important word in the question. It also reverses the actor. For an evaluation, label the fourth passage as decisive and the second as supplementary. Give the reranker the section headings along with the text. If it returns passages four and two, the writer has evidence for the answer “Yes, the operator refunds the booking fee when it cancels your sailing.” The request instructions could support a follow-up about how to claim. For the question asked, the first citation should point directly to the operator-cancellation clause.

You can turn that one case into a more revealing test by changing just the actor. Ask “Do I get the fee back if I cancel my sailing?” Now the passenger-cancellation clause deserves first place. A model that puts the operator clause first for both questions has learned a topic preference that looks good on half the test. Keep both cases together when comparing versions. The tables and outcomes here are illustrative, so the expected ordering is a test you can run on your own documents.

An Arabic question where ranking alone cannot help

A reader asks in Arabic, “هل يشحن جهاز ميرا ميني عبر منفذ USB‑C وهو مطفأ؟” They want to know whether a fictional Mira Mini charges through USB-C while powered off. The search returns an English paragraph identifying the connector, an Arabic quick-start guide about charging while the device is on, and a page for the larger Mira Pro. The Mini service manual contains the answer in a table, but the indexing job only extracted the table header.

Inspect the candidate bodies. None establishes what happens while the Mini is off. Promoting the connector description to position one gives the generator a more prominent distraction. An appropriate answer at this point can identify the connector and say the available documentation does not establish the off-state behavior. A confident yes or no would add a product claim unsupported by the retrieved text.

Repair the table extraction so the model name, power state and charging result stay together. Repeat the original Arabic question, also trying the Latin model name a customer might type. Check whether the relevant row enters the candidate list. Once it does, keeping the same candidates lets you measure whether the reranker brings it into the answer context. This sequence also distinguishes a multilingual retrieval problem from a missing row. Anthropic’s contextual retrieval experiments show how retaining document-specific context can change what the first search finds. Anthropic’s contextual retrieval study

Run a comparison that can tell you what to change

Choose real question types your system serves, including exact product IDs, short follow-ups, mixed Arabic and English, exceptions, and questions with no documented answer. Freeze the document versions. For each answerable question, write the minimum supporting passage or set of passages and the claim each supports. Accept alternative passages that establish the same fact. Hold some questions back when adjusting the model or candidate count so that your final comparison includes wording you did not tune against.

Run two versions on the same stored candidate lists with the same generator, prompt and context budget. One preserves the original order. The other reorders the candidates. Save the passage IDs that actually fit after truncation. A rank of three on the search response is little help if the decisive sentence falls outside the model’s input. Microsoft documents a concrete example of these constraints in Azure AI Search, where only the top 50 initial results are eligible for semantic ranking and long input fields can be trimmed. Microsoft’s semantic ranking documentation

Imagine twenty answerable test questions, each with one sufficient passage. Sixteen have a supporting passage in the first twenty candidates. Ten have support in the first three before reranking, and fourteen after it. Candidate hit rate is 16/20, or 80%. At the generator’s cutoff, hit rate moves from 10/20 to 14/20, a gain of 20 percentage points. Four questions had no supporting candidate anywhere in the shortlist. A better order of those same twenty passages cannot recover them. The result describes this example only.

Review the individual changes behind the gain. Six questions could have improved and two regressed. If both regressions confuse an exception with a general rule, that pattern deserves its own test group. For questions requiring two clauses, record whether both made it into the prompt. For unanswerable questions, check whether the assistant acknowledges the gap. Finally, read the actual answers and their citations. A supported passage in the prompt creates an opportunity for a correct answer. The writer can still quote the wrong line.

Put a price and a response time on the gain

Measure the whole request under typical and busy conditions. Record search time, reranker time, time to first visible answer token and time to the completed answer. Compare the median and the 95th percentile so a slow minority stays visible. Run the same questions through both versions under similar load. Adding the 95th percentiles of individual stages does not give you the 95th percentile of the whole request because the slowest stages can belong to different requests.

Make the arithmetic legible. In a hypothetical service handling 10,000 queries per day, an extra $0.002 per reranked query costs $20 daily if every query takes that path. If the team can identify a quarter of queries that account for most ordering failures, reranking only that quarter would cost $5 daily at the same unit price. Test that routing rule on held-out questions. A short exact identifier may be easy to retrieve, while a short question containing “unless” can change the applicable rule. Query length alone is a poor description of difficulty.

Try a timeout during evaluation, too. Return to the original permitted results when the ranking service is slow, and require the same evidence for the answer. Preserve the user’s access restrictions before sending passages to any ranking service. Measure how often the fallback runs and which questions it affects. A feature that performs well on successful calls can still make the overall experience worse if a busy queue sends its hardest questions through the fallback.

Decide from the errors you can explain

For the ferry question, the evidence was present at rank four and the writer had two places. Moving the operator’s clause forward changes what the answer can support. For the Mira Mini question, the decisive table row had never entered the index. Repairing that row changes what the system can know. These cases call for different engineering work even though a reader experiences both as an incorrect answer.

Take one recent failure and write down three things beside it. Record the passage that should support the answer, its position among the candidates, and whether the writer received its decisive sentence. If a sample of failures repeatedly points to the second cut, try reranking and measure the newly supported answers alongside the added delay and cost. That gives the team a concrete reason to keep, narrow or remove the extra stage.

اقرأ المقال بالعربية

YOUR TAKE

What did you think?

Choose one reaction for this article.

Was this useful?

A cookie helps limit repeat responses. Your feedback is private.

Share this noteLinkedIn ↗X ↗Email ↗

Keep exploring.