Slides · Multimodal and document AI

Multimodal GenAI and document AI

Multimodal GenAI and document AI

How a model reads a page, how to choose between reading methods, and how to find out which layer broke when a document assistant gives a wrong number.

By the end you can estimate image cost, pick a page-reading approach, diagnose parsing failures, design chunks that cite pages, and define an evaluation.

Concept

The wrong total

  • A supplier invoice arrives as a scan. Its table runs across two pages and a round stamp covers one column.
  • The system files a plausible total. Later it turns out to be wrong, and only one page’s figures are in the system.
  • Where do you look first: the reading, the finding, or the answering?
  • A useful habit, covered later: check the earliest layer first, because a later layer cannot restore what an earlier one lost.

Concept

Mental model: transcribe or look

  • Transcribe first. A cheap clerk copies out what they can read (text extraction, OCR). Fast and cheap, but whatever the clerk drops or shuffles is gone.
  • Look directly. An expensive expert studies the photo (a vision-language model). They see layout and charts, but they are slower, cost more, and can confidently misread a number.
  • Production systems mix both: transcribe by default, send only hard pages to the expert, and keep a link back to the photo so a human can check.

Diagram

How a model reads a page image

Diagram: A vision encoder cuts the page image into patches and embeds each one.

Page image

Vision encoder:
cut into patches

Patch embeddings

Projection into
token space

Language model

Your text question

Answer text

Diagram summary: A vision encoder cuts the page image into patches and embeds each one. A projection maps those embeddings into the same space as text tokens, so the language model reasons over image tokens and your question together and writes an answer. This is a common design, not the only one.

Compare

Two different things: CLIP-style and a VLM

AspectContrastive image-text model (CLIP-style)Vision-language model (VLM)
Training ideaMatch each image to its caption, using paired dataAdd a language decoder that can write text about the image
OutputVectors that place a picture near its descriptionFree-form text answers about the image
Typical useImage search, similarityReading a page, answering questions about a chart
Reads a table cell?No, it only produces an embeddingYes, though it may misread

According to the CLIP paper, the model is pre-trained on about 400 million image-text pairs gathered from the internet, learning to pair each image with its own caption.

Source1 Learning Transferable Visual Models From Natural Language Supervision

Math

The cost formula: images are tokens

An image is not free metadata. Anthropic documents that Claude splits an image into 28 by 28 pixel patches, and each patch is one visual token.

visual_tokens=⌈width28⌉×⌈height28⌉\text{visual\_tokens} = \left\lceil \frac{\text{width}}{28} \right\rceil \times \left\lceil \frac{\text{height}}{28} \right\rceil
SymbolMeaning
width, height\text{width},\ \text{height}Image size in pixels, as sent to the model
2828Patch side in pixels (Anthropic’s documented patch size)
⌈⋅⌉\lceil \cdot \rceilRound up, because a partial patch still costs a whole token
visual_tokens\text{visual\_tokens}Input tokens billed for the image, before the cap below

Images larger than either limit of the tier are downscaled (Anthropic vision docs, checked 2026-10-23):

TierModelsMax long edgeMax visual tokens
StandardAll other models1,568 px1,568
High-resolutionClaude 4.7 and later models2,576 px4,784

Source2 Vision

Worked example

Worked: one letter page at two scan resolutions

A US Letter page is 8.5 by 11 inches.

ScanPixels (w×hw \times h)PatchesRaw tokensStandard tier (cap 1,568)High-resolution tier (cap 4,784)
100 dpi850×1,100850 \times 1{,}10031×4031 \times 401,240Kept as isKept as is
150 dpi1,275×1,6501{,}275 \times 1{,}65046×5946 \times 592,714Over the cap, so downscaledUnder both limits (long edge 1,650 is below 2,576), so kept at 2,714 tokens

Arithmetic: 850/28=30.4850 / 28 = 30.4, rounds up to 31. 1,100/28=39.31{,}100 / 28 = 39.3, rounds up to 40. 31×40=1,24031 \times 40 = 1{,}240. For 150 dpi, 1,275/28=45.51{,}275 / 28 = 45.5, up to 46, and 1,650/28=58.91{,}650 / 28 = 58.9, up to 59, so 46×59=2,71446 \times 59 = 2{,}714.

  • On a standard-tier model the page is shrunk until it fits under the cap. A resized page of about 952×1,232952 \times 1{,}232 px would be 34×44=1,49634 \times 44 = 1{,}496 patches, so roughly 1,500 tokens (illustrative size; the docs give the exact rule). The model sees a shrunken page.
  • On a high-resolution-tier model the sharper scan keeps its detail and costs about 2,714 tokens, roughly 2.2 times the 100 dpi page (2,714/1,2402{,}714 / 1{,}240).
  • So the right scan resolution depends on the model tier as well as on the smallest text you need.

Source2 Vision

Compare

Providers differ: read the current docs

AspectAnthropic (docs, 2026-10-23)OpenAI (docs, 2026-10-23)
Patch size28×2828 \times 28 pixels32×3232 \times 32 pixels for the patch-based models
Older schemeNot described on the vision page512 pixel tiles plus base tokens for some models such as gpt-4o
Cap1,568 or 4,784 visual tokens by tierPer model; images over 30,000 patches are rejected
Fidelity controlPre-resize images yourselfdetail setting: low, high, original, auto
  • In OpenAI’s scheme the patch count is multiplied by a per-model multiplier.
  • Its docs note low does not always use fewer tokens than high, because token use depends on the model.
  • The principle is the same for both: more pixels and more images mean more tokens, latency and spend.

Sources2 Vision3 Images and vision

Concept

The downscaling trade-off

  • Downscaling or compressing cuts tokens and request size.
  • It can also destroy the small print: footnotes, units and table digits blur first.
  • Anthropic warns that heavy lossy compression can make text hard to read, and says to inspect the images actually sent.
  • OpenAI notes small text may need enlarging, and original detail can help where the model supports it.
  • Rule: choose resolution by the smallest text you need, then test on real pages.

Sources2 Vision3 Images and vision

Check yourself

Check: a tall receipt

A receipt photo is 1,000×3,0001{,}000 \times 3{,}000 pixels and goes to a standard-tier model (1,568 cap). What happens, and what could you do about unreadable item lines?

Answer

Raw cost is 36×108=3,88836 \times 108 = 3{,}888 patches (1,000/28=35.71{,}000 / 28 = 35.7 up to 36; 3,000/28=107.13{,}000 / 28 = 107.1 up to 108). That is over the cap, and the long edge of 3,000 is over 1,568 as well, so the image is downscaled to fit, at a scale of at most about 0.52 on each side (1,568/3,0001{,}568 / 3{,}000). Item lines shrink to about half size and may blur. Options: cut the receipt into overlapping crops and read each at full size (more calls, more tokens in total, but legible), or use a model tier with a higher cap, and then check cost again.

Source2 Vision

Compare

Four ways to read a page

ApproachStrengthWeakness
Text-layer extractionCheap, fast, exact charactersLoses layout and tables; useless on scans; no charts
OCR plus layout analysisHandles scans; recovers structureOCR errors; more moving parts
VLM page readingUnderstands charts, forms, mixed layoutsCost, latency, privacy exposure, invented numbers
Page-image retrievalSkips fragile parsing; sees layoutLarger index; newer tooling; generator still reads the page
  • Pick on your own documents with a labelled sample, not on a feature list.

Concept

Layout parsers and page-image retrieval

  • Layout-aware parsing. The Docling technical report describes an open-source PDF converter built on DocLayNet for layout analysis and TableFormer for table structure.
  • Page-image retrieval. The ColPali paper (ICLR 2025) argues that text-extraction pipelines miss visual cues such as figures, layouts and tables.
  • ColPali instead builds multi-vector embeddings straight from page images, matched by late interaction, and introduces the ViDoRe benchmark of page-level retrieval.
  • It is a strong option to test, not a default. Retrieved pages still have to be read accurately by a generator.

Sources4 Docling Technical Report5 ColPali: Efficient Document Retrieval with Vision Language Models

Diagram

Route pages, do not pick one method for everything

Diagram: Each page is routed by what it contains.

yes

no (scan)

yes

no

Page

Clean text layer?

Text and table parser

OCR and layout analysis

Charts or forms?

VLM page reading

Structured chunks

Add page and section metadata

Diagram summary: Each page is routed by what it contains. Pages with a clean text layer go to a text and table parser, scans go through OCR and layout analysis, and only pages with charts or forms go on to a VLM. All routes end in structured chunks that receive page and section metadata. Page-image retrieval is the alternative that skips this parsing and indexes page images directly.

Worked example

Worked: why routing saves money (illustrative prices)

The per-page prices below are made up to show the shape. Measure your own.

RoutePagesIllustrative price per pageCost
Text layer8,500$0.0001$0.85
OCR and layout1,000$0.001$1.00
VLM500$0.01$5.00
Routed total10,000$6.85
All pages to the VLM10,000$0.01$100.00

Arithmetic: 8,500×0.0001=0.858{,}500 \times 0.0001 = 0.85; 1,000×0.001=1.001{,}000 \times 0.001 = 1.00; 500×0.01=5.00500 \times 0.01 = 5.00; sum 6.856.85. All-VLM: 10,000×0.01=10010{,}000 \times 0.01 = 100. Routing costs about 7% of the all-VLM run here.

The routing only pays off if the cheap routes pass your accuracy test on the pages they handle.

Worked example

Worked: a 100-page PDF sent to a VLM

Anthropic’s PDF support converts each page to an image and also extracts the page text and sends it alongside. Its docs say text typically uses 1,500 to 3,000 tokens per page, with image costs on top.

ItemPer page100 pages
Image tokens (assume a page image like the 100 dpi case earlier; the real size depends on how the page is rendered)1,240124,000
Text tokens (typical range from the docs)1,500 to 3,000150,000 to 300,000
Total2,740 to 4,240274,000 to 424,000
  • The image adds about 41% to 83% on top of the text-only cost here (124,000/300,000124{,}000 / 300{,}000 and 124,000/150,000124{,}000 / 150{,}000).
  • The docs also list a request cap of 600 pages (100 when the model’s context window is under 1M tokens) and warn that dense pages can fill the context window before the page cap.
  • Split large files, and do this work at ingestion time, not when a user asks.

Sources6 PDF support2 Vision

Concept

Privacy and accuracy are part of the choice

  • Privacy. A page image sends everything on the page to a hosted API, including content you did not mean to share. Check retention and training terms, redact where you can, or self-host for sensitive documents.
  • Docling’s repository says it can run locally, including for sensitive data and air-gapped setups.
  • Accuracy. Anthropic lists mistakes on low-quality, rotated or very small images, and approximate counting. OpenAI’s list includes trouble with graphs where line styles or colors vary.
  • Anthropic’s page says to review and verify the model’s image interpretations carefully, especially for high-stakes use. OpenAI’s page notes the model can produce incorrect descriptions and is not suited to medical images. Either way, keep a human review path.

Sources2 Vision3 Images and vision7 docling

Check yourself

Check: the routing threshold that blew the budget

A pipeline reads 200,000 pages a month with OCR and sends a page to the VLM whenever its page-level OCR confidence is below 0.90. About 30% of pages are routed. At an illustrative $0.01 per VLM page that is $600 a month, and the budget assumed about 8%. What do you check before changing anything?

Answer

Arithmetic: 200,000×0.30=60,000200{,}000 \times 0.30 = 60{,}000 pages, ×$0.01=$600\times \$0.01 = \$600; the budgeted 8% is 16,000 pages, $160. Check what the routed pages are and how accurate OCR actually was on them. Take a labelled sample of pages with confidence between, say, 0.80 and 0.90 and measure field accuracy. If OCR is already accurate there, lower the threshold or use a per-field confidence, since a logo or stamp can drag a page score down. If it is not accurate, the spend is justified and the budget is wrong. Set the threshold from measured accuracy, not from a round number.

Compare

Where parsing breaks

FailureWhat goes wrongWhy it hurts
Reading orderTwo columns read straight acrossSentences appear that were never written
TablesSpanning cells and missing borders flattenA string of numbers with no column names
Units and footnotes“(in thousands)” or a footnote is droppedA correct number is off by a factor of 1,000
ChartsValues are in pixels, not textA VLM may describe the trend and misread a value
ScansSkew, low resolution, stamps, handwritingOCR error rate rises
Invented figuresA VLM cannot read a cellIt may produce a plausible number

Worked example

Worked: the stamp over the amount column

The scanned invoice has four line items and a stated total of 1,749.75. A round stamp covers the amount of the freight row, and OCR returns an empty cell there.

RowDescriptionExtracted amount
1Hardware1,200.00
2Software licence349.50
3Support75.25
4Freight(empty)
  • Sum of what was extracted: 1,200.00+349.50+75.25=1,624.751{,}200.00 + 349.50 + 75.25 = 1{,}624.75. Stated total: 1,749.75. Gap: 1,749.75−1,624.75=125.001{,}749.75 - 1{,}624.75 = 125.00.
  • A gap that is a round, plausible amount and matches one empty cell points to a single lost cell, not a misread digit.
  • This is a parsing failure at the scan: the value never reached the stored text. Reranking, a larger top-k or a bigger model would all start from the same missing number.
  • A line-items-add-to-total check flags this document before it is filed.

Diagram

Isolate the layer: parsing, retrieval, generation

Diagram: Open the chunk first.

no

yes

no

yes

Wrong answer

Fact intact in the
retrieved chunk?

Parsing failure

Was that chunk
retrieved?

Retrieval failure

Generation failure

Diagram summary: Open the chunk first. If the fact is missing or scrambled there, parsing failed. If the chunk is fine but was not among the retrieved results, retrieval failed. If the right chunk was in the prompt and the answer is still wrong, generation failed. Fix the earliest broken layer, because later layers cannot repair it.

Check yourself

Check: name the failing layer

Three tickets, three observations. Name the layer for each.

  1. Searching the index by hand finds the warranty paragraph, complete and correct, but it ranks 23rd and the prompt held the top 5.
  2. The stored text for a scanned page reads “Tota1 am0unt due” followed by no digits at all.
  3. The prompt contains an intact chunk saying “7 days”, and the answer says “14 days”.
Answer
  1. Retrieval: the right chunk exists and is intact but was not returned. 2. Parsing: the scan’s content was lost or garbled at ingestion, so no later layer can recover it. 3. Generation: the right fact was in the prompt and the model still answered wrongly, so look at the prompt wording, instructions and model behaviour.

Concept

Chunking parsed documents: five rules

  • Keep a table whole. Splitting by token count separates the header from the rows. Small tables stay in one chunk; large ones split by row groups with the header repeated in every chunk.
  • Store tables in a readable structure. Markdown, HTML, or one record per row with its column names and unit.
  • Attach metadata. Page, section path, element type and, where available, the bounding box.
  • Treat figures separately. Store a caption or a model-written summary and flag it as model-generated.
  • Keep the link to the source page, so a citation like “page 14, Table 3” can be checked in seconds.

Code

Walkthrough: split a table, repeat the header

Python

def table_chunks(header, rows, page, section, rows_per_chunk):
    sep = "| " + " | ".join("---" for _ in header) + " |"   # one divider cell per column
    chunks = []
    for start in range(0, len(rows), rows_per_chunk):
        part = rows[start:start + rows_per_chunk]
        lines = ["| " + " | ".join(header) + " |", sep]
        lines += ["| " + " | ".join(r) + " |" for r in part]
        chunks.append({
            "text": "\n".join(lines),
            "meta": {"page": page, "section": section, "type": "table",
                     "rows": f"{start + 1}-{start + len(part)}"},
        })
    return chunks
  • Every chunk starts with the header line, which carries the column names (for example Q1 (USD k), so the unit travels with the chunk).
  • Run on a three-column header Region | Q1 | Q2 with five rows and 3 rows per chunk, it gives two chunks (rows 1-3 and rows 4-5). Both start with the same header and divider line and both carry page: 14. The divider is built from the column count, so any width works.
  • This is a teaching sketch. A real parser also supplies bounding boxes and handles tables that continue on the next page.

Check yourself

Check: a chart summary in the index

A VLM writes “Sales rose steadily from 2021 to 2024” as a summary of a bar chart, and it is stored as a normal paragraph chunk. A user later quotes it as the company’s own statement. What should the chunk have carried, and why?

Answer

A flag such as element: figure and origin: model-generated, plus the page and figure number. Without the flag, nobody can tell the sentence is a machine reading of the chart and not the document’s own wording, and the numbers behind it could be misread. With page metadata, a reviewer can open the figure and check the summary.

Compare

Evaluate each layer, on your own documents

LayerWhat to measureExample check
ExtractionField-level accuracy, plus table structureExact or normalized match per field
RetrievalRecall at page or section levelDid the right page come back in the top results?
AnswersFaithfulness to the cited page, citation correctnessDoes the cited page support the claim?
NumbersProgrammatic checksLine items add to the total, units match, dates parse
ReviewShare of items below the confidence thresholdA human checks them; the rate is a cost
  • Without a labelled set you cannot tell whether switching from OCR to a VLM helped.

Worked example

Worked: three numbers from one small labelled run

A labelled sample of 5 invoices with 4 fields each (20 fields), 10 test questions, and 200 invoices processed in production.

MeasureCountsResult
Field-level accuracy17 of 20 fields correct85%
Page-level retrieval recallRight page returned for 8 of 10 questions80%
Review rate30 of 200 invoices below the confidence threshold15%
  • Exact match counts “1200” against a label “1,200.00” as wrong. Normalized match (strip commas and currency, compare as numbers) counts it as right. Decide the rule before you measure.
  • At an illustrative 2 minutes of human time each, 30 reviews cost 60 minutes. Lowering the threshold trades review time for undetected errors.
  • A 5-invoice sample is far too small to trust in practice; it only shows the arithmetic.

Check yourself

Check: a good average that hides a bad field

A labelled sample of 40 invoices gives these field results: vendor name 39 of 40, total 37 of 40, date 28 of 40. A manager reads only the overall figure. What is it, and what do you look at next?

Answer

Overall: (39+37+28)/120=104/120≈86.7%(39 + 37 + 28) / 120 = 104 / 120 \approx 86.7\%. Per field: vendor 97.5%, total 92.5%, date 70%. The average hides that dates are weak. Look at the 12 wrong dates before blaming the parser: a day-month versus month-day mismatch (03/11) or a format the normalizer does not handle would count as wrong under the match rule. Fix normalization or the date locale first, then re-measure. Report accuracy per field, because the fields carry different business risk.

Summary

Recap

  • An image becomes patch tokens, so more or larger images cost more tokens, latency and money. Downscaling saves tokens but blurs small print.
  • Choose the cheapest page-reading method that passes your test, and route only hard pages to a VLM. Weigh privacy and accuracy, not only cost.
  • When numbers are wrong, open the chunk: parsing, retrieval and generation fail differently, and the earliest broken layer comes first.
  • Keep tables whole with their headers, attach page and section metadata, and flag model-written figure summaries.
  • Evaluate with a labelled sample, programmatic number checks and a human review path for low-confidence fields.

References

References & Sources (1 of 2)

  1. Learning Transferable Visual Models From Natural Language Supervision (opens in a new tab)

    Alec Radford, Jong Wook Kim, Chris Hallacy, Aditya Ramesh, et al.2021ICML 2021 (Proceedings of the 38th International Conference on Machine Learning, PMLR 139)Paper

    Used for CLIP-style contrastive pre-training matches images to captions using about 400 million image-text pairs.

  2. Vision (opens in a new tab)

    Anthropic2026Documentation

    Used for Claude splits images into 28x28-pixel patches costing ceil(width/28) x ceil(height/28) visual tokens, with per-tier caps (1,568 and 4,784), downscaling of larger images, compression warnings and a limitations list.

  3. Images and vision (opens in a new tab)

    OpenAI2026Documentation

    Used for OpenAI's patch-based (32x32) and tile-based (512 px) image token schemes, the detail setting, and its limitations list.

  4. Docling Technical Report (opens in a new tab)

    Christoph Auer, Maksym Lysak, Ahmed Nassar, Michele Dolfi, et al.2024Preprint

    Used for Docling is an open-source PDF converter built on DocLayNet layout analysis and TableFormer table-structure recognition.

  5. ColPali: Efficient Document Retrieval with Vision Language Models (opens in a new tab)

    Manuel Faysse, Hugues Sibille, Tony Wu, Bilel Omrani, et al.2024ICLR 2025Paper

    Used for ColPali builds multi-vector embeddings straight from page images and introduces the ViDoRe page-retrieval benchmark (ICLR 2025).

References

References & Sources (2 of 2)

  1. PDF support (opens in a new tab)

    Anthropic2026Documentation

    Used for PDF pages are converted to images with page text extracted alongside; typical text use of 1,500 to 3,000 tokens per page; page limits and dense pages filling the context window.

  2. docling (opens in a new tab)

    docling-project (GitHub)2026Repository

    Used for Docling can run locally, including for sensitive data and air-gapped environments.