Large File Processing: Native File Slicing for Token Control

    This article introduces native file slicing control, a server-side approach to reducing token costs and improving context quality when working with large files. It breaks the capability into three dimensions—spatial selection, semantic layer selection, and default behavior—and includes pseudocode showing how to declare slicing intent in a request. The article also explains how to interpret reported token savings, offers a practical implementation checklist, and outlines how the pattern can be built on Baidu AI Cloud.

    1. Why Large Files Are Expensive and Slow

    In enterprise AI applications, the biggest cost sink is rarely a long prompt. It is the size of the input file itself. A hundred-page PDF, a workbook with dozens of tabs, or a meeting recording that runs for tens of minutes—when loaded into the model context in full, creates three chained problems:

    1. Token costs scale linearly: the larger the file, the more input tokens per call, and both cost and latency rise together.
    2. Attention gets diluted: irrelevant pages and irrelevant segments occupy the context, and recall on the information that actually matters drops.
    3. The engineering pipeline gets complicated: to save cost, teams are often forced to build their own “split first, then upload” preprocessing pipeline on the application side, which is expensive to maintain and fragile across formats.

    The traditional fix is client-side preprocessing: split the PDF into pages, export the spreadsheet to CSV, extract frames from the video. The problem with this route is that format semantics are destroyed during splitting—layout, formulas, layers, and timeline information are lost, and the model ends up looking at “incomplete raw material.”

    Native file slicing control moves the splitting action off the application side and up into the model service: the file is uploaded once in full, and each call declares via parameters “which parts to look at this time.” The server loads only the declared content, and billing covers only the parts actually inspected. It is a shift from “moving data around” to “declaring intent.”

    2. Three Dimensions of Slicing Control

    From an engineering perspective, this capability abstracts into three orthogonal dimensions. Any combination covers the vast majority of business needs.

    2.1 Spatial Dimension: Select a Region

    • Documents and slides: select by page number or page range, and specify a rendering resolution tier (low/medium/high). Resolution directly affects image token consumption; the low tier is enough for plain text extraction.
    • Spreadsheets: select by worksheet tab and cell range (such as A1:F200) instead of loading the whole workbook.
    • Video: trim by time interval, and adjust frame rate and resolution.

    2.2 Semantic Dimension: Select a Content Layer

    This is the most overlooked and most valuable part of the design. The same file can expose multiple “views” at once:

    File type Selectable content layers
    Documents/slides Page text, page image
    Spreadsheets Computed values, formulas, visualization elements, sheet names
    Video Transcript, video frames, audio
    Audio Time interval trimming

    For a financial review, what you need is the formula layer (to judge whether calculation logic has been tampered with). For report reconciliation, you need the computed values layer. For meeting minutes, you only need the transcript and never have to load video frames.

    2.3 Default Behavior: Omitting Parameters Means “Full Semantics”

    One point that matters a lot in engineering: when no processing options are passed, the server applies an intuitive default view—documents and slides default to page images that preserve layout, and spreadsheets default to returning computed values, formulas, and sheet names for all worksheets. This means existing code migrates smoothly with no changes, and the new capability lands through progressive adoption. Existing file size and page count limits also stay unchanged: slicing does not relax resource constraints. It is a cost optimization mechanism, not a capacity expansion mechanism.

    3. Sample Code: Writing Intent into the Request

    The code below is generic pseudocode. It only illustrates the parameter structure and does not target any specific vendor API:

    1. # 1) Upload the file and get a stable file handle
    2. file_id = upload_file("./report.pdf")
    3. # 2) Declare that this call only inspects the text layer of pages 3-5
    4. resp = generate(
    5. model="large-multimodal-model",
    6. file_id=file_id,
    7. file_options={
    8. "type": "document",
    9. "pages": "3-5",
    10. "resolution": "low",
    11. "layers": ["page_text"],
    12. },
    13. prompt="Summarize the key conclusions and risk warnings on these three pages"
    14. )
    15. # 3) Spreadsheet case: inspect computed values in one region only
    16. resp2 = generate(
    17. model="large-multimodal-model",
    18. file_id="sheet_001",
    19. file_options={
    20. "type": "spreadsheet",
    21. "sheets": ["Q3"],
    22. "cell_range": "B2:H40",
    23. "layers": ["values"],
    24. },
    25. prompt="Check whether the total row matches the detail rows"
    26. )

    Engineering advice: abstract file_options into a “retrieval intent object” on the business side, decided by the upper business layer rather than hardcoded in scattered places.

    4. Interpreting the Reported Gains Reasonably

    Early publicly disclosed benchmark data shows that extracting text page by page can use as little as roughly one fourteenth of the tokens required to render an entire PDF; in another set of tests, slicing reduced PDF prompt tokens by about two thirds and workbook tokens by about one third.

    These numbers need rational attribution and should not be read as “slicing always saves 90%”:

    • Gains correlate positively with file sparsity: if you care about 2 pages out of 100, the gain approaches an order of magnitude; if the content you care about already makes up 70% of the file, the gain is naturally limited.
    • Gains correlate strongly with layer selection: taking the text layer while skipping the image layer produces the largest savings.
    • There is fixed overhead: file upload, handle management, and the orchestration cost of multiple calls do not disappear because of slicing.

    The right way to evaluate is therefore to run A/B measurements on real business samples first, build a baseline model of “file size—proportion of interest—token consumption,” and then decide the slicing granularity.

    5. Implementation Checklist

    1. Build a file parsing layer: uniformly wrap upload, handle caching, and slicing parameter generation so business code does not reimplement it.
    2. Cache file handles: reuse the handle across multiple questions about the same file to prevent repeated uploads.
    3. Make slicing granularity configurable: turn page ranges, cell ranges, and time intervals into configuration items that support hot updates per scenario.
    4. Tiered resolution strategy: use the low tier for text extraction, and step up only when charts or layout need to be seen.
    5. Observability: instrument logs, monitoring, and alerting to record “file size, slicing parameters, actual tokens, hit rate” and build a cost dashboard.
    6. Fallback path: when slicing parameters go out of range or the file exceeds limits, fall back to the default full view with a clear notice to preserve availability.
    7. Security and compliance: set expiry and access control on file handles, and enable encryption and lifecycle policies when sensitive data lands in object storage.

    6. Implementation Approach on Baidu AI Cloud

    When building this kind of capability on Baidu AI Cloud, file slicing can be treated as an “input governance” layer of the multimodal large model service: object storage holds the original files, a container platform hosts the parsing and orchestration services, and monitoring, alerting, and logging services handle cost and quality observation. The core principle is let developers declare intent and let the platform handle loading, so tokens are spent where they are truly needed without sacrificing semantic completeness.

    7. Conclusion

    The essence of native file slicing control is shifting the responsibility for cost optimization from “brute-force preprocessing on the application side” to “semantic loading on the server side.” For developers, the real payoff is not just a thinner bill, but cleaner context, more focused answers, and a simpler pipeline. Start with the most painful class of large-file scenarios, quantify the baseline first, then refine slicing strategy step by step, and eventually build reusable cost governance capability.