Retrieval-Augmented Generation104 · Module III · Lesson 09 of 13
Article · 12 min

Query rewriting and expansion

Preprocessing the question before touching the index.

Summary

Query rewriting: transform the user's query before retrieval. Expansion: generate multiple related queries and retrieve for each. Both address the mismatch between how users write queries and how documents are worded.

Objectives
  • 01Describe HyDE (hypothetical document embeddings).
  • 02Distinguish rewriting from expansion.
  • 03State the cost/quality tradeoff.
The Lesson

Rewriting

Ask an LLM to rephrase the query for retrieval: expand abbreviations, add context, disambiguate. Cheap, effective for short conversational queries. HyDE: generate a hypothetical answer document, embed it, retrieve documents similar to that — retrieval matches document distributions rather than query distributions.

Expansion

Generate 3-5 related queries and retrieve for each; union the results. Improves recall at 3-5x the retrieval cost. Combine with reranking to prune the expanded candidate set.

Key Ideas
  • Users write queries; documents are written differently.
  • HyDE bridges the gap by embedding hypothetical answers.
References
  • Gao et al., 'Precise Zero-Shot Dense Retrieval without Relevance Labels' (HyDE, 2022)