Skip to content
VDAI with VD

Phase 19 · Capstone Projects

Capstone 04 — Multimodal Document QA (Vision-First PDF, Tables, Charts)

The 2026 document-QA frontier moved away from OCR-then-text and toward vision-first late interaction. ColPali, ColQwen2.5, and ColQwen3-omni treat each PDF page as an image, embed it with multi-vector late interaction, and let the query attend to patches directly. On financial 10-Ks, scientific papers, and handwritten notes this pattern beats OCR-first by a large margin. Build the pipeline end to end on 10k pages and publish the side-by-side against OCR-then-text.

  • Capstone
  • Python (pipeline), TypeScript (viewer UI)
  • 30 hours
  • Before this: Phase 4 (computer vision), Phase 5 (NLP), Phase 7 (transformers), Phase 11 (LLM engineering), Phase 12 (multimodal), Phase 17 (infrastructure)

Problem

Enterprises sit on PDFs that OCR pipelines mangle: scanned 10-Ks with rotated tables, scientific papers dense with equations, charts that only make sense as images, handwritten annotations. Treating these as text-first means losing half the signal. The 2026 answer is late-interaction multi-vector retrieval on raw page images. ColPali (Illuin Tech) introduced it; ColQwen2.5-v0.2 and ColQwen3-omni pushed accuracy. On ViDoRe v3, vision-first retrieval scores above OCR-then-text by meaningful margins — and the gap widens on charts, tables, and handwriting.

The trade-off is storage and latency. A ColQwen embedding is ~2048 patch vectors per page, not a single 1024-dim vector. Raw storage balloons. DocPruner (2026) brings 50% pruning without measurable accuracy loss. You will index 10k pages, measure ViDoRe v3 nDCG@5, serve answers under 2s, and compare directly against an OCR-then-text baseline.

Concept

Late interaction means every query token scores against every patch token, and the maximum score per query token is summed. You get fine-grained matching without needing a single pooled vector. A multi-vector index (Vespa, Qdrant multi-vector, or AstraDB) stores the per-patch embeddings and runs MaxSim at retrieval time.

The answerer is a vision-language model that takes the query plus the top-k retrieved pages as images and writes an answer with evidence regions (bounding boxes or page references). Qwen3-VL-30B, Gemini 2.5 Pro, and InternVL3 are the 2026 frontier choices. For equations and scientific notation, an OCR fallback (Nougat, dots.ocr) is spliced in as an optional text channel.

Evaluation is a two-dimensional matrix. One axis: content type (plain text paragraphs, dense tables, bar/line charts, handwritten notes, equations). Other axis: retrieval approach (vision-first late interaction vs OCR-then-text vs hybrid). Each cell gets nDCG@5 and answer accuracy. The report is the deliverable.

Architecture

PDFs -> page renderer (PyMuPDF, 180 DPI)
           |
           v
  ColQwen2.5-v0.2 embed (multi-vector per page, ~2048 patches)
           |
           +------> DocPruner 50% compression
           |
           v
   multi-vector index (Vespa or Qdrant multi-vector)
           |
query ----+----> retrieve top-k pages (MaxSim)
           |
           v
  VLM answerer: Qwen3-VL-30B | Gemini 2.5 Pro | InternVL3
    inputs: query + top-k page images + optional OCR text
           |
           v
  answer with cited page numbers + evidence regions
           |
           v
  Streamlit / Next.js viewer: highlighted boxes on source page

Stack

  • Page rendering: PyMuPDF (fitz) at 180 DPI, portrait-normalized
  • Late-interaction model: ColQwen2.5-v0.2 or ColQwen3-omni (vidore team on Hugging Face)
  • Index: Vespa with multi-vector field, or Qdrant multi-vector, or AstraDB with MaxSim
  • Pruning: DocPruner 2026 policy (keep high-variance patches, 50% compression at < 0.5% accuracy loss)
  • OCR fallback (equations / dense tables): dots.ocr or Nougat
  • VLM answerer: Qwen3-VL-30B self-hosted or Gemini 2.5 Pro hosted; InternVL3 as fallback
  • Evaluation: ViDoRe v3 benchmark, M3DocVQA for multi-page reasoning
  • Viewer UI: Next.js 15 with canvas overlay for evidence regions

Interactive figure coming later.

Build It

  1. Ingest. Walk a corpus of 10k PDF pages across 10-Ks, scientific papers, and scanned documents. Render each page to a 1536x2048 PNG. Persist {doc_id, page_num, image_path}.

  2. Embed. Run ColQwen2.5-v0.2 on each page image. Output shape ~2048 patch embeddings of dim 128. Apply DocPruner to keep the highest-signal half. Write to Vespa multi-vector field or Qdrant multi-vector.

  3. Query. For each incoming query, embed with the query tower (token-level embeddings). Run MaxSim against the index: for every query token, take the max dot-product over page patch embeddings, sum. Return top-k pages.

  4. Synthesize. Call Qwen3-VL-30B with the query and the top-5 page images. Prompt: "Answer using only the supplied pages. Cite each claim by (doc_id, page) and name the region (figure, table, paragraph)."

  5. Evidence regions. Post-process the answer to extract cited regions. If the VLM emits bounding boxes (Qwen3-VL does), render them as overlays in the viewer.

  6. OCR fallback. For pages identified as equation-dense (heuristic on image variance), run Nougat or dots.ocr and pass the OCR text as an extra channel alongside the image.

  7. Eval. Run ViDoRe v3 (retrieval nDCG@5) and M3DocVQA (multi-page QA accuracy). Also run OCR-then-text pipeline on the same corpus with the same synthesizer. Produce a content-type × approach matrix.

  8. UI. Streamlit prototype first; Next.js 15 production viewer with page-by-page evidence-region overlay.

Use It

$ doc-qa ask "what was the 2024 operating margin change for segment EMEA?"
[retrieve]   top-5 pages in 320ms (ColQwen2.5, MaxSim, Vespa)
[synth]      qwen3-vl-30b, 1.4s, cited (form-10k-2024, p. 88) + (..., p. 92)
answer:
  EMEA operating margin moved from 18.2% to 16.8%, a 140bp decline.
  cited: 10-K-2024.pdf p.88 (Table 4, Segment Operating Margin)
         10-K-2024.pdf p.92 (MD&A, Operating Performance)
[viewer]     open with highlighted bounding boxes overlaid on p.88 Table 4

Ship It

outputs/skill-doc-qa.md describes the deliverable: a vision-first multimodal document QA system tuned to a specific corpus and evaluated against an OCR-then-text baseline on ViDoRe v3.

WeightCriterionHow it is measured
25ViDoRe v3 / M3DocVQA accuracyBenchmark numbers vs OCR-text baseline and published leaderboard
20Evidence-region groundingFraction of cited regions that actually contain the answer span
20Storage and latency engineeringDocPruner compression ratio, index p95, answer p95
20Multi-page reasoningAccuracy on a hand-labeled 100-question multi-page set
15Source-inspection UXViewer clarity, overlay fidelity, side-by-side comparison tools
100

Exercises

  1. Measure ColQwen2.5-v0.2 vs ColQwen3-omni on the same corpus. Which pages does one get right and the other miss? Add a "content class" tag to the index to route by type.

  2. Prune embeddings aggressively (75%, 90%). Find the compression cliff: the point where ViDoRe nDCG@5 drops below the OCR baseline.

  3. Build a hybrid: run OCR-then-text and ColQwen in parallel, fuse with RRF, rerank with a cross-encoder. Does the hybrid beat either alone? Where does it help most?

  4. Swap Qwen3-VL-30B for a smaller VLM (Qwen2.5-VL-7B). Measure the accuracy-per-dollar curve.

  5. Add handwritten-note support. Render the handwriting corpus, embed with ColQwen, measure retrieval. Compare against a handwriting OCR pipeline.

Key Terms

TermWhat people sayWhat it actually means
Late interaction"ColPali-style retrieval"Query tokens score against page patches independently; MaxSim aggregates
Multi-vector"Per-patch embedding"Each document has many vectors, not one pooled vector
MaxSim"Late-interaction scoring"For every query token, take max similarity over document vectors; sum
DocPruner"Patch compression"2026 pruning that keeps 50% of patches with negligible accuracy loss
ViDoRe v3"Document-retrieval benchmark"The 2026 standard for measuring visual-document retrieval
Evidence region"Cited bounding box"A bbox on the source page that localizes the answer span
OCR fallback"Equation channel"Text pipeline used alongside vision for equation- or table-heavy pages

Further Reading

Code

  • main.py

    python phases/19-capstone-projects/04-multimodal-document-qa/code/main.pyOpen on GitHub ↗
  • ts/package.json

    Open on GitHub ↗
  • ts/README.md

    Open on GitHub ↗
  • ts/src/fixtures.ts

    npx tsx phases/19-capstone-projects/04-multimodal-document-qa/code/ts/src/fixtures.tsOpen on GitHub ↗
  • ts/src/index.ts

    npx tsx phases/19-capstone-projects/04-multimodal-document-qa/code/ts/src/index.tsOpen on GitHub ↗
  • ts/src/render.ts

    npx tsx phases/19-capstone-projects/04-multimodal-document-qa/code/ts/src/render.tsOpen on GitHub ↗
  • ts/src/server.ts

    npx tsx phases/19-capstone-projects/04-multimodal-document-qa/code/ts/src/server.tsOpen on GitHub ↗
  • ts/src/types.ts

    npx tsx phases/19-capstone-projects/04-multimodal-document-qa/code/ts/src/types.tsOpen on GitHub ↗
  • ts/tests/fixtures.test.ts

    npx tsx phases/19-capstone-projects/04-multimodal-document-qa/code/ts/tests/fixtures.test.tsOpen on GitHub ↗
  • ts/tests/render.test.ts

    npx tsx phases/19-capstone-projects/04-multimodal-document-qa/code/ts/tests/render.test.tsOpen on GitHub ↗
  • ts/tests/server.test.ts

    npx tsx phases/19-capstone-projects/04-multimodal-document-qa/code/ts/tests/server.test.tsOpen on GitHub ↗
  • ts/tsconfig.json

    Open on GitHub ↗

Take-away files

skill-doc-qa.md

---
name: doc-qa
description: Build a vision-first multimodal document QA system on 10k pages with late-interaction retrieval and evidence-region citations.
version: 1.0.0
phase: 19
lesson: 04
tags: [capstone, multimodal, rag, colpali, colqwen, late-interaction, pdf]
---

Given a corpus of PDFs (10-Ks, scientific papers, scanned documents), build a pipeline that indexes pages as images using ColPali-style late interaction and answers questions with page-level evidence regions.

Build plan:

1. Render every PDF page to a 1536x2048 PNG with PyMuPDF at 180 DPI.
2. Embed every page with ColQwen2.5-v0.2 or ColQwen3-omni. Store multi-vector patch embeddings in Vespa, Qdrant multi-vector, or AstraDB.
3. Apply DocPruner-style 50% patch pruning. Verify accuracy drop stays under 0.5% on ViDoRe v3.
4. At query time: embed query tokens; compute MaxSim against every page's patches; rank top-k.
5. Synthesize with Qwen3-VL-30B or Gemini 2.5 Pro passing the query plus top-5 page images. Require cited `(doc_id, page, region)` anchors.
6. For equation- or table-heavy pages, run Nougat or dots.ocr as an optional text channel and feed it alongside the image.
7. Build a Next.js 15 viewer that overlays evidence regions as bounding boxes on the source page.
8. Evaluate on ViDoRe v3 and M3DocVQA. Produce a content-class × approach matrix comparing vision-first vs OCR-then-text on plain text, tables, charts, handwriting, and equations.

Assessment rubric:

| Weight | Criterion | Measurement |
|:-:|---|---|
| 25 | ViDoRe v3 / M3DocVQA accuracy | Benchmark vs OCR-then-text baseline on matched pages |
| 20 | Evidence-region grounding | Fraction of cited regions that contain the answer span |
| 20 | Storage and latency engineering | DocPruner compression, index p95, answer p95 under 2s |
| 20 | Multi-page reasoning | Accuracy on a hand-labeled 100-question multi-page set |
| 15 | Source-inspection UX | Overlay fidelity, comparison tools, page-by-page explorer |

Hard rejects:

- OCR-first pipelines pitched as "vision-first" by retrofitting OCR text into a single-vector embed.
- Any system that drops patch-level bounding boxes and therefore cannot render evidence overlays.
- Storage numbers reported without documenting DocPruner settings.

Refusal rules:

- Refuse to index scanned legal contracts without a dedicated redaction policy. ColQwen embeddings leak content.
- Refuse to serve queries against a corpus the user has not disclosed. Audit trail is mandatory for regulated domains.
- Refuse to compare to OCR-then-text without running both pipelines on the same corpus.

Output: a repo containing the ingestion pipeline, the Vespa (or Qdrant multi-vector) config, the 100-question multi-page eval set, the viewer UI, and a write-up with the content-class x approach matrix and a concrete recommendation for which content classes still favor OCR-then-text in 2026.