Search

Search papers and lessons

Late Interaction

Level 4 · 10 min read

Late interaction stores one vector per token and scores a query against a document by matching each query token with its best document token, combining the cheap indexing of bi-encoders with finer matching.

On this page

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

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.

  1. Encode the query. The query has two tokens. Their vectors are q1=(1,0)q_1 = (1, 0) and q2=(0,1)q_2 = (0, 1). Check: there is one vector per query token, not one for the whole query.
  2. Encode document A. Document A has three token vectors: a1=(1,0)a_1 = (1, 0), a2=(0.6,0.8)a_2 = (0.6, 0.8) and a3=(0,0.5)a_3 = (0, 0.5). These were computed once, offline, and stored. Check: the stored list has one vector per token.
  3. Find the best match for each query token. For q1q_1, the dot products with a1a_1, a2a_2 and a3a_3 are 11, 0.60.6 and 00. The best is 11, from a1a_1. For q2q_2, they are 00, 0.80.8 and 0.50.5. The best is 0.80.8, from a2a_2. Check: each query token picks its own best document token.
  4. Add the best matches. Document A's score is 1+0.8=1.81 + 0.8 = 1.8. Check: every query token contributes exactly once.
  5. Score document B the same way. Document B has two token vectors: b1=(0,1)b_1 = (0, 1) and b2=(0.5,0.5)b_2 = (0.5, 0.5). For q1q_1 the best dot product is 0.50.5, from b2b_2. For q2q_2 it is 11, from b1b_1. The score is 0.5+1=1.50.5 + 1 = 1.5. Check: document B's matches come from different tokens than A's.
  6. 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

Definition: Late interaction score

Let the query have NqN_q token vectors Eq(i)\mathbf{E}_q^{(i)} and the document have NdN_d token vectors Ed(j)\mathbf{E}_d^{(j)}, all in the same DD-dimensional space. The late interaction score is

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, \dots, N_d\}} \langle \mathbf{E}_q^{(i)}, \mathbf{E}_d^{(j)} \rangle,

where ⟨⋅,⋅⟩\langle \cdot, \cdot \rangle 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 ii, the maximum over jj is the index of its best partner in the document. It is computed by one dot product per pair, so a query with NqN_q tokens against a document with NdN_d tokens needs Nq×NdN_q \times N_d dot products. Each dot product of DD-dimensional vectors costs DD multiplications and D−1D - 1 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 bb query-document pairs, the positive score sk+=LI(qk,dk)s_k^+ = \text{LI}(q_k, d_k) should beat the hardest negative in the batch, sk−=max⁡l≠kLI(qk,dl)s_k^- = \max_{l \neq k} \text{LI}(q_k, d_l). The loss is the Softmax cross-entropy of the positive against that negative, which the paper rewrites in softplus form:

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

The function log⁡(1+ex)\log(1 + e^{x}) 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

Example
1. Two query tokens, one document (hand-computable)

Query vectors q1=(1,0)q_1 = (1, 0) and q2=(0,1)q_2 = (0, 1). Document vectors a1=(1,0)a_1 = (1, 0) and a2=(0.6,0.8)a_2 = (0.6, 0.8). Find the late interaction score.

  1. Dot products for q1q_1: ⟨q1,a1⟩=1\langle q_1, a_1 \rangle = 1 and ⟨q1,a2⟩=0.6\langle q_1, a_2 \rangle = 0.6. The maximum is 11.
  2. Dot products for q2q_2: ⟨q2,a1⟩=0\langle q_2, a_1 \rangle = 0 and ⟨q2,a2⟩=0.8\langle q_2, a_2 \rangle = 0.8. The maximum is 0.80.8.
  3. Sum the maxima: 1+0.8=1.81 + 0.8 = 1.8.
  4. 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.
Example
2. Ranking two documents (standard case)

Use the same query. Document B has b1=(0,1)b_1 = (0, 1) and b2=(0.5,0.5)b_2 = (0.5, 0.5). Rank A and B.

  1. Dot products for q1q_1 with B: ⟨q1,b1⟩=0\langle q_1, b_1 \rangle = 0 and ⟨q1,b2⟩=0.5\langle q_1, b_2 \rangle = 0.5. The maximum is 0.50.5.
  2. Dot products for q2q_2 with B: ⟨q2,b1⟩=1\langle q_2, b_1 \rangle = 1 and ⟨q2,b2⟩=0.5\langle q_2, b_2 \rangle = 0.5. The maximum is 11.
  3. Sum: 0.5+1=1.50.5 + 1 = 1.5.
  4. Compare: A scores 1.81.8 and B scores 1.51.5, so A ranks first.
  5. 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.
Example
3. The cost of a page of patches (realistic)

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.

  1. Count the pairs: 15×1024=1536015 \times 1024 = 15360 dot products per page.
  2. Count the multiplications in one dot product: 128128.
  3. Total multiplications: 15360×128=1,966,08015360 \times 128 = 1{,}966{,}080, about 2 million per page.
  4. 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.
  5. 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: 15×512×2=1536015 \times 512 \times 2 = 15360, 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 LI(q,d)=∑imax⁡j⟨Eq(i),Ed(j)⟩\text{LI}(q, d) = \sum_i \max_j \langle \mathbf{E}_q^{(i)}, \mathbf{E}_d^{(j)} \rangle.
  • 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
Its maximum dot product with any document token vector. The score is the sum of these maxima over all query tokens.
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
The maxima are 0.90.9 and 0.70.7, so the score is 0.9+0.7=1.60.9 + 0.7 = 1.6.
QuestionWhy does late interaction use the maximum for each query token rather than averaging all the document token vectors first?Show answer
Averaging blends every document token into one vector, which can hide a single exact match behind many unrelated tokens. The maximum keeps the best match for each query term, so an exact match for one term counts fully even when the rest of the document is unrelated.
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
The index stores one vector per token rather than one per document, so storage and the number of dot products per query grow. It is usually handled with compact index formats and candidate selection, so that full scoring runs only on a short list of documents.

Sources

Late Interaction — explained simply · ungoon.me