What is Query Rewrite
Query Rewrite is a pre-retrieval technique that transforms the user’s original query into one or more alternative query forms before sending them to the retrieval system.
查询重写是一种检索前技术,在将用户原始查询发送到检索系统之前,将其转换为一种或多种替代查询形式。
Imagine you’re asking a librarian for help. Instead of just saying “books about AI,” you might also say “machine learning texts,” “neural network resources,” and “deep learning guides” — because different books use different terminology. Query Rewrite is the LLM doing exactly that: generating multiple ways to ask the same question so the search system has better chances of finding relevant documents.
CN: 想象你在问图书管理员。你不仅说“AI相关的书”,还会说“机器学习书籍”、“神经网络资料”、“深度学习指南”——因为不同的书用不同的术语。查询重写就是让LLM做同样的事:生成多种问法,让检索系统有更大机会找到相关文档。
WHat is HyDE
Hypothetical Document Embeddings,假设性文档嵌入
HyDE is a specific query rewriting technique that generates a hypothetical (fake) answer document to the user’s query first, then embeds that generated document for similarity search — instead of embedding the query directly.
CN: HyDE 是一种特定的查询重写技术,它先生成一个假设性(虚构的)答案文档来回答用户查询,然后对该生成文档做嵌入用于相似度搜索——而不是直接嵌入原始查询。
Instead of asking “where can I find Italian food?” and searching for that question, HyDE first writes a fake Yelp review: “This Italian restaurant has amazing pasta and tiramisu…” — then searches for documents that look like that review. Because the review looks more like actual documents in the database than the question does.
CN: 不是直接问“哪里有好吃的意大利菜?”然后去搜这个问题。HyDE 先写一篇假的Yelp评论:“这家意大利餐厅的意面和提拉米苏超赞…” —— 然后去搜和这篇评论相似的文档。因为评论比问题本身更像数据库里的真实文档。
Query Rewrite 的核心内容
4.1 查询重写的四种主要类型
| 类型 | EN | CN |
|---|---|---|
| 改写 (Rewriting) | Rephrase the query for better embedding alignment | 改写查询以更好地对齐嵌入 |
| 扩展 (Expansion) | Add semantically related terms | 添加语义相关的术语 |
| 分解 (Decomposition) | Split complex queries into sub-queries | 将复杂查询拆分为子查询 |
| 多路生成 (Multi-Query) | Generate multiple query variants | 生成多个查询变体 |
4.2 多查询检索 (Multi-Query Retrieval) – Fan-Out
EN: Generate multiple query variants from the original, run them in parallel against the vector DB, merge and deduplicate results. This covers more angles of the user’s intent.
CN: 从原始查询生成多个变体,并行发送到向量数据库,合并并去重结果。这覆盖了用户意图的更多角度。
4.3 RRF (Reciprocal Rank Fusion)
EN: When merging results from multiple query variants, RRF scores documents by their rank positions rather than raw similarity scores — documents that appear high in multiple result lists get boosted.
CN: 合并多路查询结果时,RRF 按文档的排名位置而非原始相似度分数来打分——在多路结果中都排名靠前的文档获得加成。
HyDE works step
- Generate: Given a query, zero-shot prompt an LLM to generate a hypothetical document that answers the query
- Embed & Retrieve: Encode that hypothetical document and use it to retrieve real documents via vector similarity
Why this works: The hypothetical document is in the same style as real documents (declarative, detailed, expository). So its embedding lands closer to real document embeddings than the query embedding would.
CN – 为什么有效: 假设性文档与真实文档风格相同(陈述句、详细、说明性)。所以它的向量比查询向量更接近真实文档的向量。
Query Rewrite vs HyDE 对比
| 维度 | EN | CN |
|---|---|---|
| Query Rewrite | Rewrites the question | 改写问题 |
| HyDE | Generates a fake answer then embeds that | 生成假答案然后嵌入假答案 |
| Query Rewrite 目标 | Make the query easier to retrieve | 让查询更容易被检索 |
| HyDE 目标 | Make the embedding closer to document space | 让向量更接近文档空间 |
| Query Rewrite 开销 | 1 LLM call + N vector searches | 1次LLM调用 + N次向量搜索 |
| HyDE 开销 | 1 LLM call + 1 vector search | 1次LLM调用 + 1次向量搜索 |

