Why LLMs Can't Read Entire Long Documents: A Technical Look at Context Length Limits and How to Work Around Them
This article explains why large language models often process only part of a long document, even when a model advertises a large context window. It covers the compute cost of attention, KV cache memory pressure, prefix caching and token billing, and product-level limits. It also outlines practical approaches for long documents, including chunking, retrieval-augmented generation (RAG), hierarchical summarization, and cache-friendly request design.
1. Why the Model Seems to Read Only the First Part
Many developers have seen this behavior when using LLM APIs or chat products. They upload a document of several hundred pages, but the model processes only the first few dozen pages, or the request fails with a message that the maximum input length has been exceeded. Some assume the product is cutting corners. In reality, the cause is concrete compute and cost constraints. To understand it, start with two concepts: the context window and the real cost of processing.
The context window is the maximum number of tokens a model can accept in a single inference call. How much text a model can read at once depends on the window limit set during training and on the resources consumed during inference. Mainstream models today have window limits ranging from tens of thousands to over a million tokens. However, “supported” and “practical to run at a reasonable cost” are different things.
2. Technical Root Causes: Why Long Inputs Are Expensive
2.1 Quadratic Complexity of Attention
In the standard Transformer architecture, the compute cost of self-attention grows with the square of the sequence length. Doubling the sequence length makes the attention matrix four times larger. Processing 100K tokens instead of 10K tokens increases the attention computation by roughly two orders of magnitude. Engineers commonly use optimizations such as sliding window attention, sparse attention, and linear attention to reduce this complexity. In production, however, long inputs still raise the compute cost of each request significantly.
2.2 KV Cache Memory Pressure
During inference, the model caches the Key and Value intermediate results from each attention layer to avoid repeated computation. This cache is the KV cache. Its memory footprint scales with the sequence length, the number of layers, and the number of attention heads. A simple estimate is:
KV Cache memory ≈ 2 × number of layers × sequence length × hidden dimension × bytes per element × batch size
For a typical mid-sized model, a single request with 128K tokens can occupy tens of gigabytes of GPU memory for its KV cache. GPU memory is the scarcest resource in an inference cluster. It determines how many requests one GPU can serve concurrently. When long-context requests increase, overall throughput drops sharply and the cost of serving rises.
2.3 Prefix Caching and Billing
Many pricing models give a large discount on input tokens that hit the cache, while input tokens that miss the cache are billed at a higher rate. As a result, sending hundreds of thousands of input tokens with no cache hits can cost far more than expected. Users on monthly token quotas can also exhaust their allowance quickly by sending very long text in one request. This is why many users feel the cost impact strongly.
3. Why Products Truncate or Rate-Limit Input
Even when a model supports a very long context window, service providers often limit the number of pages or tokens processed in a single request at the product level. The reasons include:
- Stability in multi-tenant service. A single very long request can occupy inference resources for a long time and increase response latency for other users.
- Cost of failed requests. If a very long input fails because of formatting or encoding issues, retrying is expensive.
- Avoiding low-value output. Research suggests that models become less able to recall information in the middle of very long contexts, a phenomenon often called “lost in the middle.” Instead of forcing the model to read the entire document, it is usually better to handle the content with more targeted engineering.
4. Engineering Practices for Processing Long Documents Efficiently
4.1 Chunking and Divide-and-Conquer
Split a long document into semantically coherent chunks, for example by section or by a fixed token count with overlapping windows. Process each chunk separately, then aggregate the results. Pseudocode:
chunks = split_by_semantic(doc, max_tokens=4000, overlap=200)summaries = [llm.summarize(c) for c in chunks]final = llm.synthesize(summaries)
4.2 Retrieval-Augmented Generation (RAG)
Instead of sending the full document to the model, build a vector index first. For each question, retrieve only the most relevant passages and pass them to the model. This greatly reduces the input tokens per request and makes answers easier to ground in the source. A complete pipeline typically relies on an embedding service, a vector database or object storage, and logging and monitoring for alerting.
4.3 Hierarchical Summarization
For very long documents, first compress the content level by level into a summary tree. Then answer questions over the overall document using these summaries. This preserves global information while keeping costs under control.
4.4 Caching and Multi-Turn Session Design
When the same long document is queried repeatedly, structure requests so that the shared prefix stays the same. This improves the prefix cache hit rate and can significantly reduce billing costs.
5. Summary
“The model reads only the first N pages” is not an arbitrary feature cut by providers. It is a rational trade-off shaped by attention complexity, KV cache memory, inference throughput, and billing cost. Developers who understand this logic should shift from “send the whole document at once” to a workflow built on chunking, retrieval, and summarization. This approach works around length limits and keeps costs reasonable. Context windows keep growing and compute costs keep falling, but hybrid approaches like these will likely remain the mainstream practice in production for a long time.
