Abstract
Large Language Models (LLMs) encounter significant challenges when processing ultra-long documents, often suffering from semantic fragmentation due to fixed-length chunking and performance degradation in the "middle" of long contexts. This paper introduces Dynamic Chunking and Selection (DCS), a framework designed to preserve semantic coherence and efficiently retrieve relevant information. By utilizing semantic similarity for boundary detection and a lightweight, question-aware classifier for chunk selection, DCS enables models to maintain high accuracy across context windows as large as 256k tokens.
Introduction
Modern LLMs theoretically support massive context windows, yet they frequently struggle with the "lost-in-the-middle" phenomenon and the high computational costs of quadratic attention. A common mitigation strategy involves splitting long texts into fixed-length chunks (e.g., 512 tokens). However, this often breaks critical semantic concepts across boundaries, leading to retrieval failures. DCS addresses this by ensuring that context compression does not destroy the underlying semantic "glue" of the document.
Methods: The DCS Framework
The DCS framework operates through two primary stages to optimize context for the backbone LLM:
- Dynamic Chunking: Instead of arbitrary cuts, DCS employs Sentence-BERT to generate embeddings for every sentence. It calculates semantic similarity between adjacent sentences, placing boundaries where similarity is lowest to respect natural topic shifts.
- Question-Aware Selection: To handle documents up to 256k tokens, a small Multi-Layer Perceptron (MLP) classifier scores each chunk's relevance to the user's query. To maintain efficiency, DCS uses feature distillation, extracting internal representations from the LLM to feed the classifier, avoiding the cost of full model inference for every chunk.
The top-scoring chunks are reassembled in their original order and provided to the LLM (e.g., Llama-3 or Mistral) for final response generation.
Experimental Setup
The researchers evaluated DCS across 12 long-context benchmarks, including:
- Single-hop QA: MultiFieldQA, NarrativeQA, and Qasper.
- Multi-hop QA: HotpotQA, 2WikiMQA, and Musique.
- Ultra-Long Contexts: Datasets were extended to context lengths ranging from 16k to 256k tokens.
The classifier was trained on standard QA datasets such as AdversarialQA, CoQA, and SQuAD to ensure broad generalization across unseen benchmarks.
Key Results and Discussion
DCS demonstrated significant performance gains across various models and tasks:
- Accuracy Improvements: On single-hop QA, DCS achieved a 28.62% improvement over the best baseline for Llama-3. Multi-hop reasoning tasks saw a 20.02% improvement.
- Scalability: Unlike baseline methods that degrade sharply beyond 64k tokens, DCS remains stable up to 256k tokens. This suggests that intelligent selection is more effective than sparse attention for ultra-long contexts.
- Efficiency: By reducing the token count for the final LLM pass, DCS maintains a latency profile comparable to existing long-text approaches while delivering superior accuracy.
Conclusion and Future Work
DCS provides a robust solution for ultra-long context reading comprehension by prioritizing semantic integrity and relevance. While highly effective for 7B-8B parameter models, future work will explore its application to larger frontier models and a broader variety of tasks, such as long-form summarization and code analysis. Additionally, refining the sensitivity of the segmentation threshold remains an area for further optimization.
Summary updated