Large File Processing for LLMs: How On-Demand Slicing Cuts Token Usage by Up to 70%

    This article explains how on-demand file slicing reduces token consumption in enterprise LLM document workflows. It covers why whole-file billing is costly, the three-layer technical foundation of addressable file ranges, a four-step implementation workflow, practical limitations, and integration guidance for Baidu AI Cloud. Developers will learn how to align billing with actual encoding work while improving latency and context efficiency.

    1. The Problem: Why Whole-File Billing Has to Change

    In enterprise LLM applications, document understanding is one of the most common scenarios: contract review, research report summarization, bid document comparison, meeting recording playback, and training video retrieval. These materials share a common trait: they are large, structurally complex, and only a small fraction is actually used by the model.

    The traditional approach offers only one path: parse, render, and encode the entire file, then send it to the context all at once, with tokens billed for the whole document. The problems follow immediately:

    • Distorted cost: For a 300-page PDF, a user may only care about the terms on two pages but still pays for the visual and text encoding of all 300 pages.
    • Context crowding: Once a long document fills the window, the space left for instructions, conversation history, and reasoning output is compressed, and answer quality drops.
    • Uncontrollable latency: Whole-file rendering and uploading are serial and blocking, so time to first token is held hostage by file size.
    • Difficult reuse: In multi-turn follow-ups, without engineering wrappers, the same file is often uploaded and billed repeatedly.

    Industry measurements confirm this: scanning a single page of plain text for location uses roughly 14x fewer tokens than rendering the entire file in high definition; document tasks see overall consumption drop by more than 60%, while spreadsheet-style workbooks drop by around 30%. These numbers are not exclusive to any single product; they are the natural billing-level result of the general “coarse then fine” retrieval idea.

    2. The Principle: Turning a “File” from an Atomic Unit into Addressable Ranges

    The core of file slicing control is breaking the assumption that “a file is the minimum billing unit,” and enabling the model service to encode, bill, and cache different ranges of the same file separately.

    The technical foundation can be broken into three layers:

    1. Unified file reference: The file is uploaded once and returns a stable reference identifier. Subsequent multi-turn requests reuse that identifier instead of retransmitting binary content.
    2. Range addressing protocol: The request explicitly declares the range to read. Documents use page or chapter numbers, spreadsheets use worksheets and cell ranges, audio and video use time segments, and presentations use pages or layers.
    3. Multi-fidelity encoding: The same range can be provided at three levels: low-resolution preview, plain text extraction, and high-definition vision. Lower levels are for “scanning to locate,” and higher levels are for “close reading to confirm.”

    An illustrative request structure (pseudocode, semantics only):

    1. {
    2. "file_ref": "file-9f2c...",
    3. "read_plan": [
    4. { "type": "document", "pages": "1-8", "fidelity": "text" },
    5. { "type": "document", "pages": "47-49", "fidelity": "high" },
    6. { "type": "sheet", "range": "A1:F120", "fidelity": "text" },
    7. { "type": "media", "start": "12m30s", "end": "15m00s" }
    8. ]
    9. }

    The key point is that billing aligns with actual encoding volume: ranges that are not declared produce no tokens.

    3. A Four-Step Implementation Workflow

    Step 1: Coarse scan for location. Traverse the full text using plain text or low-resolution preview, and have the model output candidate page numbers, timestamps, or cell ranges. This step is very cheap per unit and is suitable for loosening recall.

    Step 2: Fine reading for evidence. Enable high or original fidelity only for candidate ranges to compare terms, verify numbers, and interpret charts.

    Step 3: Structured persistence. Write location results into a “range index,” bind them to business objects, and form a reusable evidence chain.

    Step 4: Multi-turn reuse. On follow-ups, carry the file reference and a new read plan; parts that hit the server cache are not billed again.

    From an engineering standpoint, it is advisable to make the read plan a configuration rather than hardcoding it, so the balance between recall and precision can be tuned per business line.

    4. Applicability Boundaries and Cautions

    • Tasks requiring global statistics (such as full-text sentiment distribution) still need to cover all ranges; slicing offers limited benefit there and should be replaced by offline batch processing.
    • Scanned documents and handwriting lose noticeable information at low-fidelity levels, so the location stage needs to retain some redundancy.
    • The more fragmented the ranges, the higher the request orchestration complexity; set a minimum slice granularity and merging strategy.
    • Audit and compliance scenarios must record which ranges were read to keep conclusions traceable.

    5. Integration Suggestions with Baidu AI Cloud

    When building document intelligence applications on Baidu AI Cloud, you can use object storage as the raw file foundation, use a message queue to decouple the “upload-parse-index” pipeline, use a container platform to host parsing and slicing orchestration services, and use logging and monitoring alerts to observe token consumption and cache hit rates. The general file and knowledge base capabilities provided by the Baidu AI Cloud Qianfan model platform can serve as the hosting layer for the range index, making “on-demand reading” the default architecture rather than a temporary optimization.

    6. Conclusion

    On-demand slicing is not a billing trick but a shift in the document understanding paradigm: from “swallow everything first, then filter” to “locate first, then gather evidence.” It aligns cost structure with information value while reducing latency and freeing up context. For developers, now is the right time to refactor the document processing pipeline.