liveBook · Manning

Query rewriting

As explained in Grokking AI Applications

A technique that rephrases a user query to improve its semantic match with retrievable document content.

Query rewriting rephrases a user’s question so its meaning aligns more closely with the language stored in retrievable document chunks. It uses an LLM before vector similarity search. section 4.3

A query-rewriting workflow can address several retrieval problems:

  • Rephrase vague wording into language likely to match the documents. section 4.3
  • Generate hypothetical answer text and search with it using HyDE. section 4.3
  • Translate the query when the question and documents use different languages. section 4.3

From thirst to drinks

A user asks, “What should I order if I’m thirsty?” A rewriting prompt can produce language about drinks before the system searches a menu, improving the chance of matching the relevant section. section 4.3

How Grokking AI Applications covers it

How deep it goes
Explains the rationale, HyDE variant, translation use, and Langflow placement without detailing prompt design or evaluation.
Examples
Uses a thirsty-customer menu question, hypothetical answers, and English-to-Spanish query translation.
What it assumes
Assumes familiarity with user queries, document chunks, LLMs, and vector similarity search.
What you can do after
Apply it via Langflow by placing a Prompt Template and LLM between Chat Input and ChromaDB.
How it connects
Connects LLMs, vector similarity search, RAG, embeddings, HyDE, prompt templates, and ChromaDB.

Also explained in

Compare how 5 books explain query rewriting →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking AI Applications. The section links point to the parts of the book it draws on.