Long-Document Multimodal Understanding and Question Answering in Practice

    When a very long PDF mixes body text, tables, diagrams, and scanned pages, a question-answering system cannot simply stuff every character into a model. This article explains how to split localization, reading, visual interpretation, and synthesis; keep text, visual blocks, and a light index; route questions through ingest, retrieval, and cited answers; and measure evidence recall, citation accuracy, latency, and cost without treating a large context window as a quality ceiling.

    When a very long PDF contains body text, tables, diagrams, and scanned pages at the same time, the problem is not simply “put the text into the model.” As the page count grows, character volume, image blocks, and layout noise grow together. Users often ask about only one or two details: an arrow relationship in a diagram, an unlabeled structure, or a conclusion that holds only across pages. Heavy preprocessing makes responses slower and the pipeline more brittle. Relying entirely on a single long context brings cost, truncation, and scattered attention at once. The engineering goal should be three acceptance criteria: critical evidence can be located, non-text visual information can be cited correctly, and end-to-end latency and cost are predictable.

    Separate the tasks before choosing a model

    Long-document work has at least four subtasks. Mixing them in one call is where systems most often fail.

    1. Locate: which page and which region the question refers to.
    2. Read: the text, table cells, and heading hierarchy in that region.
    3. See: shapes, colors, relative positions, and flow direction when the figure has no extractable text.
    4. Synthesize: align terms across pages and state whether the basis comes from the body or a figure.

    Text extraction alone fails the third class systematically. Optical character recognition works for print and clear scans. It does not solve cases where the figure itself is the information: architecture diagrams, sequence diagrams, unlabeled curves, or contrasts expressed only by layout. Sending every page to a multimodal model as an image wastes context on blank pages, repeated headers, and low-resolution thumbnails. The sound approach is to route by page and by block, not to use one representation for the whole file.

    Context budget and representation

    The industry commonly calls the input size a model can handle at once a context window, usually estimated in tokens. Chinese, English, punctuation, and layout symbols convert at different rates, and images consume extra budget according to resolution and tiling. “The file is only tens of megabytes” does not mean it can be read in one pass. A vector page may contain little text. A scanned page may have almost no searchable text. A page dense with figures can grow sharply after multimodal encoding.

    In practice, keep three representations rather than a single “full text”:

    • Structured text: headings, paragraphs, lists, table cells, page numbers, and reading order. Layout analysis should keep block boundaries and section membership so multi-column articles are not concatenated left to right by mistake.
    • Visual blocks: diagrams, formula crops, and low-quality scan regions stored as separate blocks, with page number, coordinates, and neighboring headings for traceability.
    • A light index: section paths, keywords, table headers, and captions. The index narrows candidates; it does not replace the final read.

    When a stable full-text representation fits the context budget and the question needs a global pass, use direct long-context reading. When the file far exceeds the budget, or most questions depend on only a few pages, retrieve first and then read closely. Both paths can coexist: global questions use a summary tree or a section map; local questions use the original text and original images of candidate pages. Being able to fit everything into the window is not a quality ceiling. A large window can still miss a small figure in a corner if neither attention nor the prompt marks that block as evidence.

    A maintainable pipeline

    A maintainable pipeline usually has three stages: ingest, question, and answer.

    During ingest, store the original file in object storage and keep an immutable file identifier and version. The parsing service produces page-level and block-level objects: text blocks, tables, and image blocks. Each block carries a page number, coordinates, a section path, and a content hash. Do not enlarge every image block. Save a preview and a higher-resolution image for recognition, and record the scale so coordinates stay aligned. Logging should record parse time, failed pages, and low-confidence blocks. Monitoring and alerts should watch parse failure rate and queue backlog. A message queue is a good way to split parsing, indexing, and quality checks so an upload does not wait synchronously for every step.

    At question time, classify intent first. Fact lookup, table calculation, figure explanation, and cross-page synthesis should take different routes. Retrieval may use keywords, vectors, or both, but every hit must return a page number and a block identifier. For close reading, send only the text of candidate blocks and the images that are actually needed. The prompt should require evidence locations before the conclusion, and should say which page is missing when evidence is insufficient instead of filling gaps with common knowledge. For diagrams, the prompt should say explicitly: do not invent text that is not in the figure; describe only visible structural relationships.

    At answer time, write citations back to stored block identifiers. The front end should show page numbers and highlight boxes so users can check the source and so regression tests have a target. Cache on file version, normalized question text, and evidence-block hashes to avoid repeat charges. The cache must be invalidated when the file changes.

    A simple evidence record is enough:

    1. {
    2. "file_id": "doc-2024-001",
    3. "page": 37,
    4. "block_id": "p37-fig-2",
    5. "kind": "figure",
    6. "bbox": [80, 120, 520, 640],
    7. "neighbor_heading": "Deployment flow"
    8. }

    This is an application-side convention, not a vendor API. Object storage, message queues, a container platform, logging, and monitoring can all be generic capabilities. Parsing and question-answering logic stay in your own services.

    Design non-text images separately

    Mixed text-and-figure failures are usually not because the model “cannot see.” Upstream processing dropped or blurred the figure. Common traps include exporting only embedded text and dropping vector graphics; rendering a whole page at a resolution so low that thin lines merge; cropping a large cross-page figure into non-overlapping fragments that cut arrows; and treating a table as an image and then forcing OCR, which loses cell relationships.

    More reliable rules:

    • On pages with selectable text and a reliable layout, prefer text and table structure, and use images only as a supplement.
    • For scanned pages, photos, formulas, and diagrams, keep image blocks and attach nearby headings and captions as weak context.
    • When cropping, keep a small margin so axes, legends, and arrow endpoints are not cut off.
    • If the same figure is referenced at several scales, deduplicate by content hash, but still point the answer at the page the user sees.

    Evaluation should include a separate “text-free figure” set. Give the figure without its caption and see whether the system can describe relationships. Then add the caption and see whether it aligns the caption with the picture. If the two results conflict, expose the conflict instead of picking the smoother story.

    Quality, latency, and cost

    Do not accept a demo claim such as “read it in a few seconds after upload.” Split the work into repeatable metrics: parse success rate, evidence recall (whether the page that holds the gold answer enters close reading), citation accuracy (whether the answer is actually supported by the cited blocks), the rate of refusal when there is no basis, latency percentiles end to end, and input and output size per question. Break latency into queue time, parsing, retrieval, and model inference, or you cannot tell which stage to scale.

    On cost, direct long-context reading generally rises with input size. Retrieval plus close reading confines cost to candidate blocks, but adds a retrieval step and possibly a second model call. When files change rarely and questions are scattered, precomputing section summaries and figure descriptions can spread later query cost. When files change often, precomputation goes stale and should be updated incrementally by version. On a container platform, run parsing as a horizontally scalable workload and keep interactive question answering separate from offline parsing so a large file does not stall the online API.

    Access control is not optional. Document question answering often touches contracts, designs, and internal specifications. Object storage should be private, and parse results should use the same authorization as the original file. Logs should not store full text by default; store request identifiers, page numbers, and error types. External APIs should limit file size, page count, and concurrency, and should fail fast on abnormal PDFs—encrypted, corrupt, or carrying oversized embedded images—with a reason a user can understand.

    When a longer context will not help

    A larger window helps little when the layout is extremely disordered, the task needs pixel-level checking, the answer depends on facts outside the file, or the question is too vague to identify a section. Fall back to human review, ask the user for a page number, or split the task into “locate candidate pages, then let a person confirm.” A model can speed reading and drafting. It should not act as a signature when there is no evidence.

    If the team already has a shared cloud runtime, put original files, parse artifacts, and evaluation sets in object storage, connect parsing with a message queue, and use logs and monitoring for failed pages and latency. General cloud services such as Baidu AI Cloud can provide those foundations. The document-understanding strategy, prompts, evaluation sets, and citation protocol should still be defined by the business. They should not be tied to one model or to how fast one demo felt.

    Stable long-document question answering depends on traceable evidence, separate handling of text and figures, routing by question type, and recall and citation metrics instead of a subjective sense that the file was “read.” The window, retrieval, and visual blocks complement each other. Pin down page numbers, coordinates, and versions before arguing about speed. Only then will the system hold up against real files and real questions.