Courses / RAG Systems / Module 12
Module 12: Multimodal RAG: images, tables, page-image retrieval
8 h · theory 2 · hands-on 3 · project 2 · revision 1
You will be able to
- Retrieve pages as images with ColPali-style models
- Answer questions about charts and tables
- Choose between text extraction and page images
- Measure multimodal retrieval
Capstone increment: Page-image retrieval for diagram- and table-heavy documents.
Job-description skills: Multimodal · Lab tools: colpali-engine, pymupdf
1. When the answer is in a picture
Many answers live in charts, diagrams, slides, scanned forms and tables with merged cells. Text extraction flattens or loses them: a revenue chart becomes a few axis labels, an architecture diagram becomes nothing. If users ask about those pages, a text-only system can’t answer however good its retrieval is.
There are two paths. Extract text, tables and image descriptions at ingestion and search text; or retrieve the page images themselves with a vision retrieval model and let a vision-language model read them.
2. Path A: extract and describe
Parse tables into Markdown (Module 2), and caption each figure with a vision-language model at ingestion: what kind of chart it is, the axes, the series, the key numbers and the takeaway. Index captions and table text with the rest. Queries stay cheap and fast, and the hybrid retriever works unchanged.
The risk is that captions miss the detail a user asks about. Store the page image reference with every caption, show the image next to the answer, and spot-check captions against the originals.
3. Path B: retrieve page images with ColPali
ColPali (Faysse and others, 2024) embeds a page image directly: a vision-language model turns the page into about a thousand patch vectors, and queries are scored by late interaction (MaxSim), the same idea as ColBERT in Module 6. No OCR, no layout parsing; on visually rich documents it beats text pipelines on the ViDoRe benchmark.
The cost is storage and compute: about a thousand vectors per page. Binary quantization, token pooling and a first-stage filter keep it manageable; Qdrant and others support multi-vector fields. ColQwen and other variants trade size for quality.
Deep dive
Deep dive: what ColPali stores and how it scores
ColPali skips OCR. A vision-language model (PaliGemma) cuts each page image into a 32 × 32 grid of patches and outputs one 128-d vector per patch: about 1,030 vectors per page including a few extra tokens. The query becomes one vector per token, and pages are scored with the same MaxSim as ColBERT: each query token takes its best-matching patch.
That keeps the layout, tables, charts and fonts that text extraction loses, at a storage cost of about 1,030 × 128 numbers per page. Teams cut it with binary quantization, by pooling neighbouring patches, or by using ColPali only to re-rank pages found by a cheaper text index.
Worked example: storage and work for page-image retrieval
one page: 1,030 vectors × 128 dims × 2 bytes (fp16) = 264 KB 100,000 pages = 26 GB binary quantization: 1,030 × 128 bits = 16.5 KB/page = 1.6 GB query “Q3 revenue by region”: ~6 tokens × 1,030 patches = 6,180 dot products per page
| Rank | Single vector (mean of tokens, cosine) | Late interaction (MaxSim) |
|---|---|---|
| 1 | Electronics refund window 0.92 | Complete returns, shipping and warranty policy 3.00 |
| 2 | Laptop warranty and repairs 0.50 | Electronics refund window 2.93 |
| 3 | Complete returns, shipping and warranty policy 0.31 | Laptop warranty and repairs 2.32 |
| Query token | shipping | courier | PIN code | warranty | repair | invoice | laptops | refundable | 14 days | delivery | packaging | service | max |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| refund | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.43 | 0.00 | 1.00 | 0.00 | 0.00 | 0.00 | 0.00 | 1.00 |
| window | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 1.00 | 0.00 | 0.00 | 0.00 | 1.00 |
| laptops | 0.00 | 0.00 | 0.00 | 0.00 | 0.11 | 0.00 | 1.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 1.00 |
MaxSim = sum of each row’s best match = 3.00. The single vector scores the same document 0.31, because averaging every token into one vector blurs what the document is about: in the long policy, nine tokens about shipping and warranty bury the three that answer the question.
What it costs to store
One 1,024-d float vector each: 4.1 GB · one 128-d fp16 vector per token: 51 GB · ColBERTv2 residual compression (≈36 bytes per vector): 7 GB
Guided experiments
- Compare the two rankings. Why does the single-vector search put the complete policy last, even though it holds the exact answer (“laptops refundable 14 days”)?
- Open the matrix for the policy, then for “Laptop warranty and repairs”. Which query token fails to find a good match in the warranty document? That is the signal MaxSim keeps and averaging throws away.
- A cross-encoder goes further: it reads query and document together, so “window” can attend to “14 days” directly. Why is it then too slow to run over the whole index, and fine for re-ranking the top 20–50?
- Switch to ColPali at 5 million pages. Why do teams pair multi-vector retrieval with compression, or use it only to re-rank candidates from a cheaper first stage?
4. Answer with a vision-language model
Send the top one to three page images, with the question, to a vision-language model and ask it to answer from them and name the page. Image tokens are expensive, so send fewer, well-chosen pages, and resize them to the lowest resolution that keeps the numbers readable.
Keep grounding rules from Module 9: cite the page, refuse when the page doesn’t show the answer, and check numbers the model reads from a chart against the extracted table where one exists.
5. Measure multimodal retrieval
Write golden questions whose answers are only on visual pages: values from charts, cells from complex tables, labels on diagrams. Measure page-level recall@k for each path, plus answer accuracy, latency, storage and cost per question.
Most teams end up with both: text RAG by default and page-image retrieval for slide decks, reports and scans, chosen by document type at ingestion or by a router at query time.
Hands-on: coding window
The coding window and the full VS Code lab are available after you sign in.
Sign in to codeLabs
Lab 12.1: ColPali on visual pages
Index 30 slide and report pages with colpali-engine (or byaldi) on a free GPU and compare page recall@5 with the text path on 15 visual questions.
Expected: Recall@5 for both paths and five examples where they disagree.
Lab 12.2: Answer from page images
Send the top 2 retrieved page images to a vision-language model with a grounded prompt that must name the page. Check 10 numeric answers against the source.
Expected: Answer accuracy and image-token cost per question.
Lab 12.3: Visual route (capstone increment)
Index table- and diagram-heavy documents as page images in a multi-vector collection, and route visual questions there.
Expected: Visual questions are answered with page citations; text questions are unaffected.
Go deeper
Videos
- ColPali: Vision Language Models for Efficient Document Retrieval · Prompt Engineering · ~18 min. ColPali explained with the paper’s key results and a working demo.
- Optimizing Document Retrieval with ColPali and Qdrant's Binary Quantization · Qdrant Vector Search · ~9 min. Making ColPali practical: binary quantization and multi-vector search in Qdrant.
- How to Use Multimodal RAG to Extract Text, Images, & Tables (with Demos) · AWS Developers · ~12 min. The extract-and-describe path for text, images and tables, with demos.
Further reading
- Paper ColPali: Efficient Document Retrieval with Vision Language Models · Faysse et al., 2024. Page-image retrieval with late interaction, and the ViDoRe benchmark it introduced.
- Article ColPali: Efficient Document Retrieval with Vision Language Models · Hugging Face blog. The authors' walk-through with figures of patch embeddings and MaxSim heatmaps.
- Paper ColBERTv2: Effective and Efficient Retrieval via Lightweight Late Interaction · Santhanam et al., 2022. How residual compression shrinks the per-token index enough to use in production.
GitHub repositories
- illuin-tech/colpali: The ColPali and ColQwen model code and the processor that turns pages into patch vectors.
- AnswerDotAI/byaldi: A small wrapper to index and search PDFs with ColPali in a few lines.
- pymupdf/PyMuPDF: Page.get_pixmap(): rendering PDF pages to images at a chosen resolution.
Checkpoint quiz
Interview questions
- How would you build RAG over slide decks and annual reports full of charts?
- Compare captioning figures at ingestion with ColPali-style page retrieval.
- How do you control the storage cost of multi-vector page embeddings?
- How do you evaluate a multimodal RAG system?
- A VLM misreads a number from a chart. How would you detect and reduce this?
Ask the professor
Sign in to ask questions about this module.
Discussion
Community discussion appears here once giscus is configured (see README).