Shrinking a search index to a quarter: how Hugging Face's token pooling training works
Hugging Face explained a training method that cuts document vectors by 74.8% in multi-vector search while keeping 97.8% of quality. We explain the method, the results and how to try it.
Can you cut a search index to a quarter of its size and keep almost all of its quality? In a guide published on 11 November, Tom Aarsen of Hugging Face shows how, step by step. The method is called token pooling-aware training. With 74.8% fewer stored document vectors, his model keeps 97.8% of its unpooled retrieval score, while the same model trained normally keeps 94.6%. All the code is open in Sentence Transformers and takes a few lines to try.
Multi-vector search is powerful but heavy
Most semantic search turns each document into one vector. Multi-vector models such as ColBERT keep one vector per token instead; with MaxSim scoring, each query token finds its best match in the document and the scores are summed. A query for a laptop with long battery life can match the laptop in one passage and battery endurance in another. The cost is storage: even at 4 bits per coordinate, 200 vectors of 128 dimensions take 12.8 KB per document, 12.8 GB for a million documents. Pooling to 50 vectors brings that to 3.2 GB.
Token pooling
Many token vectors in a document are similar, so they can be represented together. HierarchicalTokenPooling uses Ward hierarchical clustering: it repeatedly merges the two groups that least increase within-group spread, then represents each group by its mean. Think of a classroom where students asking the same question pick one spokesperson. Budgets can be set with pool_factor (keep about a quarter at 4), max_tokens (a hard cap) or a distance_threshold that can be calibrated to a target average. Queries are never pooled, and the first token is protected.
Teaching the model to be compressed
An ordinary model was never trained to work with merged vectors, so useful distinctions can vanish. Pooling-aware training computes two losses per batch, one with full document vectors and one after pooling to about a quarter, and averages them equally. It is the Matryoshka idea applied to the number of vectors rather than their width. Because clustering makes discrete decisions, a straight-through estimator passes gradients from pooled vectors back to their member tokens. In Sentence Transformers, MultiVectorTokenPoolingLoss wraps an existing retrieval loss; pooled variants reuse the token vectors, so no extra encoder pass is needed. Optional kernels make Ward clustering 30 to 150 times faster than SciPy, according to the guide.
Results
Two ModernBERT-base models were trained on the same 120,000 MS MARCO triplets with identical settings; only the loss differed. On NanoBEIR@13 mean nDCG@10, the trained pool_factor=4 setting rises from 49.03 to 51.23. The gains carry over to settings never trained on: at 4 vectors per document, 37.22 becomes 43.00. With adaptive pooling at an average of 29.58 vectors, the pooling-aware model keeps 97.3% of its unpooled score with 84.7% fewer vectors. Even unpooled retrieval improves, from 51.84 to 52.39.
How to try it
The trained checkpoint is on Hugging Face:
from sentence_transformers import MultiVectorEncoder
from sentence_transformers.multi_vector_encoder.modules import HierarchicalTokenPooling
model = MultiVectorEncoder("tomaarsen/mve-ModernBERT-base-token-pooling")
pooling = HierarchicalTokenPooling(pool_factor=4)
query_embeddings = model.encode_query(["Which planet is known as the Red Planet?"])
document_embeddings = model.encode_document(documents, token_pooling=pooling)
print(model.similarity(query_embeddings, document_embeddings))In the guide's example, three documents shrink from 58 vectors to 16 and Mars still ranks first for "Red Planet". The full training script is in the Sentence Transformers repo and can run on Hugging Face Jobs. Aarsen's recommended order for shrinking an index: quantization first, then token pooling, then Matryoshka dimension reduction, all combinable.
Sources: Hugging Face: Token Pooling-Aware Training, Sentence Transformers GitHub