Skip to content

Query Rewriting

Abstract

Query rewriting — a technique where the model rephrases the user's question before searching the knowledge base: making it clearer, more detailed, or breaking it into several search queries.

Why is it Needed

Users rarely formulate questions perfectly. They might ask:

"What about the warranty?"

Without context, it's unclear:

  • which product is being referred to;
  • in which country;
  • for which date.

If you run vector search on such a question right away, the result will be weak. Therefore, the query is first rewritten.

How it Works

Before searching, an additional step is performed:

  1. Take the original user question.
  2. Ask the LLM to rephrase it.
  3. Get one or several clear queries.
  4. Run these queries through vector search.
  5. Combine the results.

Examples of Rephrasing

Original Question Improved Query
What about the warranty? What are the warranty conditions for motor X in 2025?
How do I set this up? How do I set up DeepSeek API connection in Cherry Studio?
Why is it so expensive? What factors influence the cost of tokens when using the API?

Main Techniques

1. Simple Rephrasing

The LLM transforms a short question into a full and unambiguous one.

2. Step-back Question

Formulate a more general question:

Not "How much does Qdrant cost?", but "What are the ways to store vectors and how much do they cost?"

3. Multi-query

The LLM generates several question variants and runs search on each.

4. HyDE

The LLM first invents a hypothetical answer, and then searches for documents similar to this answer. This helps when the question formulation is very different from the document text.

Pros and Cons

Pros Cons
Better search quality Additional delay
Clearer short questions Token usage for rephrasing
More chances to find what you need Carefully write prompts

See Also