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

Raw Question → Transformer Rewrite and Split ↗ → ↘ Refined Query A Refined Query B Refined Query C → Search and Merge Best Passages

Common Techniques

TechniqueWhat It DoesBest Fit
RewritingTurns a vague question into a clear, complete oneChat conversations with pronouns
Multi-query expansionCreates several versions with different wordingTopics with many synonyms
DecompositionSplits one complex question into smaller questionsQuestions that need several facts
Step-back promptingAsks a broader question to gather backgroundQuestions that need general principles
Hypothetical answer searchDrafts a short imagined answer and searches with itShort 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.