Track 02 · RetrievalLesson 05 of 11
Rewriting, routing and fusing queries
Handle the vague and multi-hop questions people actually type.
- Lesson library · reference
- 40 min read
- 60 min hands-on
- Pro
What you'll be able to do
01- Explain what each query-side technique fixes (condensation, rewriting, expansion, multi-query, HyDE, decomposition, step-back) and what it costs in latency, money and risk.
- Design a router that sends each question to the right back end (documents, SQL, graph, a system of record) using rules first and a schema-constrained LLM as fallback.
- Implement multi-query retrieval fused with reciprocal rank fusion, and measure whether it improves recall on your golden set.
- Extract metadata filters from natural language safely: validated, narrowing only, never touching permissions.
- Defend when not to use these techniques, especially under tight latency budgets and for exact lookups.
Before you start
- Hybrid search and reranking: BM25, RRF and stage-wise recall.
- Picking embeddings on your corpus, not a leaderboard: dense retrieval and cross-lingual behaviour.
- Typed output: schemas, validation and tool calls: router and filter outputs must be schema-validated.
- ReAct, chain of thought and reflection in practice: decomposition and step-back are prompting patterns applied to retrieval.
The short version
Users do not type clean, self-contained, single-hop queries in the corpus's language. They type follow-ups ("and for Brava?"), Portuguese questions over English contracts, questions that need two lookups joined together, and questions that belong in a database rather than a document index. Query-side techniques transform the question before retrieval: condense it into a standalone query, rewrite or translate it, generate several variants and fuse the results, generate a hypothetical answer to search with (HyDE), decompose it into sub-questions, or step back to a more general question. A router decides which back end should answer at all. Each technique adds an LLM call and some risk, so add them one at a time, behind an eval, and skip them when a deterministic route already works.
- Route first. An exact ID or a numeric tariff question should never go through paraphrasing and vector search.
- Use rules for what is certain and a schema-constrained LLM for what is not; validate every LLM output against an allowed set and fail safe.
- Filters extracted from the question can only narrow results. Permissions come from identity, never from the text.
- Multi-query plus RRF (RAG-Fusion) mostly helps recall on vocabulary mismatch and cross-lingual queries.
- Log the original query, every rewrite, the route and the filters. You will need them for evals, audits and incident review.
Pro lesson
The rest of this lesson is in Pro.
The mental model, worked example, field note, failure table, exercise and self-check, with the voice tutor.
- Every stage and specialisation, in full
- Every lab and every role project
- Halden weeks 2–10, on your record
- Every drill, live in the playground
- All solutions, plus the server judge
- Lab Assistant and every Teach with AI