Vector DBs & RAG (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)
Advanced RAG Query Transformations: Query Rewriting, HyDE, and Multi-Query Generation.
senior LevelMost AskedForms
In Simple Words: Raw user queries are often vague, keyword-sparse, or poorly worded for semantic matching:
- Query Rewriting: An LLM reformulates the user prompt into a clear, standalone search query resolving pronouns and past conversational context.
- HyDE (Hypothetical Document Embeddings):
- Feed the user prompt to an LLM: "Write a hypothetical passage that answers this question".
- Embed the generated hypothetical answer, not the user question!
- The hypothetical answer lives in "document space" rather than "query space", dramatically improving cosine similarity matches with real source documents.
- Multi-Query Expansion: Generates 3-5 distinct keyword and semantic variations of the query, executes them in parallel, and merges candidate chunks via reciprocal rank fusion.