r/learnmachinelearning • u/DueBid3298 • 25d ago
Question why do we need query expansion in RAG when semantic search already handles similar value matching?
8
Upvotes
r/learnmachinelearning • u/DueBid3298 • 25d ago
2
u/Massive_Distance_616 25d ago
Semantic search finds text that’s close in meaning to the query as written, but the query is often short or phrased differently from how the documents say it. A user might type “reset password” while the doc says “recover account credentials”, or ask something vague that has several sub-topics.
Query expansion fixes that on the query side: you rewrite it into several variants (synonyms, a hypothetical answer as in HyDE, or sub-questions) and retrieve for each one, so you’re less likely to miss a relevant chunk. It also helps with acronyms and domain terms that the embedding model handles poorly.
It isn’t always worth it. It adds an LLM call and latency, and a bad rewrite can drift from what the user actually asked. On a well-embedded corpus with natural-language questions the gain can be small. I’d measure retrieval recall with and without it on a few dozen real queries before adding it.
2
u/GiggleSamurai 25d ago
Two common techniques: multi-query (the LLM writes 3–5 rephrasings, you search each and merge the results with reciprocal rank fusion) and HyDE (embed an LLM-written hypothetical answer instead of the question, since an answer sits closer to the documents in embedding space than a short question does).
2
u/Rose_DreamersInc 23d ago
Semantic search is already pretty solid, but it's still limited if the search terms used isn't the exact wording or phrasing. Query expansion expands on it by ensuring that related terms can be used to expand the search, so that even if you don't recall the exact term, just being close to it can help you find what you're looking for. This makes it better for jargon-heavy searches, where you might forget this specific term, but know what it means, allowing you to still have an effective search term thanks to how it provides a wider pool of results.