about
Matryoshka Representation Learning (arxiv.org)
83 points by fzliu on Feb 1, 2024 | hide | past | pdf | 11 comments on HN

In plain words: Like nested dolls, this trains one embedding so its first few numbers already work and adding more numbers adds finer detail, so each task uses only the size it needs. It matched separately trained small embeddings while allowing up to 14x smaller ones.

Abstract

Learned representations are a central component in modern ML systems, serving a multitude of downstream tasks. When training such representations, it is often the case that computational and statistical constraints for each downstream task are unknown. In this context rigid, fixed capacity representations can be either over or under-accommodating to the task at hand. This leads us to ask: can we design a flexible representation that can adapt to multiple downstream tasks with varying computational resources? Our main contribution is Matryoshka Representation Learning (MRL) which encodes information at different granularities and allows a single embedding to adapt to the computational constraints of downstream tasks. MRL minimally modifies existing representation learning pipelines and imposes no additional cost during inference and deployment. MRL learns coarse-to-fine representations that are at least as accurate and rich as independently trained low-dimensional representations. The flexibility within the learned Matryoshka Representations offer: (a) up to 14x smaller embedding size for ImageNet-1K classification at the same level of accuracy; (b) up to 14x real-world speed-ups for large-scale retrieval on ImageNet-1K and 4K; and (c) up to 2% accuracy improvements for long-tail few-shot classification, all while being as robust as the original representations. Finally, we show that MRL extends seamlessly to web-scale datasets (ImageNet, JFT) across various modalities -- vision (ViT, ResNet), vision + language (ALIGN) and language (BERT). MRL code and pretrained models are open-sourced at https://github.com/RAIVNLab/MRL.

Aditya Kusupati, Gantavya Bhatt, Aniket Rege, Matthew Wallingford, Aditya Sinha, Vivek Ramanujan, William Howard-Snyder, Kaifeng Chen, Sham Kakade, Prateek Jain, Ali Farhadi
arXiv:2205.13147 · cs.LG, cs.CV · submitted May 26, 2022 · updated Feb 8, 2024
abstract · pdf · html · Edited related work to include intrinsic dimensionality works

add comment on HN
Also discussed: Jul 2025 (6 points, 0 comments)

For those unaware, OpenAI recently announced [0] an API change where they said their newer models are using Matryoshka representation learning for shortening embeddings. Basically you can use a shorter prefix of the full representation to do query/lookup for cheaper without losing much quality. Quote:

“Native support for shortening embeddings:

Using larger embeddings, for example storing them in a vector store for retrieval, generally costs more and consumes more compute, memory and storage than using smaller embeddings. Both of our new embedding models were trained with a technique [Matryoshka Representation Learning] that allows developers to trade-off performance and cost of using embeddings. Specifically, developers can shorten embeddings (i.e. remove some numbers from the end of the sequence) without the embedding losing its concept-representing properties by passing in the dimensions API parameter. For example, on the MTEB benchmark, a text-embedding-3-large embedding can be shortened to a size of 256 while still outperforming an unshortened text-embedding-ada-002 embedding with a size of 1536.”

[0] https://openai.com/blog/new-embedding-models-and-api-updates

Context: OpenAI was "caught" using Matryoshka embeddings in their new release. They apologized and added references to the paper in their release notes.
Analysis by dhruv___anand in https://twitter.com/dhruv___anand/status/1752641057278550199 suggests that there are three different "resolutions" in the embeddings, for the first 512, 1024 and full 1536 dimensions in text-embedding-3-small.

You can put a subset of the dimensions in your vector database, thus saving a lot of cost by reducing memory/compute when retrieving nearest neighbors.

Then you can optionally even re-rank the most promising top-k candidates by the full embeddings. At least one database supports this natively: https://twitter.com/jobergum/status/1750888083900240182

Co-lead of MRL and related line of work here. Happy to answer any questions!
How do they sort the dimensions so the most salient are at the front and thus retained ?
They declare by fiat that retaining only the first few dimensions should lead to low classification error and construct the training loss accordingly. (Equation 1 on page 4 of the PDF.)
Any relationship to residual vector quantized embeddings?
Both are methods to reduce the overall size of your embeddings, but from what I understand, quantization is generally better than dimensionality reduction, especially if training is quantization-aware.
#(please summarize and share possible use cases)
Number go up.

More seriously, it looks like a potential reduction in the cost to train a neural network.

You can think of every meaningful step forward in deep learning as a reduction in the cost of training, or an improvement in the ability of the signal to propagate.

https://arxiv.org/abs/2001.08361

No neither of these explanations is right.

The paper talks about a specific type of model called an embedding model that produces vectors for datapoints that are useful for downstream tasks.

Normally you have to choose a single dimensionality for the vectors and store them all in a database that’s proportional to the size of those vectors.

The method described is for a model that has multiple “options” for the lengths of its embeddings. You can use smaller vectors to save space but they don’t work quite as well. Paper analyzes this more in-depth.