RAG Query Transformation
Query transformation rewrites a user question into a better search request before retrieval begins. People type short, vague, or incomplete questions. Search works best with clear, specific wording. A transformation step bridges that gap and lifts the quality of retrieved passages.
Why Raw Questions Fall Short
Consider the question, "Can I take it abroad?" The words "it" and "abroad" carry no clear meaning without the earlier conversation. A search engine receives those few words and returns scattered results. A rewritten question such as "Can employees take company laptops outside the country?" gives the search step real substance.
A Librarian Analogy
A visitor walks up to a librarian and mumbles, "I need that book about the thing." A skilled librarian asks clarifying questions and writes a precise request: title, topic, and year. The librarian then checks several shelves. Query transformation performs that clarifying work automatically.
From One Question to Many Searches
Common Techniques
| Technique | What It Does | Best Fit |
|---|---|---|
| Rewriting | Turns a vague question into a clear, complete one | Chat conversations with pronouns |
| Multi-query expansion | Creates several versions with different wording | Topics with many synonyms |
| Decomposition | Splits one complex question into smaller questions | Questions that need several facts |
| Step-back prompting | Asks a broader question to gather background | Questions that need general principles |
| Hypothetical answer search | Drafts a short imagined answer and searches with it | Short questions with little detail |
A Practical Example
A user asks, "How does our parental leave compare with the standard remote work allowance?" One search for that whole sentence returns a muddled mix. Decomposition splits it into two questions: "What is the parental leave policy?" and "What is the remote work allowance policy?" Each question retrieves its own focused passage. The model reads both and builds a clear comparison.
Using Conversation History
Chat assistants carry earlier messages. The transformer reads those messages and replaces vague words such as "it," "that," and "they" with the actual subject. A follow-up like "What about contractors?" becomes "What is the parental leave policy for contractors?" Good rewriting keeps long conversations accurate.
Trade-Offs
- Each transformation adds a model call, which adds a little time and cost.
- Too many generated queries can bring in unrelated passages.
- Rewrites can drift away from the user's real intent.
- Simple, clear questions often need no transformation at all.
Habits That Help
- Log original and rewritten queries side by side for review.
- Limit expansion to a small number of variations.
- Keep the user's key terms inside every rewrite.
- Test with real questions collected from users.
When to Skip Transformation
Some systems answer short, precise questions such as "What is the office Wi-Fi password policy?" The original wording already matches the document title, so a rewrite adds delay without benefit. Teams often route only unclear or complex questions through the transformer and send clean questions straight to search. A simple length or clarity check can make that decision automatically.
Measuring the Benefit
Teams compare retrieval results with and without transformation on the same set of test questions. They count how often the correct passage appears in the top results. A technique that raises that count earns a permanent place in the pipeline. A technique that changes nothing gets removed to save time and cost.
Key Takeaway for Beginners
Better questions produce better retrieval. Rewrite vague input, expand wording, and split complex requests into parts. Apply these steps with care, and measure whether they improve answers for real users.
