Late interaction (ColBERT)

In one sentence

Store one vector per token instead of one per passage, and score with MaxSim at query time: precision close to a cross-encoder, with documents still pre-computed offline, paid for in storage.

Analogy: A single vector is a one-line book blurb. Late interaction keeps a sticky note on every word, and at query time checks each of your keywords against its best-matching note.

All the expensive encoding of documents happens offline; query time is one short encoder pass plus matrix products.

How it works

  • MaxSim matches token by token: each query token takes its best document token, and the maxima are summed.
  • It works as a reranker: score a hybrid top 200 with ColBERT instead of 200 cross-encoder passes.
  • Storage is the catch: a 300-token chunk takes ~77 KB uncompressed, versus ~4 KB as one vector.
  • ColBERTv2 shrinks the index 6–10× with residual compression, and PLAID prunes candidates before full scoring.
  • ColPali applies it to page images, one vector per patch, so tables and charts are retrieved without OCR.

Check yourself

Answer to mark it learned; your answers aren't scored.

Hybrid search gives you a good top 200, but the right page for queries with exact error codes like E1043 rarely reaches the top 10. A cross-encoder over 200 pairs blows your latency budget. Best next step?

Go deeper

Full explanation

Late interaction keeps one embedding per token instead of squeezing a whole passage into one vector, and compares query and document token by token at search time.

The scoring rule is MaxSim: for each query token, find its most similar document token (dot product), then sum those maxima over the query. So "rotate API keys" can match "key rotation for the API" token by token, even when the passage's averaged meaning drifted elsewhere.

It sits between the two architectures you already know:

  • Bi-encoder (one vector): documents encoded offline, one dot product per document. Fast, but one vector blurs details.
  • Cross-encoder (Reranking (cross-encoders)): query and document read together. Most precise, but nothing can be pre-computed.
  • Late interaction: document token vectors are pre-computed offline like a bi-encoder; only the cheap MaxSim runs at query time.

The catch is storage: a 300-token chunk becomes ~300 vectors of 128 dims instead of one. ColBERTv2 stores each as a centroid id plus a 1–2-bit residual per dimension (6–10× smaller), and the PLAID engine prunes candidates through those centroids before full scoring. ColPali applies the same idea to page images: one vector per image patch, so PDFs with tables and charts are retrieved without OCR.

Code MaxSim by hand, then with a library
pythonMaxSim by hand, then with a library
import numpy as np

def maxsim(q: np.ndarray, d: np.ndarray) -> float:
    """q: (n_q, 128) query token vectors; d: (n_d, 128) doc token vectors; both L2-normalized."""
    sims = q @ d.T                        # every query token vs every doc token
    return float(sims.max(axis=1).sum())  # best doc token per query token, summed

# Common production shape: late interaction as a cheap reranker
candidates = hybrid_search(query, k=200)            # stage 1: recall
q_vecs = encode_query(query)                        # ~32 vectors, one short pass
scored = [(maxsim(q_vecs, token_store[c.id]), c) for c in candidates]  # doc vecs precomputed
top = [c for _, c in sorted(scored, key=lambda x: x[0], reverse=True)[:10]]

# Or a full ColBERTv2 index (PLAID, compressed) via RAGatouille
from ragatouille import RAGPretrainedModel

RAG = RAGPretrainedModel.from_pretrained("colbert-ir/colbertv2.0")
RAG.index(collection=docs, index_name="kb")
results = RAG.search("how do I rotate API keys?", k=10)
Real example

An internal code-docs search uses a single-vector embedder and keeps missing queries like "error E1043 on ARM builds": the error code and the platform get averaged away into "build problems". The team keeps hybrid search as stage 1 (top 200) and reranks with a ColBERT model. Document token vectors were computed at ingestion, so query time is one encoder pass over ~32 query tokens plus 200 small matrix products, instead of 200 full transformer passes for a cross-encoder. The E1043 token now finds a near-exact match and the right page moves into the top 3.

Trade-offs +4 · −3

+ You gain

  • Better retrieval than single-vector embeddings on exact terms, rare entities and out-of-domain text.
  • Documents are encoded offline: query cost is one short encoder pass plus matrix products.
  • Interpretable: you can see which document token each query token matched.
  • ColPali extends it to page images, skipping OCR and layout parsing.

− You pay

  • Storage: hundreds of vectors per chunk instead of one, even after compression.
  • Fewer managed options and more operational work than a plain vector database.
  • Still below a strong cross-encoder on the hardest relevance judgments.

Use it when

When single-vector retrieval is the bottleneck, queries carry exact identifiers or rare terms, or you need a reranker cheaper than a cross-encoder. ColPali for visually rich PDFs where parsing loses meaning.

Avoid it when

Small corpora where a cross-encoder over the top 50 is cheap enough, huge corpora on a tight storage budget, or teams without capacity to run a less standard index. Try Hybrid search & RRF plus a reranker first.

Numbers to know 5
  • ColBERT: 128-dim vector per token; queries padded or truncated to 32 tokens.
  • Uncompressed: 300 tokens × 128 dims × 2 bytes (fp16) ≈ 77 KB per chunk vs ~4 KB for one 1,024-dim fp32 vector.
  • ColBERTv2 residual compression (1–2 bits per dimension): 6–10× smaller index.
  • PLAID: up to ~7× lower latency on GPU and ~45× on CPU vs vanilla ColBERTv2.
  • ColPali: ~1,000 patch vectors of 128 dims per page image.
Common pitfalls 3
  • Brute-forcing MaxSim over the whole corpus: use a PLAID-style engine, or MaxSim only to rerank a first-stage pool.
  • Sizing infrastructure with single-vector math and discovering the per-token storage multiplier in production.
  • Assuming an English MS MARCO checkpoint works on multilingual or domain data: evaluate, or pick a multilingual model.
Interview questions 2

Answer out loud first, then reveal.

Where does ColBERT sit between bi-encoders and cross-encoders?Show answer

It's about when query and document interact. A bi-encoder never lets them interact: one vector each, a single dot product. A cross-encoder interacts at every layer, so nothing can be pre-computed. ColBERT interacts late: documents are encoded offline into per-token vectors, and at query time I only compute MaxSim — each query token's best-matching document token, summed. I keep token-level precision while paying only a short query encoding and matrix products. The cost moves to storage, which is why ColBERTv2's compression and PLAID matter.

Would you use late interaction as your first-stage retriever or as a reranker?Show answer

It depends on corpus size and storage budget. For a few million passages, a full ColBERTv2/PLAID index is affordable and usually gives better first-stage quality than dense vectors. At larger scale I'd keep a cheap first stage, hybrid BM25 plus dense, and use MaxSim to rerank the top 100–500, keeping token vectors in cheap storage instead of an ANN index. That captures most of the gain at a fraction of cross-encoder latency. I'd decide with recall@k and nDCG on our own eval set, not on public benchmark numbers.