Glossary

Matryoshka embeddings

Matryoshka embeddings are vectors trained so that their first dimensions carry the most information, which lets you cut them to a shorter length and still use them for search.

Matryoshka embeddings are embedding vectors trained so that any prefix of the vector is itself a usable embedding. The first 64 dimensions give a coarse representation, the first 256 a sharper one, and the full vector the sharpest, much like the nested Russian dolls the technique is named after. Because the important information is packed into the leading dimensions, you can store or search with a shortened vector and accept a small, predictable drop in quality in exchange for less memory and faster comparisons.

Where the idea comes from

The technique was introduced as Matryoshka Representation Learning in a 2022 research paper by Kusupati and colleagues. Before it, an embedding model produced a vector of fixed length, say 768 or 1,536 numbers, and every one of those numbers mattered roughly equally. If you wanted a smaller vector you had to train a separate, smaller model or apply dimensionality reduction such as PCA after the fact, which usually cost noticeable accuracy.

Matryoshka training changes the objective. Instead of optimising only the full vector, the loss is computed at several nested lengths at once, for example 64, 128, 256, 512 and the full size, and the model is penalised whenever any of those prefixes performs poorly. The model learns to put the broad, high-value signal first and finer distinctions later. Nothing about the output format changes: it is still one dense vector per input, and you decide how much of it to keep.

Since then the approach has moved from research into everyday use. Several commercial and open models support it, and OpenAI’s text-embedding-3 models expose a dimensions parameter that returns shortened vectors on request. When those models launched, OpenAI reported that text-embedding-3-large cut to 256 dimensions still outperformed its earlier ada-002 model at 1,536. The best embedding models roundup covers which current models support truncation, and OpenAI embeddings pricing covers the cost side.

What truncation saves

The size of a vector index grows linearly with embedding dimensions. A million documents embedded at 3,072 dimensions in 32-bit floats take about 12 GB for the raw vectors alone, before the overhead of an index such as HNSW. The same million documents at 256 dimensions take about 1 GB. That difference decides whether an index fits in memory on one machine, how much a managed vector database charges, and how quickly new data can be indexed.

Comparison cost falls in step. Cosine similarity, the dot product and Euclidean distance all scale with the number of dimensions, so a 256-dimension comparison is roughly twelve times cheaper than a 3,072-dimension one. For exhaustive search or for scoring a shortlist, that translates directly into latency.

Dimensions kept

Raw size per million vectors (float32)

Typical use

64 to 128

0.25 to 0.5 GB

First-pass candidate generation, clustering, on-device search

256 to 512

1 to 2 GB

General semantic search where memory matters

1,024 and above

4 GB and up

Highest accuracy, reranking a shortlist, evaluation baselines

The quality cost is the part to measure. Truncation removes the finer distinctions, so near-duplicate documents and queries that hinge on small differences suffer first. Broad topical matching usually holds up well at a quarter of the original size. The only reliable way to choose a length is to test it on your own queries with a retrieval evaluation that tracks recall at k, since the trade-off varies with the domain and the model.

Using Matryoshka embeddings in practice

Truncate, then normalise. Most embedding models return unit-length vectors, and many search setups assume that. Cutting a vector short changes its length, so it should be re-normalised before you store it or compare it with cosine similarity. Models that offer a dimensions option through their API usually return already normalised vectors.

Pick one length per index. Every vector in an index has to share a length. If you change your mind later, you can truncate the stored full vectors again rather than re-embedding the corpus, provided you kept the full vectors somewhere. That is a strong reason to store the original output even if you only index a prefix, because re-indexing from stored vectors is far cheaper than calling the model again.

Use short vectors for the first pass. A common pattern, sometimes called funnel or adaptive retrieval, searches the whole index with short vectors to get a generous shortlist, then rescores that shortlist with the full vectors. The first pass is cheap and keeps top-k retrieval wide; the second restores most of the precision. A reranking model can follow as a third stage for the final ordering.

Combine with quantization. Truncation reduces the number of dimensions; vector quantization reduces the bytes per dimension. They stack. A 256-dimension vector stored with binary quantization takes 32 bytes, against 12,288 bytes for a 3,072-dimension float vector, and the shortlist-then-rescore pattern recovers much of the lost accuracy. Product quantization offers a middle ground with less loss than binary codes.

A worked example

A team runs semantic search over 40 million support messages. With full 1,536-dimension vectors, the index needs about 240 GB of memory for vectors alone, which means a cluster of large machines.

They switch to an embedding model trained with Matryoshka loss and index the first 256 dimensions, about 40 GB. Their offline evaluation on 2,000 labelled queries shows recall at 10 falling from 0.91 to 0.87. To win most of that back, they keep the full vectors in cheaper disk storage and rescore the top 200 candidates from the short index using the full vectors. Recall at 10 returns to 0.90, and median query latency drops because the expensive comparisons now run on 200 vectors rather than millions.

The numbers here are illustrative; what transfers is the method. Measure the short index alone, measure it with rescoring, and decide whether the remaining gap matters for your users.

How it compares with other ways to shrink vectors

PCA and other post-hoc dimensionality reduction methods work on any embedding, including ones not trained for truncation, but they need a fitting step on your data and tend to lose more quality at the same size. Naive truncation of a model that was not trained with a Matryoshka objective is worse still, because the information is spread across all dimensions and cutting any of them removes signal at random.

Quantization keeps all dimensions and stores each with fewer bits. It is complementary rather than an alternative. Index structures such as an IVF index or approximate nearest neighbor graphs reduce how many vectors you compare, not how big each one is, so they also combine well with shorter vectors. Libraries such as FAISS support all of these together.

Matryoshka embeddings are sometimes confused with multi-vector retrieval because both involve more than one representation. Multi-vector approaches such as late interaction store several vectors per document; a Matryoshka model stores one vector that can be read at several resolutions. They solve different problems and can be used together.

Changing the truncation length or the model is a form of embedding drift from the index’s point of view: vectors of different lengths, or from different models, are not comparable. Queries must always be embedded and truncated exactly as the stored documents were.

When to use them

Matryoshka embeddings are most useful when the index is large enough that memory or cost is a constraint, when you want one model to serve several tiers of accuracy, or when you plan a two-stage search. They help less for small corpora, where full vectors are already cheap, and for tasks that depend on fine distinctions, such as deduplicating near-identical documents, where the shortened vector loses exactly the detail you need.

They also make it easier to separate tenants or products with different needs. A per-tenant index for a small customer can use short vectors while a large customer’s index keeps full ones, all from the same model.

Short prefixes also suit work that happens away from the main index. A mobile app can keep a 64-dimension copy of a user’s own notes on the device for instant offline lookups, then call the server for full-precision search when connected. Clustering jobs that group millions of documents by topic run much faster on short vectors, and topic-level grouping rarely needs fine detail. A semantic cache that checks whether a new query resembles a recent one can also use short vectors, since it only needs to spot close matches cheaply before deciding whether to reuse an earlier answer.

Where Exabase fits

Exabase handles embedding and indexing for you, so dimension choices are not something you configure. Content stored through Resources is indexed automatically at write time, with no embedding pipeline, chunking logic or vector store to run, and Deep Search returns matched chunks with relevance scores, page numbers and timestamps. Text queries are hybrid by default, combining semantic search with typo-tolerant keyword matching, and a precision parameter between 0 and 1 trades recall for relevance per query.

For teams that would otherwise be tuning vector lengths, quantization and shortlist sizes, this moves those decisions into the platform. Each customer’s data lives in its own Base, files arrive through Extract or direct upload, and the searching resources guide shows the request shape. The RAG accuracy solution and the RAG pipelines use case describe how passage-level retrieval fits into an application, and comparisons such as Exabase vs Pinecone explain where a managed retrieval layer differs from running your own vector index. If you need direct control over vector dimensions for research or a custom index, a dedicated vector database remains the better tool.

Frequently asked questions

What are Matryoshka embeddings in simple terms?

Matryoshka embeddings are vectors whose first dimensions carry the most important information. You can keep only the first part of the vector, for example 256 of 1,536 numbers, and still get useful search results with a smaller index.

Can I truncate any embedding?

You can, but quality drops sharply unless the model was trained with a Matryoshka objective. Models trained that way are built to work at shorter lengths; ordinary models spread information across every dimension.

Do I need to normalise after truncating?

Yes, if you use cosine similarity or assume unit-length vectors. Truncation changes the vector’s length, so re-normalise before storing or comparing. API options that return shortened vectors usually normalise them for you.

How many dimensions should I keep?

Test it on your own queries. Many teams find that a quarter of the full length keeps most of the retrieval quality, but the right point depends on the model, the domain and how much accuracy your users notice.

Are Matryoshka embeddings the same as quantization?

No. Matryoshka truncation removes dimensions, while quantization stores each dimension with fewer bits. The two stack, and combining them is a common way to shrink large indexes.

Can I mix vectors of different lengths in one index?

No. Every vector in an index must have the same length, and queries must be truncated the same way as documents. Keep full vectors stored separately if you might change the length later.

Does Exabase use Matryoshka embeddings?

Exabase does not expose embedding dimensions. Indexing happens automatically when content is stored, and Deep Search returns passage-level results, so there is no vector length to tune.

Related pages: Embedding dimensions, Dimensionality reduction, Binary quantization, Vector quantization, Embedding model, Multi-vector retrieval, Best embedding models, Deep Search, The end of the embedding pipeline

Cut your token spend and give your agent precise context.

Get started in minutes.

Cut your token spend and give your agent precise context.

Get started in minutes.