Skip to content
AI360Xpert
Paper Breakdowns
Paper breakdown

Matryoshka Representation Learning

The 2022 paper that introduced a way to train embedding models so their output vectors can be truncated to smaller sizes without retraining.

Paper: Matryoshka Representation Learning

Authors: Aditya Kusupati, Ganesh Venkatesh, Yair Carmon, Sham Kakade, Ali Farhadi · 2022

Read the paper
MRL trains embeddings where the most important information is packed into the first dimensions, acting like nested Matryoshka dolls.
MRL trains embeddings where the most important information is packed into the first dimensions, acting like nested Matryoshka dolls.

The Problem

Standard embedding models map inputs (text or images) to a fixed-size dense vector (e.g., 768 or 1024 dimensions). While large dimensions capture rich semantics, they consume massive amounts of storage and compute when indexed in a vector database. If you want a smaller, cheaper 256-dimensional embedding, you typically have to train an entirely new, smaller model from scratch.

The Idea

The authors introduced Matryoshka Representation Learning (MRL). Inspired by Russian nesting dolls (Matryoshka), they devised a training objective that forces the most important, coarse-grained semantic information to be concentrated in the first few dimensions of the vector, with subsequent dimensions adding finer details. This allows a user to take a large embedding and simply slice off the end of it (truncate it) to get a smaller embedding that still works perfectly, without retraining.

How It Works

MRL modifies the training loss function.

Instead of calculating the loss (e.g., contrastive loss for retrieval) only on the full d-dimensional output vector, MRL calculates the loss on multiple truncated subsets of the vector simultaneously (e.g., the first 8, 16, 32, 64, 128, 256, 512, and 1024 dimensions).

The model is forced to ensure that even if only the first 64 dimensions are evaluated, the representation is as accurate as possible. This explicitly structures the vector space so that information is hierarchically packed from left to right.

Why It Mattered

MRL brought massive flexibility to vector search deployments. A single foundation model could serve users with different cost/accuracy tradeoffs. A developer could store 256-dimensional embeddings for 14x cheaper storage and faster search, while only sacrificing 1-2% in accuracy compared to the full 1024 dimensions. OpenAI famously adopted this technique for their text-embedding-3 models.

What Came After

Matryoshka embeddings became a standard feature in modern embedding API providers (OpenAI, Nomic, Cohere) allowing the user to specify a dimensions parameter. It also enabled "adaptive retrieval" systems, where a first-pass search is done cheaply on the first 64 dimensions, and a re-ranking pass is done on the top candidates using the full dimensionality.