Skip to content

LearnRetrieve

Query rewriting

Query reformulation

Using a language model to restate a vague, chatty or misspelled question as a clearer search query before retrieval.

In DocSlurpGlossary entry

On this page

Query rewriting sends the user’s question through a language model before search and searches with the result. “hey can we get the jet to london by tmrw am??” might become “private jet charter lead time to London Farnborough”. The rewrite drops filler, fixes spelling, spells out shorthand and uses words a document would use.

It helps most with conversational, misspelled or vague queries, and least with short keyword lookups, which are already in document form. A rewrite costs one model call, adding latency and tokens to every search.

The gotcha: a confident mistranslation

The model can’t ask what you meant. “Project Bravo” means the Larkspur Studio acquisition to your team; a rewrite might “clarify” it into something generic, or drop it as noise. Rewrites can also silently narrow a broad question or add assumptions. Two defenses:

  • Keep the original in play. Search with both the original and the rewrite and fuse the lists, or use the rewrite for only one branch of hybrid search.
  • Log the rewrite. When a search goes wrong, the effective query is the first thing to check.

In DocSlurp, queryRewrite is off by default. When enabled, the rewritten query drives the vector branch (and HyDE, if that is also on), while keyword search keeps the user’s exact words, so a bad rewrite can’t remove an exact identifier from the keyword side.

In DocSlurp

In DocSlurp

Off in default project retrieval settings; queryRewrite: true asks a model for one rewritten query (at most 100 output tokens) and keeps the original on failure (core/server/src/search/query-rewrite.ts). The rewrite feeds the vector branch and HyDE; the keyword branch still searches the original words (core/server/src/search/session-planner.ts).

Sources

Jump to