Skip to main content
HS
HiSETSuccess
LeetCode Prep

AI & FDE Interview Room

Role paths, mocks, cost studio, chapters, cases, and staff-level depth.

Case study · Architect · 40 min

Multimodal Document Understanding

Extract structured answers from PDFs with tables, charts, and scanned pages using OCR plus multimodal models.

visionOCRRAG

Interview opener

Ingest PDFs with tables and diagrams for Q&A.

  1. 1.Table cell answers are wrong — which pipeline stage failed?
  2. 2.OCR garbage on scans — degrade how?
  3. 3.Do you embed images, captions, or both?

Strong signals

Hit 0/3

Weak signals (avoid)

  • Naive text extract only
  • One embedding space for everything without thought

Requirements

  • Functional: upload PDF; ask questions; extract tables to CSV; cite page numbers
  • Non-functional: ingest 50-page PDF < 90s; Q&A p95 < 8s
  • Accuracy: table cell F1 ≥ 0.85 on finance corpus; OCR CER < 2% on clean scans
  • Scale: 5,000 docs/day; avg 20 pages; 20K questions/day

Back-of-envelope Estimation

MetricCalculationResult
Pages/day5,000 × 20100,000
Vision tokens/page~1,000 (tile encoding)1K
Ingest vision tokens100K × 1K100M/day
Vision cost @ $3/1M100M × $3/1M~$300/day
OCR CPU hours100K pages × 0.5s~14 CPU-hours
Q&A cost20K × 4K tokens × $2/1M~$160/day

API Design

EndpointMethodDescription
POST /v1/documentsPOSTUpload PDF → job_id
GET /v1/documents/{id}GETStatus, page count, parse quality
POST /v1/documents/{id}/askPOSTQuestion → answer + page citations
GET /v1/documents/{id}/tables/{tid}GETCSV/JSON table export

Data Model

EntityKey fieldsNotes
documentsdoc_id, pages, parse_status, storage_uriObject store for originals
pagespage_id, doc_id, text, layout_json, image_uriLayout: blocks, tables, figures
tablestable_id, page_id, cells[][]Normalized grid
chunkschunk_id, page_id, modality, embeddingText + caption embeddings

High-level Design

Ingest pipeline
PDF → Object store → Page splitter
         ├─► Digital text layer? ──yes──► Layout parser
         │                         no──► OCR (+ deskew)
         ├─► Table detector → structure model → cells
         ├─► Figure captioner (VLM) → text captions
         └─► Chunk + embed → Vector index

Ask: query → retrieve pages/chunks → VLM or text LLM → cite pages

Deep Dive: When to Use VLM vs OCR

  • Native PDF text: skip OCR; use layout-aware chunking
  • Scanned docs: OCR first; use VLM only for charts/figures
  • Complex tables: dedicated structure model cheaper than full-page VLM
  • Hybrid Q&A: retrieve text first; escalate page image to VLM if confidence low

Bottlenecks at Scale

  • VLM GPU queue — route charts-only pages; batch tiles
  • Large scanned PDFs — parallelize per page with concurrency caps
  • Storage of page images — compress; lifecycle policy 30/90 days

Failure Modes & Monitoring

SLOTargetAlert
Ingest p95< 90s for 50 pagesWarn if > 3 min
Table F1 (weekly)≥ 0.85Warn on drop
Q&A p95< 8sWarn if > 12s
Parse failure rate< 1%Page on spike