Query2doc: Query Expansion with Large Language Models

Liang Wang, Nan Yang, Furu Wei

Abstract

This paper introduces a simple yet effective query expansion approach, denoted as query2doc, to improve both sparse and dense retrieval systems. The proposed method first generates pseudo-documents by few-shot prompting large language models (LLMs), and then expands the query with generated pseudo documents. LLMs are trained on web-scale text corpora and are adept at knowledge memorization. The pseudo-documents from LLMs often contain highly relevant information that can aid in query disambiguation and guide the retrievers. Experimental results demonstrate that query2doc boosts the performance of BM25 by 3% to 15% on ad-hoc IR datasets, such as MS-MARCO and TREC DL, without any model fine-tuning. Furthermore, our method also benefits state-of-the-art dense retrievers in terms of both in-domain and out-of-domain results.

1. Introduction

In Information Retrieval (IR), the "lexical gap" remains a significant challenge: user queries are often short, ambiguous, and lack the context necessary to match relevant documents that may use different terminology. Traditional techniques like Pseudo-Relevance Feedback (PRF) attempt to mitigate this by expanding queries using top-ranked documents from an initial search. However, PRF is sensitive to the quality of the initial retrieval; if the first pass is poor, the expansion introduces noise.

Query2doc proposes a novel alternative: leveraging the internal knowledge of Large Language Models (LLMs) to generate context. By treating an LLM as a knowledge proxy, the system generates a "pseudo-document" that provides the necessary lexical variety and context to bridge the gap between the query and the target documents.

2. Methodology

The Query2doc pipeline is a "plug-and-play" method consisting of two primary stages:

2.1 Pseudo-document Generation

Given a query $q$, the system employs few-shot prompting to guide an LLM in generating a relevant passage. By providing a small number of examples (e.g., 4 pairs of queries and passages), the LLM learns to produce a detailed answer that serves as a pseudo-document $d'$.

Few-shot prompting and LLM output example for pseudo-document generation.

2.2 Query Expansion

The original query $q$ and the generated pseudo-document $d'$ are concatenated to form an expanded query $q^+$.

  • Sparse Retrieval (BM25): To prevent the longer pseudo-document from overwhelming the original query terms, the query $q$ is repeated $n$ times (typically 5) before concatenation.
  • Dense Retrieval: The query and pseudo-document are concatenated using a separator token and processed by a standard dual-encoder architecture.

3. Experimental Evaluation

The effectiveness of Query2doc was evaluated on several standard IR benchmarks:

  • In-domain: MS-MARCO passage ranking, TREC DL 2019, and TREC DL 2020.
  • Out-of-domain (Zero-shot): Five datasets from the BEIR benchmark (DBpedia, NFCorpus, Scifact, Trec-Covid, and Touche2020) to test generalization across specialized domains.

4. Results and Analysis

The experimental results demonstrate substantial improvements across both sparse and dense retrieval paradigms.

4.1 Performance Gains

As shown in the results table, Query2doc significantly enhances BM25 performance by 3% to 15% without any fine-tuning. For instance, on TREC DL 2019, the nDCG@10 improved from 51.2 to 66.2. Dense retrievers also saw consistent, albeit more modest, improvements.

Main results comparing Query2doc against various retrieval baselines on MS MARCO and TREC DL.

4.2 Key Insights

  • Scaling Effects: Performance scales positively with the size of the LLM. Moving from 1.3B parameters to 175B (davinci-003) and eventually GPT-4 yields continuous improvements in retrieval accuracy.
  • Complementary Strengths: Analysis reveals that the combination of the original query and the pseudo-document outperforms using either in isolation. The original query maintains user intent, while the pseudo-document provides the necessary lexical expansion.
  • Robustness: Unlike PRF, Query2doc does not depend on an initial retrieval step, making it more robust for difficult queries where traditional systems might fail to find any relevant documents initially.

5. Conclusion and Future Work

Query2doc presents a simple yet powerful method for query expansion using LLMs. While the method achieves state-of-the-art results, the primary limitation is the computational latency and cost associated with LLM inference, which currently exceeds the requirements for real-time web search. Future research will focus on improving the efficiency of pseudo-document generation, perhaps through model distillation or more selective prompting strategies.

Summary updated

BibTeX
@inproceedings{wang2023query,
  author = {Liang Wang and Nan Yang and Furu Wei},
  title = {{Query2doc: Query Expansion with Large Language Models}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2023},
  url = {https://openreview.net/forum?id=QH4EMvwF8I},
}
Figure