TL;DR
Late interaction is a way to score how well a query matches a document. Each document is turned into one vector per token, and each query is turned into one vector per token. The score adds up, over the query tokens, the best match each one finds among the document tokens. It keeps the offline indexing of a bi-encoder while letting each query word be matched against the most relevant part of the document.
Builds on: Bi-Encoder, Dot Product, Transformer · Leads to: ColPali, which applies the same scoring to page images
Where it's used
Passage search. ColBERT, introduced in 2020, is the original system. It encodes queries and passages separately with BERT and keeps one embedding per passage token. Because the passage embeddings are computed once and stored, a query only needs its own encoding plus a fast scoring pass over the candidates.
Document retrieval for PDFs. ColPali, from 2024, skips text extraction. It embeds the image of each document page as many patch vectors, and scores a text query against them with late interaction. The model is a vision-language model. The paper's motivation is that OCR, layout detection and chunking are the slow part of indexing, and a page encoded as images avoids them.
Retrieval for generation. In a retrieval-augmented generation system, the retriever chooses the passages a language model reads before it answers. A late-interaction retriever chooses them with token-level evidence, so a passage that mentions the exact words of several parts of the question can rank above one that only sounds similar overall.
How it works
Take a tiny index with two documents. Each token has a two-number vector, and every vector has length 1 or less, so dot products stay easy to read; for vectors of length 1 a dot product is exactly a cosine similarity.
- Encode the query. The query has two tokens. Their vectors are and . Check: there is one vector per query token, not one for the whole query.
- Encode document A. Document A has three token vectors: , and . These were computed once, offline, and stored. Check: the stored list has one vector per token.
- Find the best match for each query token. For , the dot products with , and are , and . The best is , from . For , they are , and . The best is , from . Check: each query token picks its own best document token.
- Add the best matches. Document A's score is . Check: every query token contributes exactly once.
- Score document B the same way. Document B has two token vectors: and . For the best dot product is , from . For it is , from . The score is . Check: document B's matches come from different tokens than A's.
- Rank. A scores 1.8 and B scores 1.5, so A is ranked first. Check: the ranking uses the sum of per-token maxima, nothing else.
flowchart LR Q["Query token vectors"] --> M["Dot product with every document token vector"] D["Stored document token vectors"] --> M M --> X["Keep the maximum for each query token"] X --> S["Sum the maxima = relevance score"]
The math
Let the query have token vectors and the document have token vectors , all in the same -dimensional space. The late interaction score is
where is the dot product. The inner maximum picks the best document token for one query token; the outer sum adds these picks over the query.
Step 3 in symbols: the maximum
For a fixed query token , the maximum over is the index of its best partner in the document. It is computed by one dot product per pair, so a query with tokens against a document with tokens needs dot products. Each dot product of -dimensional vectors costs multiplications and additions.
Step 4 in symbols: the sum
The outer sum is over query tokens only, so the score does not grow with document length by itself. Extra document tokens raise the score only when they match a query token better than its current best. This is the reason for summing over the query, not the document.
Beyond the walkthrough: how ColPali trains the score
Step 6 only ranks documents; training needs a loss. ColPali (section 4.1 of its paper) uses an in-batch contrastive loss. For a batch of query-document pairs, the positive score should beat the hardest negative in the batch, . The loss is the Softmax cross-entropy of the positive against that negative, which the paper rewrites in softplus form:
The function is the softplus, a smooth way to penalise the case where a negative scores above the positive. The paper describes the late interaction operation as fully differentiable, so training can flow back into both encoders.
Worked examples
Query vectors and . Document vectors and . Find the late interaction score.
- Dot products for : and . The maximum is .
- Dot products for : and . The maximum is .
- Sum the maxima: .
- Interpretation: the first query token has an exact match and the second has a partial match. The score reflects both, rather than averaging them into one vector first.
Use the same query. Document B has and . Rank A and B.
- Dot products for with B: and . The maximum is .
- Dot products for with B: and . The maximum is .
- Sum: .
- Compare: A scores and B scores , so A ranks first.
- Interpretation: A matches the first query token exactly (1.0) and the second strongly (0.8). B matches the second token exactly (1.0) but the first only weakly (0.5). A wins on the sum of its per-token maxima, so it is ranked first.
Suppose a retriever stores one 128-dimensional vector for each of 1,024 patches of a page, and a query has 15 tokens. Find how many dot products one page needs, and how many multiplications that is. These numbers are for the calculation only, not measured values from any system.
- Count the pairs: dot products per page.
- Count the multiplications in one dot product: .
- Total multiplications: , about 2 million per page.
- Interpretation: a 10,000-page corpus would need about 20 billion multiplications for one query if every page were scored in full. Real systems avoid this with candidate selection and approximate search, see Approximate Nearest Neighbor Search and maximum inner product search.
- Try it: if the page were split into 2 chunks of 512 patches each, and the same 15-token query is scored against each chunk separately, how many dot products are needed in total? Work it out before reading on.
Answer: , the same as before. Splitting a page into chunks does not change the total number of pairs when every token is compared with every token; it only changes how the scores are grouped.
Common mistakes and tradeoffs
It is tempting to think late interaction averages the query vectors and the document vectors and then takes one dot product. In fact each query token keeps its own vector and picks its own best document token. Averaging would lose the token-level matching that is the point of the method.
It is tempting to think a long document automatically scores higher. In fact the score sums over query tokens only, so a document is rewarded for matching the query well, not for having more tokens. The number of document tokens affects the storage and the cost, not the sum.
It is tempting to think late interaction is as cheap as a bi-encoder. In fact the index stores one vector per token rather than one per passage, which takes much more space, and each query pays for many dot products. Engines that index these vectors compactly are needed at scale.
Use late interaction when queries contain several specific terms that must appear in the document, and when the index can hold many vectors per document. For short queries and a tight memory budget, a single-vector bi-encoder is simpler, and for plain keyword matching a lexical ranker such as BM25 may already be enough. When the best accuracy matters more than speed for a short candidate list, a cross-encoder reads the query and document together and is more accurate per pair, at the cost of one full model pass per pair.
History
Dense retrieval with bi-encoders became practical once transformer encoders could produce good sentence and passage vectors; Dense Passage Retrieval is an early example. It made search fast because the documents could be embedded in advance. Its weakness was that one vector per passage compresses away the fine detail of which words match. In 2020 Omar Khattab and Matei Zaharia introduced ColBERT, which kept one BERT vector per token and used the maximum-similarity sum described above. It caught on because it kept the offline indexing of bi-encoders while matching individual query terms, which the single-vector approach could not do. In 2024 ColPali extended the same scoring to vision-language models that embed document page images, which made late interaction an option for visually rich document retrieval, not only for text.
Recap
- A bi-encoder stores one vector per document; late interaction stores one vector per token, which keeps offline indexing.
- The score for a query and a document is .
- Each query token picks its own best document token, and the picks are summed.
- The index is larger than for a bi-encoder, so compact indexing matters at scale.
- Read next: ColPali, for applying the same scoring to page images, and retrieval-augmented generation, for how the retrieved passages are used.
Check yourself
QuestionWhat does each query token contribute to the late interaction score?Show answer
QuestionA query token has dot products 0.2, 0.9 and 0.5 with three document tokens. A second query token has dot products 0.7, 0.1 and 0.4. What is the score?Show answer
QuestionWhy does late interaction use the maximum for each query token rather than averaging all the document token vectors first?Show answer
QuestionA search engine uses late interaction with 10 million documents. What is the main cost compared with a single-vector bi-encoder, and how is it usually handled?Show answer
Sources
- ColBERT: Efficient and Effective Passage Search via Contextualized Late Interaction over BERT, arXiv: https://arxiv.org/abs/2004.12832
- ColPali: Efficient Document Retrieval with Vision Language Models, arXiv: https://arxiv.org/abs/2407.01449