TL;DR
ColBERT is a way to search a large collection of text passages with a BERT-based model without paying BERT's full cost for every query. It encodes the query and each passage separately, keeps one vector per token of every passage, and scores a passage by matching each query token to its best passage token and adding those matches up. The passage vectors are computed once, ahead of time, so a query only needs a short pass through BERT plus a cheap scoring step. On the MS MARCO benchmark it ranks almost as well as the BERT re-rankers of its day, over 170 times faster per query in re-ranking, and it can search the whole collection instead of only re-ranking a short list.
Builds on: Late Interaction, BERT, Approximate Nearest Neighbor Search · Leads to: ColPali, which applies the same scoring to images of document pages
Why it mattered
By 2019, BERT-based rankers had the best scores on MS MARCO, the standard benchmark for passage search, but they were slow. The paper measured one BERT base re-ranker at 10,700 milliseconds per query on a single Tesla V100 GPU, to re-rank 1,000 candidates. ColBERT did the same job in 61 milliseconds with almost the same score. That gap is what made BERT-quality ranking practical for a search service that must answer in well under a second.
The idea lasted beyond the paper. ColPali (2024) uses the same late interaction scoring over vectors made from page images, so a retriever can search PDFs without first extracting their text. The paper also reports that Google and Bing had adapted BERT for their own search, which shows how much interest there was in putting BERT-quality ranking into production.
The history of the idea runs as follows. Neural ranking models such as KNRM and Duet were cheap but less accurate than what BERT later offered. BERT, released in 2018, made it possible to fine-tune one deep model for many language tasks, and in 2019 Nogueira and Cho applied it to passage re-ranking with large gains over earlier models. Those gains came with a heavy price per query, which is the problem ColBERT set out to fix. Document expansion methods such as doc2query and DeepCT moved expensive language-model work into the indexing step, but they still relied on word-based scoring. Hofstätter and colleagues published the Transformer-Kernel model at about the same time. The ColBERT paper, by Omar Khattab and Matei Zaharia, was published at SIGIR in 2020. It caught on because it kept the advance computation of bi-encoders and the token-level matching of BERT re-rankers in one scoring rule, and it could plug into vector search libraries.
The problem
Search has two jobs: find candidates quickly, then order them well. Classic candidate finders such as BM25 count words and weigh them by rarity. They are fast but miss passages that answer a question in different words. BERT fixes this by reading the query and the passage together, so each word can attend to every other word. The price is that every query-passage pair needs its own full BERT pass. The paper's table gives BERT base about 97 trillion floating point operations per query to re-rank 1,000 candidates.
Two existing designs sit at the ends of this trade-off:
- A Bi-Encoder encodes the query and the passage separately, each into one vector. The passage vectors can be computed in advance, so search is a fast lookup. But one vector per passage has to summarize every word, so fine details are lost.
- A Cross-Encoder reads the query and passage together. It is accurate, but it cannot be run ahead of time, and each candidate costs a full model pass.
The question ColBERT asks is whether a model can keep the fine matching of the second design while doing most of its work in advance, like the first. A second, practical question follows: can the same scoring run directly on a vector index, so that search does not depend on a candidate list from BM25 at all?
How it works
Here is the method as the paper runs it, in order: encode the passages offline, store them, encode the query, match, sum, rank. We follow one tiny example through the steps. The numbers are illustrative: each vector has two numbers and length 1, where the real model uses 128 numbers per vector. Each dot product below is a plain multiply-and-add.
- Encode a passage once, offline. Take passage X, which has three kept tokens after punctuation is removed. BERT reads the passage, a linear layer turns each token into a short vector, and each vector is scaled to length 1. The result is three vectors: , and . Check: , so has length 1.
- Store the vectors. Keep all of them on disk, 16 or 32 bits per number. Check: passage X now costs three vectors, not one. Storage grows with the number of tokens.
- Encode the query. The query has two tokens. Its vectors are and . The real encoder pads the query to 32 positions with
[mask]tokens, and each position gets its own vector. Check: , so has length 1. - Find the best match for each query vector. For , the dot products with passage X are , and . The best is , from . For , they are , and . The best is , from . Check: each query vector picks its own best passage vector, and the two picks can come from different tokens.
- Add the best matches. Passage X scores . Check: each query vector contributes exactly once.
- Score passage Y the same way. Passage Y has vectors and . For the dot products are and , so the best is . For they are and , so the best is . Passage Y scores . Check: Y's best match for is only partial, while X's is exact.
- Rank. X scores 1.96 and Y scores 1.76, so X comes first. Check: the ranking uses only these sums.
flowchart LR P["Passage tokens, encoded once offline"] --> PV["One vector per passage token, stored"] Q["Query tokens, encoded per query"] --> QV["One vector per query token"] PV --> M["Dot product of each query vector with each passage vector"] QV --> M M --> X["Keep the best passage vector for each query vector"] X --> S["Sum the best matches = relevance score"]
There are two ways to use these scores. In re-ranking, a candidate list from BM25 (the paper uses the top 1,000) is scored exhaustively, as in the example above. In end-to-end retrieval, step 4 is replaced by a lookup in a vector index over all passage vectors, followed by exact scoring of the candidates it returns. The math section explains the second route.
Worked examples
The query has one vector . The passage has two vectors, and . Find the score.
- Dot product with : .
- Dot product with : .
- The maximum is , from . There is only one query vector, so the sum has one term.
- Score: .
- Interpretation: the query vector matches one passage vector exactly. The second passage vector is related but weaker, and it does not affect the score.
The query has and . Passage A has and . Passage B has and . Rank A and B.
- For A and : the dot products are and . The maximum is .
- For A and : the dot products are and . The maximum is .
- Score of A: .
- For B and : the dot products are and . The maximum is .
- For B and : the dot products are and . The maximum is .
- Score of B: . So A ranks first, with against .
- Interpretation: A matches the first query vector exactly and the second partly. B matches the second exactly and the first only weakly. The score rewards the sum of each query vector's best match.
Table 1 of the paper reports 10,700 milliseconds for BERT base re-ranking and 61 milliseconds for ColBERT, both per query on one V100 GPU.
- Speed-up in latency: . The paper states it as "over 170 times".
- Latency per query for ColBERT: 61 milliseconds, so one GPU serving queries one at a time handles queries per second.
- Interpretation: the 61 milliseconds includes gathering the passage vectors from memory and moving them to the GPU. The paper notes that this transfer can be the most expensive step, and that query encoding and scoring take only 13 milliseconds of the total.
- Try it: a service re-ranks 1,000 candidates per query on one GPU, and each query has a budget of 2 seconds. Each ColBERT re-ranking takes 61 milliseconds. How many queries can one GPU answer, one after another, within 2 seconds?
Answer: , so about 32 queries in the 2 seconds. Running several queries at once on the GPU would serve more, but the paper does not measure that.
The math
Let be the set of query vectors and the set of passage vectors, each of length 1. The relevance score of passage for query is
where "" is the dot product. When both vectors have length 1, the dot product equals the cosine similarity. The inner maximum is called MaxSim: it is the best match for one query vector. The outer sum adds one MaxSim per query vector.
Step 2 in symbols: the encoders
The passage encoder runs BERT on the passage with a [D] marker after [CLS], applies a linear layer that maps BERT's hidden size (768 for BERT base) down to numbers, normalizes each vector, and then drops the vectors of punctuation tokens:
The query encoder puts a [Q] marker after [CLS], pads the query with [mask] tokens to a fixed length , and keeps a vector for every position:
Normalize divides a vector by its length, . Padding with [mask] lets BERT write useful contextual vectors into positions that have no word of their own. The paper calls this query augmentation.
Step 4 in symbols: the best match
For one query vector , the maximum over takes dot products, one per passage vector. A query with vectors against a passage with vectors therefore needs dot products, each of 128 numbers. That is cheap compared with running BERT again on every pair.
Step 5 in symbols: training
Training uses triples : a query, a relevant passage and a non-relevant passage. Each passage gets a score from the same formula, and the loss is the softmax cross-entropy over the two scores. A softmax turns the two scores into two probabilities that sum to 1, and the loss is the negative log of the probability given to the relevant passage:
The paper fine-tunes BERT together with the linear layer and the [Q] and [D] marker embeddings, using Adam with a learning rate of and batches of 32. The MaxSim step itself has no trainable parameters.
End-to-end search in symbols
Let all passage vectors be stored in an index. For each query vector , the index returns the nearest passage vectors, so the candidate set is the union of the passages those vectors came from. The paper uses . The candidate set is then rescored with the exact . For end-to-end retrieval the paper uses squared L2 distance between vectors, . For unit vectors this equals , so ranking by smallest squared distance is the same as ranking by largest dot product.
The index is an IVFPQ index, short for inverted file with product quantization. K-means clustering splits the vector space into cells. Each query vector searches only its nearest cells. Each 128-number vector is split into sub-vectors, and each sub-vector is compressed to one byte with product quantization. Distances are then computed on the compressed codes, which is much faster but less exact. The exact rescoring step corrects for part of that loss.
Results
Re-ranking the official BM25 top 1,000 on MS MARCO (development set). MRR@10 is the mean over queries of of the first relevant passage, counting only ranks up to 10:
| Method | MRR@10 (Dev) | Re-ranking latency (ms) | FLOPs per query |
|---|---|---|---|
| BM25 (official) | 16.7 | not applicable | not applicable |
| Duet | 24.3 | 22 | 159 billion |
| BERT base (Nogueira and Cho, 2019) | 34.7 | 10,700 | 97 trillion |
| BERT base (the authors' training) | 36.0 | 10,700 | 97 trillion |
| BERT large (Nogueira and Cho, 2019) | 36.5 | 32,900 | 340 trillion |
| ColBERT (over BERT base) | 34.9 | 61 | 7 billion |
Recall@ is the share of queries whose relevant passage appears among the top results. Recall@50 asks whether the right passage is in the first 50.
End-to-end retrieval from all 8.8 million passages:
| Method | MRR@10 (Dev) | Latency (ms) | Recall@50 | Recall@1000 |
|---|---|---|---|---|
| BM25 (Anserini) | 18.7 | 62 | 59.2 | 85.7 |
| docTTTTTquery | 27.7 | 87 | 75.6 | 94.7 |
| ColBERT, L2 (end-to-end) | 36.0 | 458 | 82.9 | 96.8 |
The end-to-end score is higher than the re-ranking score (34.8 for the same model), which the paper attributes to better recall: passages that BM25 never put in its top 1,000 can now be found. The paper also reports that ColBERT's Recall@50 (82.9) is higher than the official BM25 Recall@1000 (81.4).
On TREC CAR, a Wikipedia-based dataset, BM25 with ColBERT reaches a MAP of 31.3, against 31.0 for BM25 with BERT base and 33.5 with BERT large, and 15.3 for plain BM25.
The ablations (Figure 5 of the paper) compare variants of the same model. The paper reports that using a single vector per query and passage is considerably less effective, that replacing the maximum with an average lowers accuracy, and that removing query augmentation also lowers MRR@10.
The paper's storage results (Table 4) show the cost of the index. With 128-dimensional vectors stored as 4-byte numbers, the collection needs 286 GiB. With 24-dimensional vectors stored as 2-byte numbers it needs 27 GiB, and MRR@10 drops from 34.9 to 33.9.
Tradeoffs and common mistakes
It is tempting to think ColBERT is just BM25 with better word weights. In fact, each vector is contextual: the vector for "bank" depends on the words around it, so "bank" near "river" and "bank" near "loan" get different vectors. A query vector can match a passage token that is not the same word, because the best match is judged by the vectors, not by spelling.
It is tempting to think storing one vector per token is a small cost. In fact the index grows with the number of tokens, which is why the storage numbers above matter in practice.
It is tempting to think the speed comes from a smaller model. In fact both encoders are BERT base. The speed comes from moving passage encoding offline and running BERT once on the query, so the per-candidate work is a set of dot products rather than a BERT pass.
When to use it. Use ColBERT-style scoring when the ranking must be accurate, the collection is too large for a cross-encoder to score every candidate, and there is memory for many vectors per passage.
When not to use it. If the index memory budget is tight, a single-vector Bi-Encoder is simpler and smaller. If the query is a few exact keywords, BM25 may already be enough. If only a short list must be ordered and accuracy matters most, a Cross-Encoder is the simplest accurate option.
| Approach | What is computed ahead of time | Work per query | Index size |
|---|---|---|---|
| BM25 | Word counts and lengths | Lookup in an inverted index | Small |
| Bi-encoder | One vector per passage | One query encoding and a vector search | One vector per passage |
| Cross-encoder | Nothing | One BERT pass per candidate | None beyond the text |
| ColBERT | One vector per passage token | One query encoding, dot products, sums | One vector per token |
Limits. The benchmarks are English passage search tasks. MS MARCO gives one or very few relevant passages per query, so the scores measure finding those passages, not full relevance. The latency numbers depend on the hardware the authors used and include data transfer to the GPU. The authors say that quantization, shorter query padding, and keeping vectors on the GPU could make ColBERT faster, and they leave these to future work.
Reading guide
Read the paper in this order, with these prerequisites in hand:
- Section 1, Introduction, and Figure 1: the cost and quality trade-off. Needs Bi-Encoder, Cross-Encoder and BM25.
- Section 2, Related Work: a list of earlier neural rankers. Skim it on the first read; the model names are context, not method.
- Section 3.1 to 3.3, Architecture, Encoders and Late Interaction: the core of the paper. Needs Late Interaction, Dot Product, Cosine Similarity, BERT, Subword Tokenization for WordPiece tokens, Masked Language Modeling for the
[mask]padding idea, and Cross-Entropy Loss for training. - Section 3.4, Offline Indexing: how the passage vectors are computed in batches and stored. Needs Transformer for the sequence cost.
- Section 3.5 and 3.6, Re-ranking and End-to-end Retrieval: how the scores are used in both modes. Needs Approximate Nearest Neighbor Search, K-Means Clustering, Product Quantization and Euclidean Distance.
- Section 4.1 and 4.2, Setup and Re-ranking Results: the datasets, the metrics and Table 1. Needs Precision and Recall for the recall numbers.
- Section 4.3 to 4.5, End-to-end Results, Ablations and Indexing Footprint: Tables 2 to 4 and Figures 5 and 6.
- Section 5, Conclusions: a summary you can check against the tables.
Read next. ColPali applies the same scoring to page images. DPR uses one vector per passage, which is the design ColBERT improves on. Retrieval-augmented generation uses retrieved passages to answer questions.
Check yourself
QuestionIn ColBERT, which vectors are computed ahead of time, and which are computed when a query arrives?Show answer
QuestionA query has 4 vectors and a passage has 5 vectors. How many dot products does the MaxSim step compute for that one passage?Show answer
QuestionWhy does ColBERT sum the maximum matches over the query vectors rather than over the passage vectors?Show answer
QuestionA team wants to store ColBERT-style vectors for 100 million passages, and their memory is limited. Which setting from Table 4 would you start from, and what does it cost? Assume the storage grows linearly with the number of passages.Show answer
Sources
- Khattab, O. and Zaharia, M. (2020). ColBERT: Efficient and Effective Passage Search via Contextualized Late Interaction over BERT. arXiv: https://arxiv.org/abs/2004.12832
- Khattab, O. and Zaharia, M. (2020). ColBERT, SIGIR 2020 proceedings. DOI: https://doi.org/10.1145/3397271.3401075