Capability notes
Document understanding goes beyond [OCR](/tasks/ocr) to parse document structure, semantics, and relationships. It combines text extraction, layout analysis, table parsing, form field identification, and multi-page reasoning. In 2026, VLMs are the dominant local approach — specialized document models (LayoutLMv3, DiT, DocTR) handle individual subtasks well but VLMs unify the pipeline with competitive accuracy.
DocVQA benchmark (document visual question answering): human 87.1%. GPT-4V: 85.3%. InternVL2-76B: 79.8% — leads open-weight. Qwen2.5-VL 72B: 77.2%. VLMs read document images directly — no OCR pre-processing required. For clean scanned documents (300 DPI, black text on white), VLM text extraction achieves 96–98% character accuracy — below Tesseract (99.2%) and PaddleOCR (99.5%) but sufficient for most applications.
Layout analysis — identifying titles, paragraphs, tables, figures, headers, footers, and reading-order — is where VLMs excel over specialized models. InternVL2-76B segments document into reading-order regions with 88% F1 on PubLayNet (academic papers), 82% on RVL-CDIP (diverse document types — letters, forms, invoices, reports). Specialized LayoutLMv3 achieves 92% but only on document types seen in training — VLMs generalize to novel layouts.
Form parsing — extracting field labels and user-filled values — combines detection (find form fields), OCR (read labels and values), and relationship mapping (this value belongs to that field). VLM zero-shot form parsing accuracy: 72% (correct label→value pairs / total pairs). With few-shot examples of the form type: 85–90%. Handwritten form parsing: 65% VLM vs 82% specialized IAM-trained models.
Table extraction — detecting table regions and reconstructing cell grid with content — is the hardest document understanding sub-task. VLMs reconstruct tables with 70–78% cell accuracy (right content in right cell). Dedicated table extraction models (Table Transformer, TableNet) achieve 88–92% but miss tables embedded in complex multi-column layouts where VLMs' global context helps. Best practice: detect table regions with VLM, extract content with dedicated table model. For recommended models, see [Llama 3.3 70B](/models/llama-3-3-70b). Deploy locally with [Ollama](/tools/ollama) on [RTX 4090](/hardware/rtx-4090).
If you just want to try this
Lowest-friction path to a working setup.
Use [Ollama](/tools/ollama) with a vision model for document Q&A. Install:
```bash
ollama pull llama3.2-vision:11b-instruct-q4_K_M
```
Ask questions about a document image:
```python
import requests, base64
with open("document.jpg", "rb") as f:
img = base64.b64encode(f.read()).decode()
resp = requests.post("http://localhost:11434/api/generate", json={
"model": "llama3.2-vision:11b-instruct-q4_K_M",
"prompt": "This is a scanned document. "
"1. Extract all text from this document. "
"2. Identify the document type (invoice, contract, letter, report, form). "
"3. If it's a form, list all field labels and their filled values. "
"4. If it contains a table, reconstruct it as a CSV.",
"images": [img], "stream": False
})
print(resp.json()["response"])
```
For PDFs, convert pages to images first. Install Poppler (`brew install poppler` on macOS, `apt install poppler-utils` on Linux, or `pip install pdf2image` on Windows) and use:
```python
from pdf2image import convert_from_path
images = convert_from_path("document.pdf", dpi=200)
for i, img in enumerate(images):
img.save(f"page_{i}.jpg")
```
Then analyze each page through the VLM. The 11B model handles clean documents at 2–4 seconds per page on [RTX 3060 12GB](/hardware/rtx-3060-12gb). For complex documents (dense tables, multi-column layouts, mixed fonts), use Qwen2.5-VL 32B via [LM Studio](/tools/lm-studio) — drag and drop PDF pages as images, ask questions in chat.
For form filling automation: VLM identifies fields → you map to your data schema → automated filling. Start with simple forms (contact info, surveys) before attempting complex forms (tax documents, legal filings) where errors have compliance implications.
For production deployment
Operator-grade recommendation.
Production document understanding combines specialized OCR with VLM semantic analysis in a tiered pipeline.
**Tier 1: OCR and layout (always-on, CPU).** PaddleOCR or Tesseract extracts text with bounding boxes. DocTR or LayoutParser segments page into regions (text blocks, tables, figures). This tier catches 95%+ of text with 99%+ character accuracy on clean documents. Throughput on 16-core CPU: 10–30 pages/second at 200 DPI. Cost: CPU-only, negligible.
**Tier 2: Table and form extraction (GPU, conditional).** For pages flagged as containing tables or forms by Tier 1, run dedicated extraction. Table Transformer detects table cells → PaddleOCR reads cell content → grid reconstruction algorithm maps cells to rows/columns. Form detection: LayoutParser identifies key-value pairs → field matching via spatial proximity. Throughput: 2–5 pages/second on [L4](/hardware/nvidia-l4).
**Tier 3: VLM understanding (GPU, conditional).** For pages requiring semantic reasoning (contract clauses, report conclusions, cross-page references), send to VLM. InternVL2-76B on [L40S](/hardware/nvidia-l40s): 2–5 seconds per page. Typical routing: 80% of pages handled by Tier 1+2, 20% escalated to Tier 3. VLM adds cost but handles the 15–20% of pages where layout-based extraction fails.
**Throughput and cost.** 100,000 page document pipeline (invoices, 300 DPI): Tier 1 processes in 1–3 hours on CPU (negligible cost). Tier 2 processes 5,000 table/form pages in 1 hour on L4 GPU (~$0.25). Tier 3 processes 500 complex pages in 30 minutes on L40S (~$0.40). Total pipeline: ~$1–2 for 100K pages. Compare to cloud API (Google Document AI): $1.50/1K pages = $150 for 100K pages. Local is 100×+ cheaper at scale.
**Confidence flags.** Documents with low OCR confidence (<95%), unusual layouts (layout parser confidence <0.7), or mixed handwritten/printed text get flagged for human review. Typical flag rate: 5–15% of pages. Flagged pages route through: higher-resolution scanning (400+ DPI), VLM with few-shot prompting using similar document type, or human operator review queue.
**Compliance domains.** Legal document analysis ([legal analysis task](/tasks/legal-analysis)) and medical document analysis ([medical analysis task](/tasks/medical-analysis)) require 100% on-prem deployment — documents never leave infrastructure. On-prem GPU cluster trivial for SMB volume (1K–10K pages/month) — a single [L40S](/hardware/nvidia-l40s) handles this in 2–20 hours/month.
What breaks
Failure modes operators see in the wild.
**Table spanning across pages.** Symptom: table header on page 3, body rows on pages 3–5, footer on page 5 — extraction produces 3 separate disconnected tables. Cause: page-by-page processing loses cross-page continuity — VLM handles one page at a time with no memory of previous page structure. Mitigation: detect table continuation patterns (repeated header on page 4, "continued" text), merge multi-page table segments before extraction, include previous page's table header in current page prompt.
**Handwritten / mixed text failure.** Symptom: printed form with handwritten values — OCR extracts printed labels at 99% accuracy, handwritten values at 65%. Cause: handwriting recognition is a harder OCR sub-problem — varied stroke styles, connected characters, inconsistent baselines. Mitigation: apply handwriting-specific OCR (TrOCR fine-tuned on IAM, Microsoft's handwritten OCR model) to detected handwriting regions. VLM few-shot with handwriting examples improves cursive extraction 15–20%.
**Checkbox and signature field misreading.** Symptom: VLM reports checkbox as "checked" when it's empty, or "unchecked" when it contains a faint mark. Cause: checkbox state detection requires fine-grained visual discrimination — small marks in small regions confuse coarse VLM features. Mitigation: dedicated checkbox classifier — crop checkbox region, run binary classifier (checked/unchecked) on crop. Signature presence: detect via stroke density heuristic in signature field region — simple CV, <10ms, 98%+ accuracy.
**Multi-column reading order errors.** Symptom: 2-column academic paper — VLM reads across columns: "Introduction Methods Results Discussion" interleaved rather than column-by-column. Cause: VLMs process images as 2D grids with learned attention patterns — reading order is an implicit convention, not an architectural guarantee. Mitigation: pre-segment columns with layout parser, process each column as independent text region, enforce top-to-bottom within-column reading order. Reading-order accuracy improves from 82% (VLM-only) to 96% (layout-guided).
Hardware guidance
**Hobbyist tier ($1,500–2,500).** [RTX 4090](/hardware/rtx-4090) at 24 GB: Qwen2.5-VL 32B at Q4 — 2–5 seconds per page, DocVQA ~70%. Handles personal document analysis (contracts, tax documents, academic papers) at 100–300 pages/hour. [RTX 5090](/hardware/rtx-5090) at 32 GB: same model at Q8 or 72B at Q4 — 3–7 seconds per page at 73–77% DocVQA. 32 GB enables 72B-class models for best personal-tier accuracy.
**SMB tier ($6,000–15,000).** [RTX 6000 Ada](/hardware/rtx-6000-ada) at 48 GB: InternVL2-76B at FP8 — 2–4 seconds per page, DocVQA 78–80%. Handles departmental volume (5K–50K pages/month). 48 GB fits model + KV cache for multi-page document context. [L40S](/hardware/nvidia-l40s) at 48 GB: identical with datacenter reliability — 24/7 document processing.
**Enterprise tier ($25,000+).** [A100 80GB SXM](/hardware/nvidia-a100-80gb-sxm): InternVL2-76B at FP16 — 1.5–3 seconds per page. 80 GB fits full-document context (50+ pages) for cross-page reasoning (contract analysis, legal discovery). [H200](/hardware/nvidia-h200) at 141 GB: handles 100+ page documents with full context retention. [AMD MI300X](/hardware/amd-mi300x) at 192 GB: best for long-document workloads — 200+ page contracts processed with full attention, no page-chunking artifacts.
**CPU preprocessing tier.** Document understanding benefits from CPU preprocessing: image deskewing, contrast normalization, DPI standardization. These run on CPU at 50–200 pages/second without GPU. Dedicate a CPU tier for preprocessing before GPU VLM analysis — reduces GPU pipeline time 15–30% by presenting clean, standardized inputs.
**Apple Silicon.** [MacBook Pro 16" M4 Max](/hardware/macbook-pro-16-m4-max) at 64 GB+: Qwen2.5-VL 72B at Q4 via [MLX-LM](/tools/mlx-lm) — 5–12 seconds per page. Handles personal and SMB volume without dedicated GPU. [Mac Studio M3 Ultra](/hardware/mac-studio-m3-ultra) at 192 GB: runs largest VLMs with full document context — a capable on-prem document understanding server for legal/medical SMBs.
Runtime guidance
**Document understanding toolchain — from PDF to structured data.**
[PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR) is the preferred OCR engine for document understanding pipelines. Multilingual (80+ languages), table structure recognition, layout analysis, and key-value extraction all in one toolkit. Python API: `from paddleocr import PaddleOCR; ocr = PaddleOCR(lang='en'); result = ocr.ocr('document.jpg')`. Output: text, confidence, and bounding box per element. On GPU: 10–30 FPS for text extraction. On CPU: 2–5 FPS. Use for Tier 1 extraction before VLM analysis.
[DocTR](https://github.com/mindee/doctr) (Mindee, Apache 2.0) provides OCR + document analysis with both TensorFlow and PyTorch backends. Strength: document-specific model architectures (recognition models trained on document fonts and layouts, not natural scene text). Output includes reading-order prediction. Python API similar to PaddleOCR. Better on typewritten documents; PaddleOCR better on mixed handwritten/printed.
[LayoutParser](https://github.com/Layout-Parser/layout-parser) for layout analysis and region detection. Integrates with Detectron2 for deep learning-based layout detection and Tesseract/OCR engines for text extraction. Output: document object model (DOM-like) with regions, their types, and relationships. Useful for pre-segmenting documents before VLM analysis.
[Ollama](/tools/ollama) with vision models for VLM document Q&A. Use after OCR for semantic questions: "does this contract contain a non-compete clause?" "what is the total amount on this invoice?" VLM queries are 5–10× more expensive than OCR extraction — reserve for questions requiring reasoning.
[pgvector](/tools/pgvector) or [Qdrant](/tools/qdrant) for document retrieval. After extracting text + structure from documents, embed chunks for semantic search. [BGE-M3](/models/bge-m3) embeddings on document chunks enable cross-document Q&A: "show me all contracts with indemnification clauses exceeding $1M."
**End-to-end pipeline.** PDF → pdf2image (200–300 DPI) → PaddleOCR (text + layout) → [BGE-M3](/models/bge-m3) embeddings → [pgvector](/tools/pgvector) storage → user question → retrieval (find relevant document chunks) → VLM (answer question with retrieved context). This combines fast retrieval (milliseconds) with deep understanding (seconds) — retrieves relevant pages first, then runs expensive VLM on only those pages. 90%+ of queries answered from retrieval cache; 10% require VLM.
Hardware buying guidance for Document Understanding
RAG workflows mix embedding throughput, long-context inference, and reasonable VRAM headroom. The guides below cover the buyer decision honestly.