Slides · Multimodal and document AI
Multimodal GenAI and document AI
1 / 30
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
Compare
Two different things: CLIP-style and a VLM
| Aspect | Contrastive image-text model (CLIP-style) | Vision-language model (VLM) |
|---|---|---|
| Training idea | Match each image to its caption, using paired data | Add a language decoder that can write text about the image |
| Output | Vectors that place a picture near its description | Free-form text answers about the image |
| Typical use | Image search, similarity | Reading a page, answering questions about a chart |
| Reads a table cell? | No, it only produces an embedding | Yes, 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.
Source[1] 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=⌈28width⌉×⌈28height⌉| Symbol | Meaning |
|---|---|
| width, height | Image size in pixels, as sent to the model |
| 28 | Patch side in pixels (Anthropic’s documented patch size) |
| ⌈⋅⌉ | Round up, because a partial patch still costs a whole token |
| 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):
| Tier | Models | Max long edge | Max visual tokens |
|---|---|---|---|
| Standard | All other models | 1,568 px | 1,568 |
| High-resolution | Claude 4.7 and later models | 2,576 px | 4,784 |
Source[2] Vision
Worked example
Worked: one letter page at two scan resolutions
A US Letter page is 8.5 by 11 inches.
| Scan | Pixels (w×h) | Patches | Raw tokens | Standard tier (cap 1,568) | High-resolution tier (cap 4,784) |
|---|---|---|---|---|---|
| 100 dpi | 850×1,100 | 31×40 | 1,240 | Kept as is | Kept as is |
| 150 dpi | 1,275×1,650 | 46×59 | 2,714 | Over the cap, so downscaled | Under both limits (long edge 1,650 is below 2,576), so kept at 2,714 tokens |
Arithmetic: 850/28=30.4, rounds up to 31. 1,100/28=39.3, rounds up to 40. 31×40=1,240. For 150 dpi, 1,275/28=45.5, up to 46, and 1,650/28=58.9, up to 59, so 46×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,232 px would be 34×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,240).
- So the right scan resolution depends on the model tier as well as on the smallest text you need.
Source[2] Vision
Compare
Providers differ: read the current docs
| Aspect | Anthropic (docs, 2026-10-23) | OpenAI (docs, 2026-10-23) |
|---|---|---|
| Patch size | 28×28 pixels | 32×32 pixels for the patch-based models |
| Older scheme | Not described on the vision page | 512 pixel tiles plus base tokens for some models such as gpt-4o |
| Cap | 1,568 or 4,784 visual tokens by tier | Per model; images over 30,000 patches are rejected |
| Fidelity control | Pre-resize images yourself | detail setting: low, high, original, auto |
- In OpenAI’s scheme the patch count is multiplied by a per-model multiplier.
- Its docs note
lowdoes not always use fewer tokens thanhigh, 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.
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
originaldetail can help where the model supports it. - Rule: choose resolution by the smallest text you need, then test on real pages.
Check yourself
Check: a tall receipt
A receipt photo is 1,000×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,888 patches (1,000/28=35.7 up to 36; 3,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,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.
Source[2] Vision
Compare
Four ways to read a page
| Approach | Strength | Weakness |
|---|---|---|
| Text-layer extraction | Cheap, fast, exact characters | Loses layout and tables; useless on scans; no charts |
| OCR plus layout analysis | Handles scans; recovers structure | OCR errors; more moving parts |
| VLM page reading | Understands charts, forms, mixed layouts | Cost, latency, privacy exposure, invented numbers |
| Page-image retrieval | Skips fragile parsing; sees layout | Larger 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.
Sources[4] Docling Technical Report[5] ColPali: Efficient Document Retrieval with Vision Language Models
Diagram
Route pages, do not pick one method for everything
Worked example
Worked: why routing saves money (illustrative prices)
The per-page prices below are made up to show the shape. Measure your own.
| Route | Pages | Illustrative price per page | Cost |
|---|---|---|---|
| Text layer | 8,500 | $0.0001 | $0.85 |
| OCR and layout | 1,000 | $0.001 | $1.00 |
| VLM | 500 | $0.01 | $5.00 |
| Routed total | 10,000 | $6.85 | |
| All pages to the VLM | 10,000 | $0.01 | $100.00 |
Arithmetic: 8,500×0.0001=0.85; 1,000×0.001=1.00; 500×0.01=5.00; sum 6.85. All-VLM: 10,000×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.
| Item | Per page | 100 pages |
|---|---|---|
| Image tokens (assume a page image like the 100 dpi case earlier; the real size depends on how the page is rendered) | 1,240 | 124,000 |
| Text tokens (typical range from the docs) | 1,500 to 3,000 | 150,000 to 300,000 |
| Total | 2,740 to 4,240 | 274,000 to 424,000 |
- The image adds about 41% to 83% on top of the text-only cost here (124,000/300,000 and 124,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.
Sources[6] PDF support[2] 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.
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,000 pages, ×$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
| Failure | What goes wrong | Why it hurts |
|---|---|---|
| Reading order | Two columns read straight across | Sentences appear that were never written |
| Tables | Spanning cells and missing borders flatten | A string of numbers with no column names |
| Units and footnotes | “(in thousands)” or a footnote is dropped | A correct number is off by a factor of 1,000 |
| Charts | Values are in pixels, not text | A VLM may describe the trend and misread a value |
| Scans | Skew, low resolution, stamps, handwriting | OCR error rate rises |
| Invented figures | A VLM cannot read a cell | It 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.
| Row | Description | Extracted amount |
|---|---|---|
| 1 | Hardware | 1,200.00 |
| 2 | Software licence | 349.50 |
| 3 | Support | 75.25 |
| 4 | Freight | (empty) |
- Sum of what was extracted: 1,200.00+349.50+75.25=1,624.75. Stated total: 1,749.75. Gap: 1,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
Check yourself
Check: name the failing layer
Three tickets, three observations. Name the layer for each.
- Searching the index by hand finds the warranty paragraph, complete and correct, but it ranks 23rd and the prompt held the top 5.
- The stored text for a scanned page reads “Tota1 am0unt due” followed by no digits at all.
- The prompt contains an intact chunk saying “7 days”, and the answer says “14 days”.
Answer
- 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 | Q2with 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 carrypage: 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
| Layer | What to measure | Example check |
|---|---|---|
| Extraction | Field-level accuracy, plus table structure | Exact or normalized match per field |
| Retrieval | Recall at page or section level | Did the right page come back in the top results? |
| Answers | Faithfulness to the cited page, citation correctness | Does the cited page support the claim? |
| Numbers | Programmatic checks | Line items add to the total, units match, dates parse |
| Review | Share of items below the confidence threshold | A 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.
| Measure | Counts | Result |
|---|---|---|
| Field-level accuracy | 17 of 20 fields correct | 85% |
| Page-level retrieval recall | Right page returned for 8 of 10 questions | 80% |
| Review rate | 30 of 200 invoices below the confidence threshold | 15% |
- 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%. 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)
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
arXiv 2103.00020 (opens in a new tab)https://proceedings.mlr.press/v139/radford21a.html
Used for CLIP-style contrastive pre-training matches images to captions using about 400 million image-text pairs.
Anthropic2026Documentation
https://platform.claude.com/docs/en/build-with-claude/vision
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.
Images and vision (opens in a new tab)
OpenAI2026Documentation
https://developers.openai.com/api/docs/guides/images-vision
Used for OpenAI's patch-based (32x32) and tile-based (512 px) image token schemes, the detail setting, and its limitations list.
Docling Technical Report (opens in a new tab)
Christoph Auer, Maksym Lysak, Ahmed Nassar, Michele Dolfi, et al.2024Preprint
arXiv 2408.09869 (opens in a new tab)https://arxiv.org/abs/2408.09869
Used for Docling is an open-source PDF converter built on DocLayNet layout analysis and TableFormer table-structure recognition.
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
arXiv 2407.01449 (opens in a new tab)https://proceedings.iclr.cc/paper_files/paper/2025/hash/99e9e141aafc314f76b0ca3dd66898b3-Abstract-Conference.html
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)
PDF support (opens in a new tab)
Anthropic2026Documentation
https://platform.claude.com/docs/en/build-with-claude/pdf-support
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.
docling-project (GitHub)2026Repository
https://github.com/docling-project/docling
Used for Docling can run locally, including for sensitive data and air-gapped environments.
Keys: ← → move, Home End first and last, F full screen.