Query Rewriting

Definition

Query rewriting is the family of techniques that transform a user’s original query into a different formulation better suited to what the search system can actually serve. It is the pivot point of Query Understanding: everything upstream works out what the user meant, and rewriting is where that interpretation is committed to an executable query.

The goal is always to close the gap between how the user expressed their intent and how the system can best satisfy it.

Why Rewrite

Different rewriting strategies address different failure modes:

ProblemStrategyRelated
Query too narrow — too few resultsAdd termsQuery Expansion
Query too specific — Zero ResultsDrop or loosen termsQuery Relaxation
Equivalent expressions differ in surface formNormalizeSynonyms
The query contains errorsCorrectSpelling Correction
Multi-word units are being tokenised wronglyGroupQuery Segmentation

How Rewrites Are Produced

Three broad sources, increasing in flexibility and decreasing in predictability:

  • Hand-crafted rules — reliable for well-understood, high-traffic patterns.
  • Learned from logs — historical query and click data mined for reformulations users make themselves.
  • Model-generated — models trained on reformulation tasks. An agent holding user context can also produce the rewrite at query time; see the memory-driven case below.

Measuring It

Impact has to be read across three quantities at once: recall, precision, and the fraction of queries actually affected. The governing constraint is that rewriting which helps the tail must not damage the head — a rewrite that rescues rare queries while degrading the most common ones is a net loss, and aggregate metrics can easily hide that.

Personalized and Memory-Driven Rewriting

Rewriting is also the natural place to apply per-user context. In the Agentic Memory pattern, preferences held in memory are injected into the query itself — backpack becomes backpack leather neutral professional — so that personalization happens before retrieval rather than as a re-ordering afterwards. This shifts rewriting from a static, corpus-level transformation to a per-user one.

Two practical constraints surface in that setting:

  • Prefer soft signals to hard filters when the rewrite is driven by inferred preference rather than explicit user input, since a preference is evidence rather than a constraint.
  • Express negative preferences affirmatively where the rewritten query feeds an embedding model, because such models handle negation poorly.

Because a rewrite can lose information the ranker still needs, the same context is often supplied to the rerank stage as well.

Articles

Videos

Topics