Query rewriting for RAG: expansion, decomposition and HyDE, explained simply

Originally published at https://pranjulrathour.scult.in/blog/query-rewriting-and-hyde-for-retrieval. That copy is the canonical version and gets updates first.
Retrieval is only as good as the query it receives, and users write queries like "that thing about refunds after 30 days for the premium plan". The document says "Refund eligibility: Premium subscribers, 30-day window". Bridging that gap before retrieval is query rewriting, and it is cheaper than most people expect.
Expansion: more words for the same meaning
Ask a small model to produce two or three alternative phrasings of the question, run retrieval on all of them, and merge with Reciprocal Rank Fusion — the same merge used in hybrid retrieval. Expansion helps most when the corpus uses formal vocabulary and users do not.

Decomposition: one question at a time
"Compare the refund policy for premium and basic plans" is two retrievals. Split it into sub-questions, retrieve for each, and give the model both contexts labelled. Without decomposition, the retriever returns whichever plan is mentioned more often and the comparison is invented.
HyDE: retrieve with a guess
Hypothetical Document Embeddings has the model write a short, plausible answer first, then embeds that answer to search with. The hypothetical text is closer in style to real passages than the question was, so it often retrieves better. The catch: if the model's guess is wrong in vocabulary, retrieval follows it off a cliff. Use it alongside the original query, never instead of it.

How to know if it helped
- Run your evaluation set with and without each rewrite step and compare recall@5.
- Log the rewritten queries in production and read a sample weekly — you will find rewrites that change the meaning.
- Measure added latency; an extra model call before retrieval is fine for chat, not for autocomplete.
What I actually run
For most document-QA products: hybrid retrieval on the original query plus one expansion, decomposition only when a classifier flags a multi-part question, and no HyDE by default. Simple systems with good chunking beat clever ones with bad chunks, every time.
![]() | Pranjul Rathour GenAI engineer, Kanpur · 3x first-prize hackathon winner · campus mentor I ship production RAG pipelines, fine-tune LLMs and build agentic AI products end to end. I lead engineering at SCULT INDIA for a 14-member team and have mentored 200+ students through TechVerse Enclave. Open to: GenAI roles, hackathon judging, mentorship sessions and guest talks at colleges. Email: pranjulrathour41@gmail.com |
![]() In a packed college auditorium | ![]() Pranjul Rathour | ![]() On the mic |








Comments
Post a Comment