UncertaintyRAG: Span-Level Uncertainty Enhanced Long-Context Modeling for Retrieval-Augmented Generation

Zixuan Li, Jing Xiong, Fanghua Ye, Chuanyang Zheng, Xun Wu, Jianqiao Lu, Zhongwei Wan, Xiaodan Liang, Chengming Li, Zhenan Sun, Lingpeng Kong, Ngai WongarXiv 2024

Abstract

We present UncertaintyRAG, a novel approach for long-context Retrieval-Augmented Generation (RAG) that utilizes Signal-to-Noise Ratio (SNR)-based span uncertainty to estimate similarity between text chunks. This span uncertainty enhances model calibration, improving robustness and mitigating semantic inconsistencies introduced by random chunking. Leveraging this insight, we propose an efficient unsupervised learning technique to train the retrieval model, alongside an effective data sampling and scaling strategy. UncertaintyRAG outperforms baselines by 2.03% on LLaMA-2-7B, achieving state-of-the-art results while using only 4% of the training data compared to other advanced open-source retrieval models under distribution shift settings. Our method demonstrates strong calibration through span uncertainty, leading to improved generalization and robustness in long-context RAG tasks. Additionally, UncertaintyRAG provides a lightweight retrieval model that can be integrated into any large language model with varying context window lengths, without the need for fine-tuning, showcasing the flexibility of our approach.

Introduction

Large Language Models (LLMs) are increasingly deployed for long-context tasks, such as summarizing extensive documents or cross-document question answering. However, these applications face two primary challenges: computational overhead and the "chunking" problem in Retrieval-Augmented Generation (RAG). Standard RAG pipelines split long texts into discrete chunks; if these splits occur randomly, they often disrupt semantic coherence, making it difficult for retrieval models to identify relevant information. Existing solutions typically require massive labeled datasets or expensive LLM fine-tuning, and often struggle with distribution shifts when encountering unfamiliar data types.

Methodology

UncertaintyRAG addresses these challenges by introducing SNR-based Span Uncertainty. This approach utilizes the internal state of the LLM to guide the retrieval process without requiring human-labeled data.

SNR for Calibration

Rather than relying on raw token probabilities, the researchers calculate the Signal-to-Noise Ratio (SNR) of the model's self-information (negative log-likelihood) within a sliding window. They observed that when two text chunks are semantically aligned, the SNR stabilizes, providing a more reliable indicator of semantic alignment than standard entropy.

Unsupervised Contrastive Learning and Scaling

By using the LLM's internal certainty (via SNR) to judge chunk alignment, the system generates its own training pairs. This unsupervised contrastive learning is paired with a K-Nearest Neighbors (KNN) clustering strategy to sample diverse "anchor" chunks from various datasets. This allows the model to learn complex semantic structures from a relatively small but highly diverse corpus.

Overview of the UncertaintyRAG training and scaling pipeline, illustrating the SNR-based uncertainty calculation and the anchor scaling strategy.

Experimental Setup

The model was trained and scaled using a diverse mix of datasets, including HotpotQA, MultiFieldQA, Qasper, NarrativeQA, and QMSum. To test generalization and robustness against distribution shifts, evaluation was conducted in a zero-shot setting on datasets the model had never seen during training: 2WikiMultihopQA, Musique, TREC, TriviaQA, and SAMSum.

Key Results

UncertaintyRAG demonstrates significant improvements in both performance and efficiency over established baselines:

  • Performance Gains: The model outperformed baselines on LLaMA-2-7B by an average of 2.03% across long-context tasks.
  • Data Efficiency: UncertaintyRAG achieved state-of-the-art results using only 7 million paired texts—just 4% of the training data used by models like BGE-M3 (which uses ~184 million).
  • Superior Calibration: In uncertainty calibration tests (measured by AUROC), the SNR-based method significantly outperformed traditional metrics like Entropy, indicating that the model has a much more accurate internal representation of its own certainty.
Performance comparison of UncertaintyRAG against various retrieval models across multiple datasets and LLM engines.

Discussion and Insights

The core insight of this work is that SNR acts as a "semantic compass," filtering out linguistic redundancy to focus on core meaning. The researchers found that scaling positive/negative samples primarily improves the "uniformity" of the embedding space, while scaling "anchor" samples improves the "alignment" of related items.

Despite its successes, the model faces limitations in few-shot learning scenarios (e.g., TREC), likely due to the difficulty of segmenting in-context exemplars within the retrieval window. Future work may explore dynamic, uncertainty-aware chunking during the inference phase and testing across non-transformer architectures.

Conclusion

UncertaintyRAG provides a lightweight (110M parameters), plug-and-play retrieval model that significantly improves long-context RAG performance. By leveraging the internal uncertainty of LLMs through SNR, it offers a highly data-efficient path toward robust and well-calibrated retrieval systems.

Summary updated

BibTeX
@misc{li2024uncertaintyrag,
  author = {Zixuan Li and Jing Xiong and Fanghua Ye and Chuanyang Zheng and Xun Wu and Jianqiao Lu and Zhongwei Wan and Xiaodan Liang and Chengming Li and Zhenan Sun and Lingpeng Kong and Ngai Wong},
  title = {{UncertaintyRAG: Span-Level Uncertainty Enhanced Long-Context Modeling for Retrieval-Augmented Generation}},
  year = {2024},
  eprint = {2410.02719},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2410.02719},
}
Figure