Single-Pass Document Scanning for Question Answering

Weili Cao, Jianyou Wang, Youze Zheng, Longtian Bao, Qirui Zheng, Taylor Berg-Kirkpatrick, Ramamohan Paturi, Leon Bergen

TL;DR

This paper introduces the "Single-Pass Document Scanner," a novel approach for question answering over extremely long documents. It processes entire documents in a single pass with linear time complexity, preserving global context and outperforming traditional chunk-based methods while being significantly more efficient than full-context transformers.

What Problem Does This Paper Address?

Answering questions from very long documents (hundreds of thousands of tokens) is a significant challenge. Standard transformer models struggle with this due to quadratic computational costs. Existing solutions like Retrieval-Augmented Generation (RAG) use chunking with embedding models, which can lose crucial global context. This paper addresses the need for a method that can efficiently process long documents while maintaining a holistic understanding of the content.

Methods

The core of the proposed solution is the Single-Pass Scanner, built upon the Mamba-2 architecture (a state-space model). Unlike traditional chunking methods, this scanner processes the entire document sequentially in a single pass, achieving linear scaling with document length. It uses a classification head to score sentences for relevance to the query, conditioned on the entire preceding context. This allows it to capture long-range dependencies and global coherence, which are often missed by chunk-based approaches. The paper also introduces a link-based synthetic data generation method to create training data, which leverages natural connections between document sections to generate more coherent and contextually relevant questions.

Datasets

The paper evaluates its approach on 41 QA benchmark test sets, categorized into educational, creative, official, and conversational types. These datasets cover a wide range of document lengths, from 1,000 to 780,000 tokens. For training, the authors utilize a novel link-based synthetic data generation strategy, which is contrasted with "chunk-based" and "pair-based" generation methods. The synthetic data is generated from various sources including Project Gutenberg, government reports, finance documents, and legal contracts.

Key Insights and Ideas

  • Global Coherence is Key: The paper strongly emphasizes that preserving global coherence is paramount for long document QA, and chunking inherently breaks this. The single-pass approach directly tackles this limitation.
  • State-Space Models Shine for Long Context: The success of the Mamba-2 architecture in enabling efficient, linear-time processing of long sequences is a significant finding, suggesting SSMs are a promising direction for this problem.
  • Synthetic Data Matters: The development and effectiveness of the link-based synthetic data generation method highlight the importance of carefully crafted training data for teaching models to leverage long-range dependencies. This method outperforms simpler generation strategies.
  • Efficiency Gains are Substantial: The Single-Pass Scanner achieves competitive or superior accuracy to state-of-the-art methods while using a fraction of the computational cost (FLOPs) and being significantly faster.

Key Results

  • The Single-Pass Scanner consistently outperforms chunk-based embedding methods across 41 QA benchmarks.
  • It competes with large language models (like GPT-40) at a fraction of the computational cost.
  • For documents longer than 256k tokens, the Single-Pass Scanner achieves performance close to GPT-40's full-context capabilities, despite being much smaller.
  • The SPScanner 1.3B model is faster and uses fewer FLOPs than embedding models while achieving higher accuracy. For example, it processes documents significantly faster than NV-Embed-v2-7B.
  • The link-based synthetic data generation strategy leads to stronger results compared to chunk-based and pair-based generation.

Limitations and Future Work

  • "Lost in the Middle" Phenomenon: While the paper investigates this, it notes that the Single-Pass Scanner shows a decreasing recall for the last 10% of relative positions (end of the document), suggesting it might struggle with information at the very end. However, it doesn't exhibit the classic "lost in the middle" pattern.
  • Generative Models vs. Discriminative Models: The paper notes that generative models for sentence selection are significantly worse than discriminative models like the SPScanner, suggesting a lossy approach in long-context settings.
  • Direct Answer Generation: Training state-space models to directly answer questions from full contexts is shown to be challenging and results in substantially lower performance compared to the SPScanner's retrieval-then-generation approach.
  • Future Work: The authors suggest further exploration into improving performance at the end of documents and potentially adapting the approach for other long-context NLP tasks. The availability of code and datasets encourages further research in this area.

Summary updated

BibTeX
@inproceedings{cao2025single,
  author = {Weili Cao and Jianyou Wang and Youze Zheng and Longtian Bao and Qirui Zheng and Taylor Berg-Kirkpatrick and Ramamohan Paturi and Leon Bergen},
  title = {{Single-Pass Document Scanning for Question Answering}},
  booktitle = {COLM},
  year = {2025},
  url = {https://openreview.net/forum?id=7Vj78acKIp},
}
Figure