Matryoshka embedding models front-load meaning into the first dimensions, so you can truncate vectors 3-12x and keep most retrieval quality. How MRL works, which models support it, how to truncate correctly, and how it stacks with quantization.
A Matryoshka embedding model is trained so that every prefix of its output vector is itself a usable embedding. Keep the first 256 of 768 dimensions and you get a smaller vector that still ranks documents well, because training pushed the most useful information to the front. The technique is Matryoshka Representation Learning (MRL), and it is now built into most major embedding APIs.
Vector memory scales linearly with dimensions, so this is one of the cheapest cost levers in vector search. A billion 768-d float32 vectors take 3.07 TB of raw storage. Truncating to 256 dimensions cuts that to 1.02 TB, and MRL stacks with int8 and binary quantization on top. The catch: truncation only works on models trained for it, and it is easy to get subtly wrong. If you need the basics of dense vectors first, start with our sparse vs. dense vectors explainer.
What are Matryoshka embeddings?
Matryoshka Representation Learning is a training method introduced by Kusupati et al. (NeurIPS 2022). It computes the training loss on the full embedding and on a set of nested prefixes (for example the first 64, 128, 256 and 512 dimensions), then sums those losses. The model learns to put coarse meaning in the first dimensions and finer detail in later ones, like nested Russian dolls.
The paper reports up to 14x smaller embeddings at the same ImageNet-1K classification accuracy, and up to 14x real-world speedups for large-scale retrieval. Training cost barely changes. Hugging Face's introduction to Matryoshka models notes that MRL "does not incur a notable overhead in training time", and inference costs exactly the same, since you compute the full vector and drop the tail.
The difference from a normal model is large. In the paper's ResNet-50 experiment, 64 dimensions taken from a conventionally trained 2048-d model reach 49.9% 1-NN accuracy on ImageNet-1K. The first 64 dimensions of the MRL model reach 70.2%, almost the full-size model's 71.0%. On text, Hugging Face's own MPNet experiment kept 98.37% of STS-B performance at 64 of 768 dimensions (8.3% of the size), versus 96.46% for the same model trained without MRL.
Training one yourself takes a single wrapper loss in Sentence Transformers:
from sentence_transformers import SentenceTransformer
from sentence_transformers.losses import CoSENTLoss, MatryoshkaLoss
model = SentenceTransformer("microsoft/mpnet-base")
base_loss = CoSENTLoss(model=model)
loss = MatryoshkaLoss(
model=model,
loss=base_loss,
matryoshka_dims=[768, 512, 256, 128, 64],
matryoshka_weight=[1, 1, 1, 1, 1],
)
The same library ships Matryoshka2dLoss, which also makes the number of Transformer layers truncatable, for faster inference as well as smaller vectors.
Which embedding models support Matryoshka truncation?
Most current commercial and open embedding models are trained with MRL. They expose it either as an API parameter or as documented truncation sizes. The table lists full size and supported sizes as stated in each vendor's docs or model card.
| Model | Full dims | Truncation options | How to request |
|---|---|---|---|
| OpenAI text-embedding-3-large | 3072 | Any size | dimensions |
| OpenAI text-embedding-3-small | 1536 | Any size | dimensions |
| Cohere embed-v4.0 | 1536 | 256, 512, 1024, 1536 | output_dimension |
| Google gemini-embedding-001 | 3072 | 128-3072 (768, 1536, 3072 recommended) | output_dimensionality |
| EmbeddingGemma | 768 | 512, 256, 128 | Truncate, then re-normalize |
| nomic-embed-text-v1.5 | 768 | 512, 256, 128, 64 benchmarked | Layer norm, truncate, normalize |
| jina-embeddings-v3 | 1024 | 32 to 1024 | truncate_dim |
| Qwen3-Embedding-8B | 4096 | 32 to 4096 | Truncate |
| Snowflake arctic-embed-l-v2.0 | 1024 | 256 | Truncate |
OpenAI's launch post gives the headline result: text-embedding-3-large shortened to 256 dimensions still outperforms the unshortened ada-002 at 1,536 on MTEB. Model cards that publish per-size scores show a consistent shape. Quality stays nearly flat down to a third or a quarter of the full size, then drops faster. nomic-embed-text-v1.5 scores 62.28 on MTEB at 768 dimensions, 61.04 at 256 and 56.10 at 64. EmbeddingGemma goes from 69.67 on English MTEB at 768 to 68.37 at 256 and 66.66 at 128.
Voyage's current models also accept output_dimension (256 to 2048), but their docs don't say Matryoshka, so treat them as their own method. Whatever the model, the leaderboard isn't your corpus. We measured Cohere Embed 4 on a real dataset and found that cutting 1536 dimensions to 512 had almost no impact on retrieval quality. That kind of test on your own queries is the one that counts.
How to truncate Matryoshka embeddings correctly
Truncation is a slice, but four mistakes keep showing up in production:
- Truncating a model that wasn't trained with MRL. The vector shrinks and the meaning goes with it: in the paper's experiment above, 64 dimensions of a regular model scored about 20 points below the MRL model. If your model has no Matryoshka training, a PCA or SVD projection fitted on your data is the fallback. It beat naive truncation by a wide margin in the paper (67.0% vs 49.9% at 64 dims) but still trailed MRL.
- Forgetting to re-normalize. A truncated unit vector is no longer unit length. Cosine similarity doesn't care, but dot-product and inner-product indexes do. OpenAI and Google both tell you to normalize after truncating manually. The jina-embeddings-v3 card documents a bug where truncation ran after normalization, which shows how easily this slips through.
- Skipping model-specific steps. nomic-embed-text-v1.5 needs a layer norm before truncation. Read the model card instead of assuming a plain slice.
- Mixing sizes. Queries and documents must use the same prefix length, and an index built at 768 dimensions can't take 256-d vectors. Changing the size means re-embedding or at least re-indexing the whole corpus, so pick it before the big backfill.
With Sentence Transformers, the truncate_dim argument does the slicing:
import numpy as np
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("tomaarsen/mpnet-base-nli-matryoshka", truncate_dim=256)
emb = model.encode(["Pod keeps getting OOMKilled after the 3.0 upgrade"])
emb = emb / np.linalg.norm(emb, axis=1, keepdims=True) # back to unit length
print(emb.shape) # (1, 256)
With a hosted API, request the size directly: client.embeddings.create(model="text-embedding-3-large", input=texts, dimensions=1024). OpenAI's docs recommend the dimensions parameter over slicing the vector yourself.
Getting the vectors smaller doesn't make embedding any faster. As Hugging Face points out, the model still computes the full vector. The savings are all downstream: memory, disk, network transfer and distance computations in the index.
Matryoshka plus quantization: two encodings, one index
Truncation removes dimensions. Quantization removes bits per dimension. The two are independent, and Hugging Face's embedding quantization guide calls them "fully perpendicular". The interactive figure above shows the arithmetic: 512-d binary vectors are 64 bytes each, 48x smaller than 768-d float32.
Quality doesn't stack as kindly as memory does. Mixedbread measured mxbai-embed-large-v1 (1024-d) on 13 BEIR datasets in their binary MRL post:
| Encoding | Bytes per vector | NDCG@10 | Retained |
|---|---|---|---|
| 1024-d float32 | 4,096 | 54.39 | 100% |
| 1024-d binary | 128 | 52.46 | 96.5% |
| 512-d float32 | 2,048 | 51.79 | 95.2% |
| 512-d binary | 64 | 49.37 | 90.8% |
| 256-d binary | 32 | 43.25 | 79.5% |
Over 90% of the quality at 1/64th of the size is a good deal. Below that, quality drops off a cliff. The fix is to stop picking one encoding. Search a small one to get a shortlist, then rescore that shortlist with a precise one. The MRL paper calls this adaptive retrieval: it shortlisted with 16 dimensions and reranked with 2048, matching full-size accuracy while being up to 14x faster in practice.
Published results back the pattern up:
- Binary + int8 rescoring: Hugging Face's guide reports that rescoring binary search results keeps about 96% of float32 retrieval quality, and int8 search with rescoring and a 4-5x oversampling factor reaches about 99%. Their 41M-document Wikipedia demo keeps a 5.2 GB binary index in memory and a 47.5 GB int8 index on disk, against roughly 200 GB for float32.
- Short prefix + full-vector rerank: Supabase ran adaptive retrieval on pgvector with 1M DBpedia vectors. An HNSW pass on 512-d prefixes of text-embedding-3-large, reranked with the full 3072 dimensions, reached 99% accuracy against exact search at up to 580 QPS.
Several engines can run both stages in one query. Qdrant stores the short and full vectors as named vectors and chains them with prefetch. Vespa can truncate and binarize inside its embedder. pgvector 0.7+ indexes a prefix with subvector():
CREATE INDEX ON items USING hnsw ((subvector(embedding, 1, 256)::vector(256)) vector_cosine_ops);
SELECT * FROM (
SELECT * FROM items
ORDER BY subvector(embedding, 1, 256)::vector(256) <=> subvector($1::vector, 1, 256)::vector(256)
LIMIT 200
) AS candidates
ORDER BY embedding <=> $1::vector
LIMIT 10;
subvector() doesn't re-normalize, which is fine here because cosine distance ignores length. Switch to inner product and you need normalized prefixes. Elasticsearch and OpenSearch don't truncate for you: you send the shorter vector, and their quantized indexes rescore with full-precision vectors (rescore_vector in Elasticsearch, disk-based vector search in OpenSearch). How these choices play out at different scales is covered in Scaling Vector Search from Millions to Billions. For the choice of index, see HNSW vs. IVFFlat.
Key takeaways
- Matryoshka embeddings are trained so every prefix is a usable vector. Truncating them is a supported operation, not a hack.
- Typical MRL models keep most of their quality down to a third or a quarter of full size. Below that, measure before you commit.
- Never truncate a model that wasn't trained with MRL. Re-normalize after slicing, follow model-specific steps, and keep query and document sizes identical.
- Truncation and quantization multiply: 512-d binary is 48x smaller than 768-d float32.
- For the best quality per byte, shortlist with a small encoding and rescore with a precise one.
- Evaluate on your own queries. Leaderboard deltas rarely match what you see on your corpus.
Frequently asked questions
What is a Matryoshka embedding?
A Matryoshka embedding is a vector from a model trained with Matryoshka Representation Learning, where the loss is applied to several nested prefixes of the vector at once. As a result, the first N dimensions form a valid, lower-resolution embedding on their own, and you can truncate the vector to save memory and compute.
Can I truncate any embedding model's vectors?
No. Only models trained with MRL or a similar objective keep their quality when truncated. Truncating a conventionally trained model drops quality sharply. If your model isn't Matryoshka-trained, use a PCA projection fitted on your data, or switch models.
Do I need to re-normalize after truncating?
Yes, if your index uses dot product or inner product, or your model card says so. A truncated unit vector is shorter than 1. Cosine similarity is unaffected, but normalizing anyway is cheap and avoids surprises when someone changes the distance metric.
How many dimensions should I keep?
Start at a third or a quarter of the full size and measure recall and relevance on your own queries. Published results show small losses down to that range for most MRL models and much larger ones below 128 dimensions.
Does truncating embeddings make inference faster?
No. The model still computes the full vector; you drop the tail afterward. The savings come from storage, memory, network transfer and faster distance computations at query time.