Long-Context Truncation: Compute Limits and Cache Costs Explained
Why do some LLM applications read only the first few pages of a document or cap input at around 10,000 tokens? This article explains how context windows, request limits, document parsing, prefill computation, KV caching, and resource scheduling shape long-document processing—and how retrieval, chunked summaries, and caching can help developers manage those constraints.
Long-Context Truncation: Compute Limits and Cache Costs Explained
When using large language models to process long documents, developers often encounter an unexpected limit: the system reads only the first few pages, or a request accepts no more than roughly 10,000 input tokens.
It is tempting to conclude that the model lacks the capability or that the platform does not have enough compute. That explanation is only partly correct. Long-context requests face several overlapping constraints: the model’s context window, request admission policies, document preprocessing and parsing, GPU memory and compute resources, cache hit rates, billing, and fair scheduling.
A limit such as “the first 20 pages” or “10,000 tokens per request” is often a protective policy at the application or platform level—not an absolute limit on how much content the model can understand.
1. Model Context Windows vs. Application Input Limits
A model’s context window is a technical parameter that defines the total number of tokens it can accommodate in a single request. Whether an application allows an entire document to be submitted at once depends on additional constraints:
- Request size limits: Platforms may cap input tokens per request to prevent unusually large requests from consuming disproportionate resources.
- Document parsing limits: PDFs, scanned documents, and tables must first be converted into text. Parsing services may process them in batches based on page or character counts.
- Timeouts and time-to-first-token requirements: Large inputs increase preprocessing time and delay the first generated token. Platforms must balance this against interactive response requirements.
- Cost and quota controls: Processing hundreds of thousands of tokens without cache reuse can sharply increase compute costs.
- Fair scheduling: A small number of long requests can occupy substantial GPU memory and compute capacity, reducing throughput and stability for other users.
Limits such as “read only the first 20 pages” are therefore common in document Q&A, web-reading tools, and knowledge-base ingestion workflows. They may be default policies or part of a tiered processing strategy: short requests run directly, while longer requests use asynchronous jobs, chunk indexing, or retrieval-augmented workflows.
2. The Core Cost of Long Context: Prefill and Attention
LLM inference typically has two stages:
- Prefill: The model processes the input tokens and performs the associated attention computations.
- Decode: The model generates output one token at a time.
Long inputs put substantial pressure on the prefill stage.
Suppose the input length is n and the hidden dimension is d. Attention establishes relationships between tokens. In simplified terms, its computational cost can grow nonlinearly with n. Even with extensive implementation optimizations, long inputs require more matrix computation, GPU memory traffic, and intermediate activation storage.
Increasing an input from a few thousand tokens to hundreds of thousands is therefore not simply a matter of “reading a few more pages.” It increases compute requirements, memory pressure, and scheduling complexity together.
Long inputs also create several operational challenges:
- Higher time to first token: Users wait longer before seeing any output.
- Higher peak GPU memory usage: Capacity must be reserved for intermediate activations, attention caches, and batching.
- Lower batching efficiency: Very long requests reduce the number of requests that can run concurrently in a batch.
- More expensive timeouts and retries: Retrying a failed request can repeat substantial computation.
Limits on how much content a platform processes at once help control peak resource consumption and maintain an acceptable baseline user experience.
3. KV Caching and the Cost of a Cache Miss
During decoding, generative models typically reuse the keys and values computed for earlier tokens. This is known as the key-value cache, or KV cache. It avoids recomputing the entire historical context at every generation step.
For repeated requests involving the same document, conversation prefix, or fixed instructions, reusing cached prefix computations can also reduce repeated prefill work.
In this context, “zero cache” means that no reusable input cache is available across requests, so each request must perform the full prefill again. This is distinct from the KV caching used within a single decoding run.
A document containing around 600,000 Chinese characters may translate into hundreds of thousands of tokens, depending on tokenization, language, and document structure. Without prefix, document, or retrieval-cache reuse, the platform must process the input again for each request, making the workload more expensive.
The following simplified pseudocode illustrates the difference:
def handle_long_document(doc, question, cache_store):chunks = split_into_chunks(doc, max_tokens=2000)# Without caching: recompute the full input every timefull_context = "\n".join(chunks)answer = model_generate(prompt=full_context + question,use_cache=False)# With caching: reuse a fixed prefix or document-block cacheprefix = build_stable_prefix(chunks)cached_prefix = cache_store.get(prefix)if cached_prefix is None:cached_prefix = model_prefill(prefix)cache_store.set(prefix, cached_prefix)answer = model_generate(prompt=question,prefix_cache=cached_prefix,use_cache=True)return answer
These are illustrative operations, not a specific provider’s API. The two paths show the contrast between recomputing the input and reusing cached prefix computation.
Caching is not a universal solution. It requires storage, cache-hit checks, invalidation policies, and consistency management. Frequently changing documents may produce low hit rates. Stable knowledge bases and fixed system prompts are more suitable for prefix or block-level caching.
4. Common Platform Strategies for Long Documents
Platforms typically use a layered approach to balance cost and usability:
- Direct processing for short requests: Inputs with relatively few tokens go directly to the model.
- Chunking for long requests: Documents are split into smaller blocks for summarization, retrieval, and answer generation.
- Retrieval augmentation: Vector or keyword search identifies relevant passages, and only those passages are sent to the model.
- Asynchronous processing: Very long documents run as background jobs with longer processing allowances, rather than blocking an interactive session.
- Prefix and document caching: Computed results are reused for stable prefixes and fixed knowledge blocks.
- Quotas and rate limits: Platforms restrict input size, per-user concurrency, and token consumption over time.
- Observability: Systems track input tokens, truncation rates, cache hit rates, time to first token, and failure rates.
General-purpose cloud components can support this asynchronous pipeline. Object storage holds uploaded documents; a message queue triggers chunking and indexing tasks; results are written to a retrieval service; and logging, monitoring, and alerts track queue backlogs and errors. Function compute can support parts of the processing workflow.
General cloud product categories offered by platforms such as Baidu AI Cloud can be used to build this type of architecture. Specific service selection should be evaluated against workload scale, latency requirements, and budget.
5. What Developers Can Do About “Only the First N Pages”
When faced with document limits, simply increasing the input length is rarely the best first step. A more practical approach is to separate finding the relevant information from reading it closely.
5.1 Retrieve First, Then Read
Split the document into chunks and build an index. For each question, retrieve the top-K relevant passages and ask the model to answer from those passages.
This keeps token usage under control while improving the relevance of the supplied context.
def answer_with_retrieval(question, index, top_k=8):candidates = index.search(question, top_k=top_k)context = merge_chunks(candidates, max_tokens=8000)prompt = (f"Answer only from the following material and cite your sources:\n"f"{context}\nQuestion: {question}")return model_generate(prompt)
5.2 Use Hierarchical Summaries
For very long documents, first generate summaries of individual chunks, then combine them into section-level summaries. Use those summaries to answer document-wide questions.
For detailed questions, return to the original text through retrieval. Hierarchical summarization is useful for structured documents such as reports, contracts, and manuals.
5.3 Keep Cacheable Prefixes Stable
Place system instructions, fixed rules, and stable knowledge blocks at the beginning of the request. Keeping these prefixes unchanged improves the likelihood of cache reuse.
Avoid inserting volatile content, such as timestamps or random IDs, into otherwise stable system prompts.
5.4 Control Input Structure and Truncation
If truncation is unavoidable, prioritize useful content rather than mechanically taking the first N pages.
Preserve titles, tables of contents, conclusions, question-relevant passages, and key table fields. Content can be ranked using heading hierarchy, paragraph relevance scores, and keyword matches.
5.5 Monitor Cost and Quality
At a minimum, track:
- Input token-count percentiles
- Cache hit rate
- Percentage of requests affected by truncation
- Time to first token
- Generation failure rate
- Cost per request
These metrics help distinguish an insufficient context window from poor retrieval. Without that distinction, expanding the window may increase cost without addressing the underlying problem.
6. Conclusion
A limit such as “the first 20 pages” or “10,000 tokens” is not simply a compute-capacity issue. It reflects an engineering trade-off among computational complexity, GPU memory consumption, cache reuse, billing costs, and interactive responsiveness.
For platforms, limiting per-request input helps protect resources and preserve fair access. For developers, retrieval augmentation, chunked summaries, prefix caching, asynchronous processing, and observability offer more dependable ways to handle long documents.
Replacing “send everything at once” with “locate relevant content, read it closely, then generate” is often more stable, more economical, and easier to implement than pursuing a larger context window alone.
