systemdesign.academyAI EngineeringFree lessonsSign inGet the course
  1. Home
  2. AI Engineering: Data, RAG and Agents
Previous lessonChunking: The First Lever on Retrieval QualityNext lessonHybrid Retrieval: When Keyword Search Beats Your Embeddings

System Design

  • Foundation
  • Intermediate
  • Advanced
  • Capstone

AI Engineering

  • Foundation
  • Data, RAG and Agents
  • Evaluation, LLM Ops and Security

systemdesign.academy

  • Home
  • Glossary
  • Interview prep
  • Reviews
  • About
  • Pricing
  • Privacy
  • Terms
  • Refunds
  • Delivery
  • Contact
  • Retrieval and RAG in Production
  • Reranking: The Highest-Return Change in Your RAG Stack
  • AI Engineering · Retrieval Rag

    Reranking: The Highest-Return Change in Your RAG Stack

    Free preview: the first part of this 10-part lesson.

    Already bought the course? Sign in to read the whole lesson.

    this lesson is part of

    AI Engineering

    Unlock this lesson and the 199 other paid lessons

    • 210 lessons in 16 chapters
    • 118 lessons built on a lab that really ran
    • An AI tutor beside every lesson that answers and draws
    • Lifetime access, every new lesson included

    $49 once, by PayPal

    See the AI Engineering course

    The rest of this lesson

    1. Two Stages: Retrieve Wide, Then Rerank
    2. Why a Cross-Encoder Beats the Bi-Encoder That Found the Chunk
    3. Watch the Right Answer Climb to the Top
    4. Measure the Right Thing at the Right Stage
    5. What Reranking Costs You
    6. What Reranking Cannot Do For You
    7. When the Top 5 Are Five Copies of One Fact
    8. How Teams Actually Ship This
    9. Knowledge Check

    read the rest of this lesson in

    AI Engineering

    Unlock this lesson and the 199 other paid lessons

    • 210 lessons in 16 chapters
    • 118 lessons built on a lab that really ran
    • An AI tutor beside every lesson that answers and draws
    • Lifetime access, every new lesson included

    $49 once, by PayPal

    See the AI Engineering course

    Continue this lesson

    in Retrieval Rag

    This lesson is part of the AI Engineering course. Unlock the full course, a separate one-time payment, for lifetime access.

    One-time payment. Lifetime access. No subscription.
    Global
    $49/lifetime

    One-time payment via PayPal

    Get Lifetime Access
    Foundation lessons free, try before you buy
    India Special
    India
    ₹999/lifetime

    One-time payment: UPI, card or netbanking

    Get Lifetime Access
    Foundation lessons free, try before you buy
    Every ML Platform lesson, Foundation to Advanced
    Real architecture diagrams with real tool logos
    MLOps, LLMOps, and data engineering in depth
    Quizzes with instant feedback
    Built and reviewed by senior engineers
    Lifetime access, all future content included

    Foundation lessons of this course are free, no payment needed. Try them now

    The Chunk Was There, Ranked Twelfth

    A support bot keeps giving the wrong answer to one question: how to reset a password when the account has no recovery email. The team assumes the answer is not in the knowledge base. It is. Someone finally dumps the raw retrieval output for that query and reads it by hand. The correct chunk, the one that explains the SMS fallback, is sitting right there in the results. At position twelve.

    The system was only putting the top five chunks into the prompt. So the model never saw the answer. Not because the answer was missing, and not because retrieval failed to find it, but because retrieval ranked it below eleven chunks that happened to share more words with the question. Three of those top chunks were about changing your password while logged in, which is useless to a user who is locked out. One was about managing marketing email preferences. Every one of them was, on the surface, about passwords or email, and that surface overlap is exactly what pushed the real answer down.

    This is one of the most common failures in production , and it is worth naming precisely: the right chunk was retrieved but ranked too low to be used. Vector search found it. Vector search just could not tell that it was the best one. That is not a recall problem, it is a ranking problem, and the two are worth keeping apart in your head because they have opposite fixes. A recall problem means the answer is not in the results at all, and you fix it upstream. A ranking problem means the answer is in the results but ordered wrong, and you fix it with a second stage.

    Before the mechanism, the size of the effect, measured rather than claimed.

    The corpus is this course: 818 real lessons, all written in one voice about one field, so every wrong answer is a plausible neighbour rather than an obviously unrelated document. Twenty queries, each with exactly one correct lesson chosen before any retrieval ran. Ten are phrased the way a person actually complains about a problem and deliberately avoid the target lesson's vocabulary; ten carry a distinctive literal term.

    A recorded terminal session reporting recall over an 818-lesson corpus with 20 known-item queries. Recall at 1, 3, 5 and 10: dense embeddings 45, 55, 55 and 70 percent; bm25 keywords 50, 70, 75 and 80 percent; hybrid fusion of both 55, 70, 75 and 85 percent; dense plus LLM rerank 45, 65, 75 and 80 percent. A second block splits recall at 5 by query phrasing: dense scores 43 percent on natural-language queries and 83 percent on exact-term queries, while bm25 scores 64 percent and 100 percent. A third block notes the rerank ceiling: it reorders only the dense top 20, and two queries had their answer outside that window.
    RecordedMeasured on a laptop against the course's own 818 lessons

    Start with the row this lesson is about. Reranking took recall at 5 from 55 percent to 75 percent. That is twenty points from a second stage bolted onto an unchanged first stage, and it is the largest single move in the table. The chapter's claim survives contact with a measurement.

    Then read the last block, because it is the boundary the claim has. A reranker reorders the dense top 20 and nothing else. Two of the twenty queries had their correct lesson sitting outside that window, one of them at position 72, and no amount of reranking will ever find them. That is the recall problem from two paragraphs ago, and the second stage is structurally incapable of fixing it. Reranking is the highest-return change you can make to ranking. It is not a change to recall.

    Now the row that should bother you. BM25, which is keyword scoring with no model involved at all and about fifteen lines of code, beat the embedding model at every single depth. On the exact-term queries that is expected and it is the subject of the lesson. On the natural-language queries, the ones written specifically to share no vocabulary with their target, it still won, 64 percent against 43.

    Two honest caveats on that, because it is a strong claim from a small experiment. Twenty queries is a small sample and the interval around each of these numbers is wide. And the model here is a small one running locally; a frontier embedding API would very likely close some of that gap. What the result does establish is narrower and still useful: the lexical baseline is not a legacy fallback you keep for exact terms. It is a genuine competitor, it costs nothing, and if you have never measured it against your embeddings on your own corpus, you do not know which one you should be running.

    Which is why the best row in the table is neither. Hybrid, fusing both lists, is top at recall 1 and top at recall 10. The two methods fail on different queries, and combining them recovers what either alone would lose.

    The fix is that second stage. Let the fast retriever cast a wide net and return many candidates, then run a slower, more accurate model over just those candidates to reorder them before you pick the final few. That second model is a reranker, and adding one is often the single highest-return change you can make to a RAG stack. It is a few lines of code, it needs no re-indexing, it touches nothing about how your documents were embedded, and it goes straight at the failure above. For a team that has already built retrieval and is watching quality plateau, it is usually the first thing to try.