systemdesign.academyAI EngineeringFree lessonsSign inGet the course
  1. Home
  2. AI Engineering: Data, RAG and Agents
  3. Retrieval and RAG in Production
  4. Query Transformation and Routing: Fixing Retrieval Before It Runs

AI Engineering · Retrieval Rag

Query Transformation and Routing: Fixing Retrieval Before It Runs

Free preview: the first part of this 13-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. Why Questions and Chunks Live in Different Neighborhoods
  2. Five Moves You Can Make Before the Index Sees Anything
  3. Rewriting: The Query Must Stand Alone Before It Can Be Embedded
  4. Multi-Query: Buy Recall With Parallel Rephrasings
  5. HyDE: Search With an Answer, Not a Question
  6. Run It: Watch the Rewrite and the Pseudo-Answer Flip the Ranking
  7. Decomposition: A Compound Question Is Several Retrievals Wearing One Trench Coat
  8. Routing: Not Every Question Deserves the Vector Store
  9. Run It: Multi-Query Union Recall vs the Single-Query Lottery

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 by card or PayPal

Get Lifetime Access
Previous lessonThe RAG Retrieval Cliff: Engineering Recall Back at ScaleNext lessonRAG Evaluation: Localizing Failure Between Retrieval and Generation

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
Every Transform Is a Model Call on the Hot Path
  • Where This Sits in the Full Pipeline, and Who Ships It
  • Knowledge Check
  • 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 Index Is Tuned. The Question Is Still Broken.

    Two strings.

    The user types: can I get my money back?

    The chunk that answers them says: Refund eligibility: purchases made through the self-serve checkout are refundable within 30 days of the transaction date.

    Same meaning. Almost no shared vocabulary, and a completely different register: one is a casual first-person question, the other is third-person policy prose. Your model maps text into a space where wording and style shape position, so these two land far enough apart that a chunk about updating payment methods, which happens to share the casual FAQ register and the word "money," can outscore the actual refund policy. The user gets an answer about credit cards. The refund chunk was in the index the whole time, cleanly chunked, well embedded, correctly ranked among its own kind.

    Everything else in this chapter so far has worked on the index side of the equals sign. You cut better chunks, added a reranker, ran BM25 next to the embeddings, cleaned up extraction. All of that improves what the corpus looks like. None of it touches the other input to the similarity function: the query itself. The hybrid retrieval lesson already met one narrow version of this problem, the exact-token query that embeddings blur, and fixed it with a second index. This lesson is about the broad version: the query whose meaning is right but whose wording, register, or scope points the search at the wrong neighborhood. That gets fixed by changing the query before retrieval runs, and by sometimes deciding that retrieval should not run at all.

    The reason this deserves a full lesson is leverage. A retrieval miss can come from either input to the similarity function, but the two inputs cost wildly different amounts to fix. The corpus side is millions of documents; the query side is a few dozen tokens at request time. When the cheap side is also the one you have not touched, that is where the next percentage points of recall live.