Feeding Large Files to LLMs: How On-Demand Chunking Cuts Token Usage by Up to 90%
This article explains why sending entire large documents to a large language model is expensive and introduces a two-stage pattern—coarse scanning for location followed by on-demand fine reading—that can reduce token consumption by up to 90%. It covers chunking strategies across documents, spreadsheets, audio, and video, key engineering practices such as reusable file references, standardized chunk descriptors, two-layer caching, fallback, and observability, plus evaluation metrics and guidance on when this approach fits or falls short.
1. Why Loading Everything Is Expensive
Most large language models bill by token within a context window. When a document hundreds of pages long is sent to the model in full, you pay for the entire input regardless of whether the answer depends on two pages or the whole file—and latency scales the same way. Three hidden costs make this worse:
- Attention dilution: when irrelevant content dominates the input, the model’s accuracy in locating key information drops.
- Higher time to first token: the prefill stage must process the full input, slowing the response.
- Poor reuse: if the same file is uploaded again in a multi-turn conversation, costs stack linearly with each turn.
So the real optimization is not switching to a cheaper model, but changing how the input is constructed: show the model only what it needs to see at that moment.
2. The Core Pattern: Coarse Scan to Locate, Fine Read on Demand
The industry is converging on a two-stage reading pattern:
- Coarse scan: quickly traverse the full content via plain text extraction or low-resolution previews, producing “index signals” such as a table of contents, heading hierarchy, and keyword hit locations.
- Fine read: enable high-fidelity input only for the pages, regions, or time spans that were located, concentrating the budget on the segments that genuinely need understanding.
Illustrative pseudocode:
# Stage 1: low-cost scan to get candidate locationsindex = low_cost_scan(file) # plain text / low-res previewhits = locate(index, query) # returns page numbers, cell ranges, or time ranges# Stage 2: load only matched spans for high-fidelity understandingfor span in hits:chunk = load_high_fidelity(file, span)answer = model.chat(context=chunk, prompt=query)
The key is decoupling retrieval from understanding: retrieval uses cheap signals, while understanding uses expensive but precise input.
3. Chunking Dimensions: Where to Split by Modality
- Documents (PDF, presentations, word processing files): split by page, section, layer, or annotation region.
- Spreadsheets (workbooks): split by worksheet, cell range, or named range, avoiding the heavy redundant markup that comes from serializing an entire sheet.
- Audio: split by time span; first transcribe at a low sampling rate to locate content, then run fine-grained recognition on the target spans.
- Video: split along the timeline and by keyframes; first sample sparse frames to map content distribution, then sample densely within the target periods.
The unifying principle: chunk boundaries should align with semantic boundaries, so you never cut a sentence, a table, or a unit of reasoning in half.
4. Engineering Implementation
- Upload once, reuse across turns: store the file as an addressable resource; later requests carry only a reference and a chunk descriptor instead of re-uploading content.
- Standardize chunk descriptors: express “which page / which region / which time range / what fidelity” in a uniform structure, making caching and auditing straightforward.
- Two-layer caching: cache scan results at the index layer and high-fidelity loads at the chunk layer; a cache hit costs nothing.
- Fallback on failure: when the coarse scan misses, allow progressively widening the scope (page → section → full document) with a budget cap.
- Observability: log the input composition, chunk hit rate, and token distribution of each request as a basis for continuous optimization.
5. How to Evaluate Results
Don’t look at total cost alone. Track four metrics together: token consumption per task, chunk hit rate, answer accuracy, and end-to-end latency. In practice, the common gain comes from “scanning costs far less than full rendering,” but the exact multiple varies widely with document structure, query type, and chunk granularity. Build a baseline comparison on your own dataset rather than copying external numbers.
6. When It Fits and When It Doesn’t
Good fit: long-document Q&A, contract clause lookup, extracting key points from research reports, searching meeting and training recordings, and field lookup in large tables.
Use with caution: tasks requiring global statistics (such as sentiment distribution across a full text), reasoning tasks where chunking breaks context, and very short files where building an index costs more than feeding the full input.
7. Suggested Rollout Path
Step 1: add a “reference + chunk” model to the existing upload pipeline. Step 2: integrate plain-text and low-resolution scanners to produce the index. Step 3: change prompt construction to concatenating matched chunks. Step 4: establish budget and fallback policies. Step 5: regress accuracy and cost against an offline evaluation set. If you build on the cloud, you can store original files in object storage, use a message queue to smooth out scan workloads, and use logging and monitoring services to track token distribution, closing the loop.
On-demand chunking is essentially the engineering of “human-style reading”: flip through the table of contents first, then study the key pages closely. Bake that habit into the pipeline, and the cost structure of long-file processing shifts from “billing per file” to “billing per use.”
