Abstract
We deal with the problem of Question Answering (QA) over a long document, which poses a challenge for modern Large Language Models (LLMs). Although LLMs can handle increasingly longer context windows, they struggle to effectively utilize the long content. To address this issue, we introduce the concept of a virtual document (VDoc). A VDoc is created by selecting chunks from the original document that are most likely to contain the information needed to answer the user’s question, while ensuring they fit within the LLM’s context window. We hypothesize that providing a short and focused VDoc to the LLM is more effective than filling the entire context window with less relevant information. Our experiments confirm this hypothesis and demonstrate that using VDocs improves results on the QA task.
Introduction
Modern Large Language Models (LLMs) like Gemini and Claude have expanded context windows to support hundreds of thousands of tokens. However, this expansion has revealed a significant performance bottleneck known as the "lost in the middle" phenomenon. As context length increases, models often fail to prioritize relevant information, especially when it is buried deep within irrelevant "noise." This paper addresses this efficiency gap by proposing a method to "distill" long documents into shorter, high-density versions called Virtual Documents (VDoc). Instead of expanding the context window indefinitely, the goal is to build a "better haystack" that maximizes the model's reasoning capabilities.
Methodology
The VDoc pipeline consists of three primary stages: Document Segmentation, Segment Ranking, and VDoc Reconstruction.
- Document Segmentation: The source document is divided into 512-token chunks. The authors explored standard sliding window techniques and semantic segmentation, which leverages HTML structures like headers and titles to define logical passages.
- Segment Ranking: Chunks are ranked based on their relevance to the user's query. Three ranking strategies were evaluated: Dense (MiniLM vector embeddings), Sparse (Elser expansion-based search), and Perplexity (using Flan-T5 to measure how "surprised" the model is by the question given a segment).
- VDoc Reconstruction: The highest-ranked segments are reassembled into a new document. A key finding was that maintaining the original Doc order of segments generally outperforms Rank order, suggesting that LLMs benefit from the natural narrative or logical flow of the original text.
Experimental Setup
The researchers evaluated the VDoc approach across three diverse datasets:
- GoogleNQ: Wikipedia-based questions where the answer is a specific section.
- Qasper: A dataset of questions based on full-length research papers.
- NarrativeQA: Part of the ZeroScrolls benchmark, featuring questions about entire books and movie scripts.
Results and Discussion
The experiments yielded several critical insights. First, "less is more": for datasets like Qasper, a 4800-token window outperformed larger contexts. Providing a focused, high-density context is more effective than overwhelming the model with low-relevance data. Second, sparse ranking via Elser proved highly effective, particularly when paired with semantic segmentation.
The efficiency gains are equally significant. As shown in Figure 4, while F1 performance peaks at a certain context size (around 7.2K tokens), the inference time increases dramatically as more tokens are added. For instance, with Llama-3-70b, processing 500 examples took 28 minutes with a 7.2K VDoc compared to 125 minutes with a 64K context window. VDoc achieved superior accuracy in roughly one-fourth of the time. On the NarrativeQA dataset, using VDoc with a Llama-3-8b-instruct model led to a 41% improvement in F1 score compared to a naive prefix baseline.
Conclusion
VDoc demonstrates that selective context distillation is a powerful strategy for long-document QA. By prioritizing relevance and maintaining logical order, VDoc improves F1 scores—by up to 58% on NarrativeQA for some models—while drastically reducing computational costs. Future work will focus on scaling semantic segmentation to unstructured text and exploring the application of VDoc principles to multi-document retrieval-augmented generation (RAG) systems.
Summary updated