Start studying
Module 9 · RAG Module contents
Module 9  ·  Card 14 / 19intermediate

Query Rewriting

Query rewriting reshapes the user's question before retrieval.

Follow-up questions like what about last year need conversation history folded in.

Vague questions can be expanded with likely synonyms and related terms.

Complex questions can be decomposed into several sub-queries.

HyDE generates a hypothetical answer and embeds that instead of the question.

Learn in depth ↓
Module 09 · RAG · 19 concepts
In depth  /  15 lines

Query Rewriting, in more detail

The user's question is often a poor search query, and rewriting fixes that before retrieval.

Follow-ups are the clearest case, since what about last year retrieves nothing on its own.

The conversation history must be folded in to make it self-contained.

Vague questions can be expanded with likely synonyms and related terminology.

Complex questions can be decomposed into several sub-queries run separately.

Compare our revenue and headcount across three years is really several searches.

Retrieving for each and merging the results beats one muddled search.

Multi-query generates several phrasings of the same question and unions the results.

That covers the case where the document uses different words than the user did.

HyDE takes a different angle by generating a hypothetical answer first.

That fake answer is embedded and used as the query.

It works because an answer resembles the documents more closely than a question does.

Every rewrite costs a model call before retrieval even starts, which adds latency.

Use a small fast model for it, since the task is simple.

Log the rewritten query, because a bad rewrite is invisible unless you look.

Want the full technical article? Wikipedia ↗
Test yourself

One question on this card. Every option explains itself once you pick, right or wrong.

Question 1
A user asks 'what about last year?' as a follow-up. What does the pipeline need?
RAG

19 concepts in this module, then a graded test with every answer explained.

Study this module →
↑↓ move↵ openesc close