Optimizing Query Generation for Enhanced Document Retrieval in RAG

Hamin Koo, Minseon Kim, Sung Ju HwangarXiv 2024

Abstract

Large Language Models (LLMs) excel in various language tasks but they often generate incorrect information, a phenomenon known as "hallucinations". Retrieval-Augmented Generation (RAG) aims to mitigate this by using document retrieval for accurate responses. However, RAG still faces hallucinations due to vague queries. This study aims to improve RAG by optimizing query generation with a query-document alignment score, refining queries using LLMs for better precision and efficiency of document retrieval. Experiments have shown that our approach improves document retrieval, resulting in an average accuracy gain of 1.6%.

Introduction

Retrieval-Augmented Generation (RAG) has become the primary strategy for grounding Large Language Model (LLM) responses in external, verifiable data. Despite its success, RAG systems are highly sensitive to the quality of the initial user query. Vague or poorly phrased questions often lead to the retrieval of irrelevant documents, which in turn causes the LLM to hallucinate. To address this "garbage in, garbage out" challenge, we introduce QOQA (Query Optimization using Query expAnsion), a framework designed to iteratively refine search queries to maximize alignment with target documents.

The QOQA Framework

QOQA treats the LLM as an iterative optimizer that "evolves" a user's initial prompt into a high-precision search query. The framework operates through a feedback loop consisting of three primary stages:

  1. Query Expansion: The system retrieves the top-$N$ documents based on the original query. These documents are concatenated with the query to provide context for the LLM.
  2. Alignment Scoring: The LLM generates multiple rephrased queries. Each is assigned an "alignment score" based on its similarity to the retrieved document set. Scoring methods include Sparse (BM25), Dense (vector embeddings), or a Hybrid approach.
  3. Iterative Optimization: A "query bucket" stores rephrased queries and their scores. These are used as few-shot exemplars for the LLM, which is then tasked with generating a new query that maximizes the alignment score.
The QOQA framework architecture, illustrating the iterative loop between the retrieval model, query bucket, and LLM optimizer.

Experimental Setup

The effectiveness of QOQA was evaluated using three diverse datasets from the BEIR benchmark, representing different domains:

  • SciFact: Scientific claim verification.
  • Trec-Covid: Bio-medical information retrieval related to COVID-19.
  • FiQA: Financial question answering.

The experiments utilized GPT-3.5-Turbo as the optimizer and the BGE-base-en-v1.5 model for dense retrieval embeddings.

Results and Analysis

QOQA demonstrated consistent performance improvements across both sparse and dense retrieval architectures. On average, the framework achieved a 1.6% gain in nDCG@10 across the tested benchmarks.

Experimental results showing nDCG@10 scores for QOQA compared to baseline sparse and dense retrieval methods across SciFact, Trec-covid, and FiQA datasets.

Key findings include:

  • Peak Performance: In the SciFact dataset, QOQA achieved a top score of 75.4 using the BM25 alignment score with dense retrieval. In Trec-Covid, a hybrid scoring approach reached 79.2.
  • Vocabulary Bridging: Qualitative analysis showed that QOQA successfully bridges the vocabulary gap between user queries and technical documents. For instance, it rephrased "0-dimensional biomaterials" to "nano-sized," a term more prevalent in the source literature.
  • Optimization Value: Ablation studies confirmed that while initial expansion provides a baseline boost, the iterative optimization step is critical for reaching peak retrieval accuracy, especially in dense retrieval settings.

Discussion and Conclusion

While QOQA significantly improves retrieval precision, it introduces considerations regarding latency and cost. The current implementation relies on multiple LLM iterations (up to 50), which may be prohibitive for real-time production environments. Future research will focus on reducing the number of iterations through better "warm-start" queries and exploring the convergence properties of the optimization loop to prevent overfitting.

In conclusion, QOQA provides a robust mechanism for turning LLMs into "search engineers," systematically refining queries to ensure that RAG systems are grounded in the most relevant information possible.

Summary updated

BibTeX
@misc{koo2024optimizing,
  author = {Hamin Koo and Minseon Kim and Sung Ju Hwang},
  title = {{Optimizing Query Generation for Enhanced Document Retrieval in RAG}},
  year = {2024},
  eprint = {2407.12325},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2407.12325},
}
Figure