RAG Optimization · Module 03
Query Transformations
Rewrite the question before searching: hypothetical document embeddings, decomposing a complex question, multi-query, step-back prompting and routing.
Học xong bạn làm được
- Implement HyDE and explain why it helps
- Decompose a multi-intent question into sub-questions
- Use multi-query generation and step-back prompting
- Route a query to the right index or tool
Bài học
- Query Transformations: HyDE
Real users type short, context-free or multi-part questions, such as "remote work", whose vectors do not match detailed documents. Query transformation uses an LLM to rewrite, expand or break down the question before searching. HyDE asks the LLM for a hypothetical answer and searches with its embedding, bridging the asymmetry between short questions and long documents.
- Query Decomposition
A complex question that compares or aggregates information from several sources has a vector stuck between topics. Query decomposition has an LLM break it into single-intent sub-questions, retrieves for each one, and synthesises the results into one answer. Query transformation as a whole acts as an intelligent editor of the user's question.
- Additional Query Transformation Techniques: Multi-Query and Step-Back
Multi-query generation has the LLM write 3-5 phrasings of a question, searches with each and merges and de-duplicates the results, raising recall. Step-back prompting first asks a more abstract question, so retrieval finds the principles that the specific answer depends on.
- Query Routing
Query routing is a pre-retrieval decision rather than a transformation - a lightweight LLM classifier sends each query to the backend that suits it - vector store for semantic similarity, web search such as Tavily for current events, SQL for aggregation over structured records, code search for exact symbols. Without it, every query hits one backend and some fail silently.
- Assignment: Query Transformation
Query Transformation with HyDE and Decomposition