Multimodal Reading and Q&A for Very Long Documents

    This article explains how to turn large, mixed text-and-image enterprise documents into auditable, citable answers. It covers operating constraints, why OCR-then-RAG fails on visual content, a practical pipeline, context and latency trade-offs, evaluation, access control, and a staged rollout.

    Enterprises often face “hard-to-read” documents: tens of megabytes, hundreds of pages, with body text, tables, diagrams, and screenshots mixed together. Users rarely need copyable sentences; they care about arrow relationships, color-block meaning, UI state, or unlabeled spatial layout. Optical character recognition recovers characters but does not explain what a figure actually shows. Turning this material into answers that can be queried, cited, and audited is a document-intelligence engineering problem, not a chat-UI trick.

    Define the operating constraints first

    Describe requirements with four constraints rather than “can I upload this file?”

    1. Size and page count: files may be tens of megabytes and one to two hundred pages. Upload, parsing, and indexing cannot be designed like pasting a short article.
    2. Layout complexity: dual columns, headers and footers, footnotes, tables that span pages, and rotated scans often appear together.
    3. Question types: fact location, cross-page comparison, chart details, process order, and identifying anomalous pages.
    4. Latency and interaction: users expect a usable first answer in about ten seconds; follow-ups should reuse an existing index rather than reread the whole document.

    A hundred-thousand-token text budget is only a rough order of magnitude. High-resolution page images are the expensive part: the same page must keep text, thin lines, small labels, and cropped regions. Split “stuff the whole document into context” from “fetch pages on demand as evidence,” and switch by question difficulty. Do not default to re-encoding the entire book.

    Why extract-then-QA is not enough

    When the text layer is complete, extracting body copy, chunking by headings, and running vector search can answer definitions, clauses, and list-style questions. When the answer depends on vision, that path fails systematically:

    • Diagrams have no copyable text, or only captions such as “Figure 1” or “see figure.”
    • Critical information lives in connectors, relative position, color, and legends.
    • Scans are skewed, stamped over, or low-contrast, so OCR confidence is low.
    • Tables span pages or merge cells; linearization loses row–column structure.

    Keep at least three representations in parallel: layout blocks (titles, paragraphs, tables, figures, notes), text blocks, and visual representations of pages or crops. At question time, decide whether the question “must look at the figure.” If yes, retrieve the page or crop and send it with nearby text to a multimodal reader. Otherwise use text retrieval only, to control cost and latency.

    1. Ingest and persist. Large files go to object storage with hash, page count, language, and permissions. Parsing runs asynchronously so it does not occupy online request threads.
    2. Normalize. Unify pagination, drop duplicate pages, correct orientation, and judge whether the text layer is trustworthy. Mark scanned pages separately from native digital text.
    3. Layout analysis. Emit blocks in reading order with page number, coordinates, and block type. Keep table structure instead of flattening tables into prose.
    4. Visual segmentation. Crop figures, tables, formulas, and low-confidence text regions; keep a full-page thumbnail for “what is this page about overall.”
    5. Index. Text blocks get sparse and dense retrieval. Visual blocks store page number, nearby headings, and a short description. Use the description for recall and the original image for final reading so auto-summaries do not drop detail.
    6. Q&A. Rewrite the query, retrieve a small set of evidence pages, and assemble a prompt: question, page numbers, related text, and necessary images. Require a conclusion plus page and block identifiers.
    7. Traceability. The UI shows cited pages and crop regions. If evidence cannot be located, say so explicitly rather than filling gaps with general knowledge.

    Evidence assembly can stay minimal; the point is to constrain citation, not dump the full document:

    1. question: user question
    2. evidence:
    3. - page: 12
    4. blocks: [body block A, table header block B]
    5. image: figure region on page 12
    6. answer_policy:
    7. - use evidence only
    8. - must return page and block
    9. - refuse when evidence is insufficient

    Context budget and latency

    Full-document reading preserves cross-page relationships but is slow to prefill, costly, and brittle. Retrieval-based reading is stable and cheaper but answers poorly if recall misses a key page. A practical approach is layered:

    • Always put the table of contents, abstract, and heading tree in system context so the model knows the document skeleton.
    • Attach only a few highly relevant pages per question, not hundreds of images.
    • For comparison questions, fetch two candidate pages explicitly so the model does not see one-sided evidence.
    • For questions that already name a page (“what does this icon on page N mean?”), skip corpus retrieval and load that page directly.
    • Separate index construction from online Q&A. The user’s ten seconds should go to recall and one multimodal inference, not live layout analysis of the entire file.

    On timeout, excess pages, or oversized images, degrade: return a text-layer conclusion and state that the original image was not checked, or ask the user to narrow the question. Degradation is a product capability; silent failure is not.

    Evaluate more than fluency

    Prepare at least four question sets with human-labeled evidence pages.

    1. Pure-text facts: answers in the body; tests chunking and retrieval.
    2. Table values: tests whether structure is preserved.
    3. Visual details with no usable text: arrows, legends, UI state, spatial relations. The OCR path should fail on purpose so you can test the visual path.
    4. Cross-page synthesis: conclusions that need two or more pages.

    Track answer accuracy, evidence-page hit rate, whether refusals are justified, time to first token, and cost per question. Judging only whether the answer “sounds right” hides hallucination. For visual items, annotators should check the original image, not extracted text.

    Permissions, cache, and maintainability

    Contracts, drawings, and internal specs usually have access control. Indexes, crops, and cached answers must inherit the source file’s ACL; a vector store must not become a public search. Invalidate caches by file hash when documents change. Log questions, evidence pages, and model versions for review, but do not leave sensitive full-page images in debug directories indefinitely.

    If the team already uses object storage, async jobs, logging, and monitoring (for example on Baidu AI Cloud), put file persistence, parse queues, latency, and retries on those components. Keep document-understanding logic replaceable; do not bind the business flow to a single chat session.

    Rollout order

    Start with a set of real long documents and 20–50 human-labeled questions, at least one third of which require looking at figures. Implement pagination, layout blocks, and evidence linking, then add retrieval and multimodal reading. After text Q&A is stable, tune image resolution, crop strategy, and cross-page comparison. Regression-test every step on the same set so a few demo pages do not define “done.”

    The hard part of very long illustrated documents is not “reading the file once.” It is keeping visual information, controlling context cost, and tying every conclusion back to a page and region. An evidence-oriented pipeline is more operable than repeatedly rereading the whole document, and closer to the reliability enterprise knowledge Q&A actually needs.