Get Started

Query Rewriting: HyDE, Multi-Query, and Decomposition

The query the user types is not the query your retriever wants. Rewriting bridges the gap before retrieval, so the index sees something closer to what the answer looks like.

90 minutesBuildPythonMembers

Learning Objectives

  • Implement Hypothetical Document Embeddings (HyDE): generate a fake answer, embed it, retrieve against that vector instead of the query vector.
  • Implement multi-query expansion: rewrite one query into N paraphrases, retrieve with each, merge the union by reciprocal rank fusion.
  • Implement query decomposition: split a complex question into sub-questions, retrieve per sub-question, merge.
  • Compare the three rewriters head to head on a fixture and explain when each strategy wins.
  • Wire a mock LLM that produces deterministic, on-fixture outputs so the rewriter loop runs offline.