Query2Doc
What it is
Query2Doc (Wang et al., 2023) improves retrieval by expanding the query with a few-shot LLM-generated pseudo-document rather than replacing it. The expanded query (original query + generated passage) is then used with BM25 or a dense encoder. Unlike HyDE, which embeds only the generated text, Query2Doc concatenates original and generated text, preserving the exact query terms while adding semantic context.
[illustrate: Query + few-shot prompt → LLM → pseudo-document → concatenate with original query → BM25 or dense retrieval]
How it works
-
Few-shot prompt:
Q: {example_query_1} A: {example_answer_1} Q: {example_query_2} A: {example_answer_2} Q: {query} A: -
Generation:
- LLM generates a short pseudo-document (answer-like passage)
-
Query expansion:
- For BM25: concatenate query + pseudo-document as the query string
- For dense: encode the concatenated text as the query vector
-
Retrieval:
- Standard BM25 or ANN retrieval with the expanded query
Variants and history
Query2Doc (2023) showed improvements on MSMARCO and TREC DL for both sparse and dense retrieval. Compared to HyDE: Query2Doc retains the original query terms (important for entity-heavy or code queries), while HyDE discards them. Step-Back Prompting and Chain-of-Thought Retrieval are related expansions. In practice, HyDE and Query2Doc often have complementary strengths.
When to use it
Use Query2Doc when:
- LLM is available for query-time inference
- Original query terms must be preserved (entities, technical terms)
- Both sparse and dense retrieval are in use (Query2Doc helps both)
- Few-shot examples for the domain are available