Knowledge: Documents
How AI reads documents: OCR, layout and visual search
Most business documents are not clean text but scans, forms, tables and multi-column PDFs. Whether AI can pull the right answer out of them is usually decided at the reading stage, long before a language model ever answers. There are three ways to make documents machine-readable, and each has its own point of failure.
AI-GENERATED Short answer
AI understands documents in three ways: optical character recognition turns pixels into characters, layout-aware models map those characters onto headings, tables and fields, and visual search models compare a question directly with the image of the page. For exact values, recognised text is hard to avoid. For finding the right page, visual search is often more robust.
Definition
Document analysis: Document analysis is the automated processing of documents as text, structure and image. It covers optical character recognition, which turns pixels into characters, layout analysis, which determines headings, tables and reading order, and visual search, which compares pages directly as images. The goal is either to extract values reliably, or to find the right page for a question.
In the glossary: Optical character recognition, Visual document search, Late interaction, Multimodal model, Computer vision, Embedding, Retrieval, Gold-standard test set, Evaluation
01
What does it mean for AI to understand a document?
AI understands a document when it does three things: recognise the characters, map them onto the page's structure, such as a table cell, heading or form field, and connect both to a question or a target schema. Each layer builds on the one beneath it, so errors at the bottom propagate upward.
A digitally created PDF already contains a text layer, whereas a scan is only pixels. An invoice table is unambiguous to the eye, but to a machine it starts out as a set of characters with coordinates. Whether the number 240 is a quantity or an amount is not written in the digits themselves, but in the column they sit in.
| Layer | Question | Typical technique | Typical failure |
|---|---|---|---|
| Characters | Which letters and digits are here? | Optical character recognition (OCR) | Confused characters, dropped umlauts, unreadable scans |
| Structure | What does this character belong to? | Layout analysis, layout-aware models | Columns merged, table rows shifted, reading order wrong |
| Meaning | Does the page answer my question? | Extraction into a schema, semantic or visual search | Correct text found on the wrong page, or the wrong field filled in |
All three layers keep coming up. How retrieved passages become an answer with a citation is covered in Retrieval-augmented generation explained. Where documents fit into the bigger picture of capturing, finding and maintaining knowledge is covered in Knowledge management with AI.
02
How does a classic OCR pipeline work?
A classic OCR pipeline first prepares the image: deskewing, rotation and contrast. A layout analysis step then finds text blocks and lines, a recognition model reads each line, and post-processing checks the result against dictionaries or formats. The output is text with coordinates that can be searched, copied and processed further.
- 01Prepare the imageDeskew, rotate, adjust contrast
- 02Find the layoutBlocks, columns, lines
- 03Recognise linesCharacter sequence per line
- 04Post-processDictionary, formats, confidence
- 05Text with coordinatesSearchable, verifiable
Modern OCR tools no longer recognise letter by letter but read whole lines with neural networks. The open-source engine Tesseract, for example, includes a recognition system based on recurrent networks (LSTM) that, according to the project documentation, works as a line recogniser and needs roughly ten times the compute of the older recogniser (Tesseract documentation). The gain in accuracy comes at the cost of compute.
The pipeline's weak point is rarely character recognition itself, but the step before it. If layout analysis misses two columns, recognition reads straight across the column boundary, and every line produces a grammatically plausible but factually wrong sentence. The result looks clean and is still useless. These silent errors are exactly what makes OCR the most common source of error in document projects, as the glossary entry on OCR also notes.
03
What can layout-aware models do when they read text and position together?
Layout-aware models process each word's position on the page as well, often together with the image itself. That lets them learn that a value to the right of "Date" is a date, and a number in the third table column is an amount. They handle form and table tasks noticeably better than models that only see the character sequence.
LayoutLM (Xu et al., KDD 2020) laid the groundwork: the model was the first to be pre-trained jointly on text and layout positions, and according to the paper improved the form-understanding score from 70.72 to 79.27. Successors such as LayoutLMv3 (Huang et al., ACM Multimedia 2022) process text and image patches in a single transformer and learn which parts of the image belong to which words.
A second branch skips upstream OCR entirely. Donut (Kim et al., ECCV 2022) reads the page image directly and produces structured output. The authors justify this with three drawbacks of classic pipelines: the compute cost of OCR, poor flexibility across languages and document types, and OCR errors propagating into every downstream step. Today's multimodal language models, which process image and text together, continue that line (multimodal model).
Layout analysis as a task in its own right
How well a system recognises blocks depends heavily on the documents it learned from. The DocLayNet dataset (Pfitzmann et al., KDD 2022) was annotated by humans, distinguishes 11 layout classes and deliberately covers a range of document types. The authors show that models trained on it generalise better across document types than models that have only seen scientific papers.
Three ways to read a page
| Criterion | Classic OCR | Layout-aware model | OCR-free image model |
|---|---|---|---|
| Input | Page image | Text, coordinates, often the image | Page image |
| Output | Text with coordinates | Fields, classes, structure | Structured text or an answer |
| Strength | Traceable, copyable, good for full text | Forms, tables, fixed fields | No OCR errors as a starting point |
| Weakness | Loses structure | Depends on OCR quality and training documents | Harder to verify, can invent values |
| Verifiability | High: every character has a position | Medium: fields come with a confidence score | Lower: output has no direct source location |
04
How does visual document search work with models like ColPali?
Visual document search splits every page into many small image patches and computes a vector for each one. The search query is likewise broken into vectors, one per token. During matching, every query token looks for its best-matching patch, and the top scores are summed. That lets the search find pages whose information sits in the layout.
ColPali (Faysse et al., arXiv 2024, published at ICLR 2025) embeds document page images directly, according to the paper, and matches them using the late interaction principle. The authors introduced the ViDoRe benchmark alongside it, because existing search systems mostly score extracted text and ignore visual cues such as tables, charts and font sizes. By their measurements, the approach outperforms classic pipelines while also being simpler to build.
Capture pages as images
Every page is rendered or scanned. No OCR is needed for the search itself.
Embed the patches
The model divides the page into a grid of small patches and produces a vector for each one, so a single page ends up described by many vectors.
Embed the query
The question is broken into tokens, and each one gets its own vector.
Compare late
For every query token, only the most similar page patch counts. The sum of these best scores becomes the page's score. The method is called MaxSim and comes from ColBERT (Khattab and Zaharia, SIGIR 2020).
Re-rank the candidates
In practice, a faster search often narrows down the candidates first, and the expensive comparison only runs over those pages.
The main drawback is storage: many vectors per page take up a multiple of the index a single text vector would need. Smaller models shift that calculation. ModernVBERT (Teiletche et al., arXiv 2025) needs only 250 million parameters and, according to the paper, outperforms models up to ten times its size once fine-tuned for document search. The OCR-free document stack lays out the building blocks, and Late interaction explained goes deeper on the late interaction principle.
05
Extraction or search: which task should document AI actually solve?
Extraction and search need different things. Extraction transfers values into a fixed schema, such as a date, case number or reading, and needs exact characters to do it. Search must find the right page for a question and tolerates small character errors as long as the page turns up. Naming the task first picks the right technique.
Which technique fits which task
| Criterion | Extraction | Search and question answering | Making an archive searchable |
|---|---|---|---|
| Goal | Transfer values into fields | Find the matching page for a question | Make a collection searchable and citable |
| Needs exact characters | Yes | No, the page is what counts | Yes, for full text and citations |
| Obvious core | OCR plus layout-aware extraction with validation rules | Visual search or hybrid text search | OCR with a text layer, complemented by visual search |
| Key metric | Share of correctly filled fields | Recall within the first k results | Character error rate and findability |
| Typical risk | A plausible but wrong value | The right answer pulled from the wrong page | Silent errors in the text that nobody notices |
Many projects need both. A proven pattern is to split the work: visual search finds the handful of relevant pages, and only those get a thorough OCR pass whose result is cited or processed further. That keeps the expensive stage small and stops OCR errors from spoiling the search in the first place. Classic OCR alongside visual search describes this split using a concrete model.
06
Why do tables, scans and handwriting fail so often?
Tables, scans and handwriting fail because their information does not sit in the characters alone. In tables it sits in rows and columns, in scans the image itself is already degraded, and in handwriting the characters themselves vary. Public benchmarks show that no single approach leads across all document types, so testing on your own collection is what decides it.
| Case | What goes wrong | What helps |
|---|---|---|
| Tables | Cells shift, merged cells and header rows get lost | Recognise and measure table structure specifically, for example with TEDS; for search, compare the page as an image |
| Tables spanning pages | The continuation is read as a new table with no header row | Process across pages, or carry header rows forward deliberately |
| Poor scans | Skew, shadows, stamps over the text | Pre-process the image, check scan resolution, flag uncertain spots |
| Multi-column pages | Reading order jumps between columns | Layout analysis with reading order, spot-check against the original |
| Handwriting | High error rate, large variation between writers | Set expectations accordingly, always route handwritten fields to human review |
| Charts and drawings | Carry information but almost no text | Visual search to find them, description by a multimodal model only with review |
The authors of OmniDocBench (Ouyang et al., CVPR 2025) find that classic pipelines and end-to-end vision-language models each have their own strengths and weaknesses depending on document type. That is an argument against picking an approach purely by leaderboard rank.
07
When is classic OCR still the better choice?
Classic OCR is the better choice whenever you need the actual characters: for full-text search across an archive, for quoting and copying, as an audit trail, for handing exact values to other systems, and for documents whose information sits almost entirely in running text. Visual search delivers a page, not text, and does not substitute for any of these tasks.
- Full text and quotes: A result that a person needs to copy or quote verbatim requires recognised text.
- Audit trail: Anyone who has to prove which word at which position a value came from needs characters with coordinates.
- Running text with simple layout: For reports, minutes or contracts with plain formatting, text search is cheaper and good enough.
- Handing off to systems: Databases and line-of-business applications expect values, not page images.
Common assumptions about document AI
Only for part of the job.
Visual search finds pages more robustly, but delivers no copyable text. OCR is still needed for quotes, full text and exact values, often as a second stage over the pages it found.
False.
Vision-language models can plausibly fill in values that are not actually on the page. Without checking against the source location, a fabricated amount goes unnoticed.
Not necessarily.
The text layer may come from an old, faulty recognition pass, or hold columns in the wrong order. A copy test reveals this quickly.
Rarely reliable.
Benchmarks use specific document types, often in English. German forms, stamps and technical terms behave differently and belong in a test set of their own.
Not any more.
Compact models with a few hundred million parameters run on modest hardware. The bigger cost factor is often the storage for the index, not the model.
08
How do you check the quality of document AI?
You check document AI quality layer by layer: character error rate for OCR, structural fidelity for tables, share of correct fields for extraction, and recall for search. The basis is a test set of your own, difficult documents with verified expected values. A single overall score hides which layer the error actually comes from.
| Layer | Metric | What it shows |
|---|---|---|
| Characters | Character error rate (CER) and word error rate (WER) | Share of inserted, missing or swapped characters or words against the reference |
| Structure | Tree-edit distance for tables (TEDS) | How close the recognised table structure, including cell content, is to the correct one |
| Extraction | Field accuracy by field type | Which fields are reliable and which belong under review |
| Search | Recall within the first k results (Recall@k) | Whether the right page is even among the candidates |
Checklist
Building a test set for document AI
For the team comparing approaches. Nothing here is saved.
Checking AI answers goes deeper on how to judge a system's answers against the documents it retrieved, that is, faithfulness to the source and relevance.
09
How do you pick the right approach for your own document collection?
Three questions decide the right approach: does the task need exact characters or the right page? Does the layout carry the information, as in tables and forms? And are the documents allowed to leave your own network? The answers determine whether OCR, visual search or a combination takes centre stage, and what gets tested first.
Decision path
OCR, visual search, or both?
Three questions that show where a test should start.
All questions and results as a list
- Does the end result need to be exact values or citable text?
- Yes, continue with: Do users also need to ask the collection open-ended questions?
- No, it is about finding things, continue with: Does the information often sit in tables, forms, charts or scans?
- Do users also need to ask the collection open-ended questions?
- Yes, Result: Test a combination
- No, Result: Extraction with validation rules
- Does the information often sit in tables, forms, charts or scans?
- Yes, Result: Visual search first
- No, mostly running text, Result: Text search is probably enough
- Result: Test a combinationWhat to work out: which pages visual search should find first, and which of those get a thorough OCR pass. The test set then needs both reference pages for questions and reference values for fields.
- Result: Extraction with validation rulesWhat to work out: which fields are needed, which validation rules protect them, and at what uncertainty level a person decides instead. Layout-aware models are worth comparing against plain OCR.
- Result: Visual search firstWhat to work out: which documents your current search fails on, and how large the index gets with many vectors per page. A small model is often the more honest place to start.
- Result: Text search is probably enoughWhat to work out: whether the existing text layer is clean, and whether a hybrid search combining keywords and meaning covers what users actually ask. Visual search can always be added later.
The third question, whether documents may leave the building, changes the choice more than any leaderboard. OCR, layout models and compact visual search models all run on your own hardware today. Local language models explains what running models locally requires.
iiterate Technologies GmbH builds AI applications and custom software from architecture through implementation to operation, on client infrastructure or in EU hosting, with a focus on RAG, local language models and integration with existing systems (Services).
Read more on iiterate.de
Deeper dives in Signals
- Signal Done with OCR? Visual document search Why searching the page image helps exactly where tables and scans throw OCR off.
- Signal The OCR-free document stack The building blocks of visual search from encoder to vector database, with their limits.
- Signal Late interaction explained The MaxSim matching principle without formulas, and its two-stage implementation.
- Signal ModernVBERT: a small model built for on-premises use Why a compact model makes visual search realistic on your own hardware.
- Signal Classic OCR alongside visual search How OCR and image search take on separate jobs within the same system.
- Signal Reading long documents in a single pass An approach that processes long PDFs without splitting them, with checkpoints before going into production.
Implementation and tools
- Consulting Document AI Invoices, receipts and forms turned into structured data with validation rules.
- Consulting RAG implementation How document search and a language model combine into a system that answers with sources.
- Tool RAG readiness check A self-test of how well your documents and organisation are prepared for a search system.
- R&D Lab Vellum: a document scanner without the cloud Edge detection, deskewing and OCR all run directly on the phone.
More in Knowledge
- Knowledge Knowledge management with AI The overview of capturing, finding, applying and maintaining knowledge with AI.
- Knowledge Semantic search in the enterprise Keyword search, vector search and hybrid methods, with metrics for relevance.
- Glossary Visual document search in the glossary The short definition, with links to related terms.
Frequently asked questions
Can a multimodal language model replace OCR entirely?
For some tasks, yes, such as answering a question about a single page. As a replacement for traceable OCR it only works with caveats, because its output carries no per-character coordinates and it can plausibly invent values. Wherever values get processed further or quoted, checking against the source location is necessary.
Does document AI work with German documents and umlauts?
Broadly yes, though quality varies between models more than it does for English text. Umlauts in poor scans, long compound words, technical abbreviations and older typefaces are the critical cases. Public benchmarks say little about this. A test set built from your own German documents quickly shows which approach holds up.
How much more storage does visual search need than text search?
Considerably more, because a page is described not by one vector but by many. The exact factor depends on the model, vector size, compression and page count. It is common to put a faster search in front and only run the expensive comparison over the candidates. Work through the index size against your own page count before deciding.
How do you handle tables that span multiple pages?
Processing page by page loses the header row on the continuation, leaving values with no meaning attached. The fix is a method that reads several pages together, or post-processing that carries header rows forward onto continuations. Such tables deliberately belong in the test set, because benchmarks rarely include them.
Do documents have to go into a cloud for AI analysis?
No. OCR, layout models and compact models for visual search can all run on your own hardware, so documents never leave the network. The limit sits more with very large vision-language models, whose hardware needs grow accordingly. Local language models covers which model size fits which hardware.
What is the difference between layout analysis and extraction?
Layout analysis determines which regions of a page are a heading, paragraph, table, figure or form field, and in what order they should be read. Extraction uses that structure to transfer specific values into a fixed schema. Good layout analysis is therefore a precondition for reliable extraction, but it does not replace it.
Read on
Related topics
Sources
- 01 ColPali: Efficient Document Retrieval with Vision Language Models arXiv (ICLR 2025), 2024 · arxiv.org
- 02 ModernVBERT: Towards Smaller Visual Document Retrievers arXiv, 2025 · arxiv.org
- 03 ColBERT: Efficient and Effective Passage Search via Contextualized Late Interaction over BERT arXiv (SIGIR 2020), 2020 · arxiv.org
- 04 LayoutLM: Pre-training of Text and Layout for Document Image Understanding arXiv (KDD 2020), 2019 · arxiv.org
- 05 LayoutLMv3: Pre-training for Document AI with Unified Text and Image Masking arXiv (ACM Multimedia 2022), 2022 · arxiv.org
- 06 OCR-free Document Understanding Transformer arXiv (ECCV 2022), 2021 · arxiv.org
- 07 DocLayNet: A Large Human-Annotated Dataset for Document-Layout Analysis arXiv (KDD 2022), 2022 · arxiv.org
- 08 Image-based table recognition: data, model, and evaluation arXiv, 2019 · arxiv.org
- 09 DocVQA: A Dataset for VQA on Document Images arXiv (WACV 2021), 2020 · arxiv.org
- 10 OmniDocBench: Benchmarking Diverse PDF Document Parsing with Comprehensive Annotations arXiv (CVPR 2025), 2024 · arxiv.org
- 11 Overview of the new neural network system in Tesseract 4.00 Tesseract OCR Projekt, o. J. · tesseract-ocr.github.io
Let us talk about your project
Whether it is a prototype, an internal tool or an AI application: describe briefly what you are building or want to take into production.