Search

Search papers and lessons

ColPali: Efficient Document Retrieval with Vision Language Models

Manuel Faysse, Hugues Sibille, Tony Wu et al. · 2024

ColPali searches document pages by their images instead of OCR text: a vision-language model turns each page into many vectors, and a late-interaction score ranks pages against the query.

On this page

  • Colour = topic mix
  • Neural network basics
  • Calculus
  • Discrete math
  • Linear algebra
  • Probability
  • Language & LLMs
  • ReadReady to readNot yet

TL;DR

Most search systems for PDFs first turn each page into text (parsing, OCR, chunking, captions) and then search that text. ColPali skips the text step: a vision-language model reads the page image and produces about a thousand small vectors, one per image patch, and a late-interaction score matches a query against them. On the authors' new ViDoRe benchmark it reaches an average nDCG@5 of 81.3, against 65.5 to 67.0 for the strongest text pipelines in their table.

Builds on: Vision-Language Model, Bi-Encoder, Late Interaction · Leads to: later visual retrievers such as ColQwen2, which the paper itself tests as a stronger backbone

Why it mattered

Retrieval-augmented generation depends on finding the right page before a model can answer from it. ColPali showed that a single vision-language model, trained on query-page pairs, can replace a multi-stage PDF ingestion pipeline and still win on accuracy. Its public release (models, training data, code and the ViDoRe leaderboard) turned "retrieve by page image" from an idea into something other groups could benchmark and fine-tune. The paper's own follow-up tests (Section 6) include a Qwen2-VL backbone that scores 86.6 on the same benchmark average, which the authors read as a sign that better vision-language models make better visual retrievers.

History

Before 2020, document retrieval mostly meant text search over OCR output or parsed PDFs. Dense text retrieval grew around bi-encoders such as Dense Passage Retrieval (2020), and late interaction arrived with ColBERT in 2020, which kept one vector per token so that scoring could be fine-grained while the index was still built ahead of time. Vision-language models followed a separate path: contrastive models such as CLIP (2021) and SigLIP (2023) aligned images with text, but were not trained for matching a query to a long, text-heavy page.

ColPali (2024) joined these two lines. Its authors took PaliGemma, a vision-language model in which image patches feed a language model, and trained it with ColBERT's late-interaction loss on query-page pairs. They also released ViDoRe, a benchmark for page-level retrieval across ten datasets, because they found that existing benchmarks measured text passages or natural images, not document pages. The benchmark and the released models made the comparison easy to repeat, and the storage costs the method creates can be cut with compression methods that the paper cites.

The problem

A search system for documents is judged on three things, which the paper names R1 (retrieval quality), R2 (query latency) and R3 (indexing throughput, that is how many pages can be embedded per unit of time). Before this paper, the standard pipeline for a PDF was:

  • extract words with a PDF parser or OCR;
  • detect layout (titles, tables, figures, headers);
  • cut the text into chunks with some sense of meaning;
  • optionally write a caption for each figure or table so that a text model can see it.

The authors measured where the quality came from. Changing the text embedding model made little difference; changing what the ingestion pipeline kept made a large one. On the same chunks, a plain BM25 ranker and a strong dense text encoder (BGE-M3) were close: with OCR, their average nDCG@5 was 65.5 and 66.1. The bottleneck was that figures, tables and layouts were thrown away or turned into lossy text before any model saw them. Indexing was also slow: the authors report about 7.22 seconds per page for the Unstructured pipeline in their setting, most of it spent on layout detection, OCR and captioning.

The question is then: can a model read the page image directly and be good enough at retrieval that the pipeline is unnecessary?

How it works

The walkthrough below follows one query and one page through the system, using the paper's architecture.

  1. Offline, index a page. Take a page as an image. The image is cut into a fixed grid of patches. In PaliGemma's vision encoder this gives 1024 patches.
  2. Run the vision-language model over the image tokens and a short text prompt. The patch embeddings enter a language model (Gemma 2B inside PaliGemma 3B) together with a fixed prompt, "Describe the image", which the paper adds as six text tokens. The model produces one output vector per token, so about 1030 vectors for the page.
  3. Project each vector down. A linear layer maps every output vector to 128 dimensions, the size used in the ColBERT paper. The page is now a matrix with about 1030 rows and 128 columns, and it is stored once in the index.
  4. Online, embed the query. The query text goes through the same language model and projection. Each query token gets its own 128-dimensional vector. The paper also appends five special query-augmentation tokens.
  5. Score the page with late interaction. For each query vector, find the page vector it matches best (largest dot product). Add those best matches up over all query vectors. That sum is the score of the page.
  6. Rank. Do step 5 for every page in the corpus and sort. The top pages go to the user, or to a language model that writes the answer.
flowchart LR
  A[Page image] --> B[Patches through<br/>PaliGemma 3B]
  B --> C[About 1030 vectors<br/>projected to 128-d]
  C --> D[(Index)]
  Q[Query tokens] --> E[Same model<br/>and projection]
  E --> F[Late interaction:<br/>best page match per query token, summed]
  D --> F
  F --> G[Ranked pages]

The key design choice is step 2: the image tokens and the text tokens are read by one model, so the query is compared with image content that already carries the model's language understanding. The rest is the late-interaction scoring from Late Interaction, which keeps the page vectors separate so they can be indexed ahead of time.

The math

The paper writes the query as Eq∈RNq×D\mathbf{E_q}\in\mathbb{R}^{N_q\times D} and the page as Ed∈RNd×D\mathbf{E_d}\in\mathbb{R}^{N_d\times D}, where NqN_q and NdN_d are the numbers of vectors and D=128D=128 is the projected dimension. Each row is one token (query) or one patch (page).

Step 5 in symbols: the late-interaction score

LI(q,d)=∑i=1Nqmax⁡j∈[1,Nd]⟨Eq(i) ∣ Ed(j)⟩\text{LI}(q,d)=\sum_{i=1}^{N_q}\max_{j\in[1,N_d]}\langle \mathbf{E_q}^{(i)}\,|\,\mathbf{E_d}^{(j)}\rangle

Read it from the inside out. ⟨Eq(i) ∣ Ed(j)⟩\langle \mathbf{E_q}^{(i)}\,|\,\mathbf{E_d}^{(j)}\rangle is the dot product of query vector ii with page vector jj, a single number that is large when the two point the same way. The max⁡\max over jj keeps the best page vector for query vector ii. The sum over ii adds one such best match per query vector. The paper uses a dot product here, not the normalised Cosine Similarity.

Training in symbols: the contrastive loss

Training uses a batch of bb query-page pairs {qk,dk}\{q_k,d_k\}, where dkd_k is the correct page for qkq_k. Write sk+=LI(qk,dk)s_k^{+}=\text{LI}(q_k,d_k) for the score of the correct page and sk−=max⁡l≠kLI(qk,dl)s_k^{-}=\max_{l\neq k}\text{LI}(q_k,d_l) for the best-scoring wrong page in the batch. The loss is the Cross-Entropy Loss of picking the correct page, with the wrong pages in the batch as competitors. The paper rewrites it with the Softmax denominator in a numerically stable form:

L=1b∑k=1blog⁡(1+exp⁡(sk−−sk+))\mathcal{L}=\frac{1}{b}\sum_{k=1}^{b}\log\left(1+\exp\left(s_k^{-}-s_k^{+}\right)\right)

The function log⁡(1+ex)\log(1+e^{x}) is the softplus function. It is near 0 when sk+s_k^{+} is well above sk−s_k^{-} and grows roughly linearly when the wrong page wins. Because LI\text{LI} is built from maxima and sums of dot products, gradients flow through it, so the whole model is trained end to end.

Worked examples

Example
1. A toy page with two patches (hand-made numbers, not from the paper)

Query has two token vectors, q1=(1,0)\mathbf{q}_1=(1,0) and q2=(0,1)\mathbf{q}_2=(0,1). Page A has three patch vectors (0.9,0.1)(0.9,0.1), (0.2,0.8)(0.2,0.8), (0.1,0.1)(0.1,0.1).

  1. For q1\mathbf{q}_1 against page A: dot products are 0.90.9, 0.20.2, 0.10.1. The best is 0.90.9.
  2. For q2\mathbf{q}_2 against page A: dot products are 0.10.1, 0.80.8, 0.10.1. The best is 0.80.8.
  3. Add the two best matches: LI=0.9+0.8=1.7\text{LI}=0.9+0.8=1.7.
  4. Page B has vectors (0.6,0.6)(0.6,0.6) and (0.3,0.2)(0.3,0.2). For q1\mathbf{q}_1 the best dot product is max⁡(0.6,0.3)=0.6\max(0.6,0.3)=0.6. For q2\mathbf{q}_2 it is max⁡(0.6,0.2)=0.6\max(0.6,0.2)=0.6. So LI=1.2\text{LI}=1.2.
  5. Page A scores higher, 1.7>1.21.7 \gt 1.2, so it ranks first.

Interpretation: each query token only needs one good patch on the page. Page A has a patch that matches the first query token strongly and a different one that matches the second, so it wins even though page B has patches that are moderately similar to both.

Example
2. One pair in the training loss

Take one query in a batch, with a correct page scoring s+=2.0s^{+}=2.0 and the best wrong page in the batch scoring s−=0.5s^{-}=0.5.

  1. Compute the gap s−−s+=0.5−2.0=−1.5s^{-}-s^{+}=0.5-2.0=-1.5.
  2. Compute exp⁡(−1.5)≈0.2231\exp(-1.5)\approx 0.2231.
  3. Compute log⁡(1+0.2231)=log⁡(1.2231)≈0.2014\log(1+0.2231)=\log(1.2231)\approx 0.2014.
  4. This is the loss for this query. A query whose wrong page scored 2.52.5 instead would have gap +0.5+0.5 and loss log⁡(1+e0.5)≈0.974\log(1+e^{0.5})\approx 0.974, so the loss rises sharply when a wrong page competes closely.
  5. Check with the softmax form: e2e2+e0.5≈7.3899.038≈0.8175\frac{e^{2}}{e^{2}+e^{0.5}}\approx \frac{7.389}{9.038}\approx 0.8175, and −log⁡(0.8175)≈0.2014-\log(0.8175)\approx 0.2014. The two forms agree.

Interpretation: training pushes the correct page's best-match sum above the strongest wrong page in the batch, and the loss saturates towards 0 once the margin is large.

Example
3. Storage per page, from the paper's own numbers

The paper reports 257.5 KB per page for ColPali stored in float16. Reproduce it from the parts.

  1. A page gives 1024 image-patch vectors, plus the six text tokens, so Nd=1030N_d = 1030 vectors.
  2. Each vector has D=128D=128 numbers.
  3. Each number takes 2 bytes in float16, so one page is 1030×128×2=263,6801030 \times 128 \times 2 = 263{,}680 bytes.
  4. Divide by 1024 to express it in KiB: 263,680/1024=257.5263{,}680 / 1024 = 257.5. This matches the paper's 257.5 KB if "KB" means 1024 bytes.
  5. For comparison, the paper reports 8.60 KB per page for BGE-M3. ColPali uses about 30 times as much space per page.
  6. The paper's token pooling (mean-pooling groups of patches, with a pool factor of 3) cuts the vector count by 66.7% and keeps 97.8% of performance on average, which brings the index down to roughly a third of the size.

Interpretation: the larger index is the real cost of the method. The paper argues the cost is acceptable because centroid clustering or binary quantisation can cut storage by about two orders of magnitude with minimal performance loss, citing Santhanam et al.

Try it: A corpus has 1 million pages, each stored at the paper's exact size of 1030×128×2=263,6801030 \times 128 \times 2 = 263{,}680 bytes with no pooling. Roughly how much disk space does the index need, in gigabytes (1 GB = 10910^{9} bytes), and about how much after the pool-factor-3 reduction that the paper describes? Answer: 1,000,000×263,680=263.68×1091{,}000{,}000 \times 263{,}680 = 263.68 \times 10^{9} bytes, so about 264 GB. With the 66.7% cut in vectors the index keeps about one third of that, roughly 88 GB.

Common mistakes and tradeoffs

It is tempting to think ColPali is just "a better OCR". In fact it never produces text: the model reads pixels and the score is computed between query tokens and image patches. The paper's interpretability figure shows that the query token for "hour" gives high similarity to both the words "hourly" and "hours" in the page image, and to the chart's x-axis, which the authors read as OCR-like behaviour without an OCR step.

It is tempting to think a single vector per page is enough. For documents it is not: a page holds many separate pieces of information (a table, a headline, a figure), and one pooled vector averages them away. The ColBERT-style multi-vector store keeps them apart, which is where most of the gain over bi-encoders comes from. The paper's single-vector BiPali model scores 58.8 on average, against 81.3 for ColPali.

It is tempting to think ColPali is cheap. At query time it is not much slower than a text encoder (about 30 ms against about 22 ms for BGE-M3 in the paper's setting, for a single query), and it is much faster to index, since a page needs one forward pass instead of a parsing pipeline. But it costs about 30 times more storage per page, and it needs a GPU-sized model to embed pages.

When to use it: a corpus of visually rich pages (scanned forms, slides, reports, tables and figures) where the ingestion pipeline is the slow or lossy part, and where you can afford a larger index. When not to use it: plain-text corpora where a BM25 or text bi-encoder already works, or settings with very tight storage. Alternatives the paper tests are the captioned or OCR pipelines (strong but slow to index), contrastive single-vector models such as SigLIP (fast but weak here), and cross-encoders, which score a query with each page jointly and are too slow to run over a whole corpus.

Results

The main table of the paper (Table 2) reports nDCG@5 on ten ViDoRe datasets. The academic datasets are ArxivQ, DocQ, InfoQ, TabF and TATQ; the practical ones are Shift, AI, Energy, Government and Healthcare. The averages below are the paper's own.

SystemAverage nDCG@5
Unstructured text-only + BM25not reported as an average in the paper
Unstructured + OCR + BM2565.5
Unstructured + OCR + BGE-M366.1
Unstructured + Captioning + BGE-M367.0
SigLIP (vanilla, single vector)51.4
BiPali (single vector, PaliGemma)58.8
ColPali (late interaction)81.3

What they mean:

  • Multi-vector scoring is the step that matters most. The single-vector BiPali model, which uses the same backbone, reaches 58.8. ColPali reaches 81.3.
  • The gap is largest on the visually hard sets. On ArxivQ, ColPali scores 79.1 against 40.1, the best text-pipeline score there (BM25 with captioning). On InfoQ it scores 81.8 against 71.9, the best text-pipeline score there (BGE-M3 with captioning). Both comparisons are read from Table 2.
  • Query latency: Section 3 says every system evaluated answers queries in at most 22 ms on an NVIDIA L4. Section 5.2 puts BGE-M3's query encoding at about 22 ms and ColPali's at about 30 ms (batch size 1, averaged over 1000 queries). The two statements do not quite agree, so read ColPali's query cost as roughly 20 to 30 ms.
  • Indexing is much faster: the paper's Table 5 gives 7.22 s per page for Unstructured with captioning, 0.39 s for ColPali and 0.12 s for vanilla SigLIP.
  • Ablations (Section 6): halving the patches to 512 costs 24.8 nDCG@5 points; a larger backbone (ColQwen2 on Qwen2-VL, 768 patches) scores 86.6, which is 5.3 above ColPali; training only on the external DocMatix dataset costs 2.2 points.

Limits: the benchmark's practical queries are generated by Claude-3 Sonnet, with every one checked by human annotators, and the practical tasks have 100 queries over 1000 pages per topic, so small differences between systems are not reliable. The storage cost is large in the paper's own numbers. The paper evaluates page-level retrieval only, not answer generation.

Reading guide

Recap

  • Text-based document search loses visual information during parsing, OCR and captioning, and that loss, not the text embedding model, limits quality.
  • ColPali embeds each page image directly with a vision-language model into about 1030 vectors of size 128.
  • Query tokens are scored against page vectors with late interaction: for each query vector take the best dot product over the page's vectors, then sum.
  • Training uses an in-batch contrastive loss on that score, so the whole system is end to end.
  • On ViDoRe the authors report an average nDCG@5 of 81.3, versus 65.5 to 67.0 for the best text pipelines in their table, at much lower indexing latency and higher storage cost.

Read next: the Late Interaction lesson for the scoring rule in general, and Retrieval-Augmented Generation for the setting where this retrieval step feeds a language model.

Check yourself

QuestionRecall: what does the late-interaction score sum over, and what does it take the maximum over?Show answer
The score sums over the query's vectors, one term per query token. For each query vector it takes the maximum dot product over all of the page's vectors. So each query token is matched with its single best page patch, and the page score is the sum of those best matches.
QuestionA query has 3 token vectors. For a page, their best dot products with the page's vectors are 0.7, 0.4 and 0.9. What is the late-interaction score?Show answer
The score is the sum of the three best matches: 0.7+0.4+0.9=2.00.7 + 0.4 + 0.9 = 2.0.
QuestionWhy does ColPali keep one vector per patch instead of pooling a whole page into one vector, and what does that cost?Show answer
A page holds many different pieces of information (tables, headlines, figures), and a single pooled vector averages them together, so a query about one detail is matched poorly. Keeping one vector per patch lets each query token find its own best match, which is why the paper's multi-vector model scores 81.3 against 58.8 for the single-vector BiPali. The cost is storage: 257.5 KB per page in float16 against 8.60 KB for BGE-M3 in the paper's table.
QuestionA team's pipeline spends most of its indexing time on OCR and layout detection. Based on the paper, what would switching to ColPali change, and what would it not fix?Show answer
It would remove the parsing, layout and captioning stages from indexing, which the paper measures as the slow part (7.22 s per page for the Unstructured pipeline against 0.39 s for ColPali). It would not reduce storage, which grows to about 257.5 KB per page, and it would not remove the need for a model at query time, since queries are encoded by the same vision-language model.
QuestionIn the training loss, the correct page scores 1.0 and the best wrong page in the batch scores 1.0. Compute the loss for that query.Show answer
The gap is s−−s+=0s^{-}-s^{+}=0, so the loss is log⁡(1+e0)=log⁡2≈0.693\log(1+e^{0})=\log 2\approx 0.693. A tie between the correct and the best wrong page gives this value, and the loss falls as the correct page pulls ahead.

Sources

Read the full paper

Manuel Faysse, Hugues Sibille, Tony Wu et al., 2024. arXiv:2407.01449