Honey, I shrunk the embeddings: Matryoshka vs. PCA
TL;DR Highlight
Shrinking embeddings with PCA matched or beat Matryoshka truncation on most dimensions
Who Should Read
A backend developer building RAG who wants to cut vector DB cost and latency by reducing embedding dimensions
Core Mechanics
- MRL shrinks at training time, PCA after
- MRL (Matryoshka Representation Learning) trains the model to pack key information into the first dimensions, so you truncate to d and re-normalize.
- PCA projects onto the top d directions of variance from a sample of embeddings and works with any model.
- PCA adds operational work because you must store and version the projection.
- On 3-small at 32 dims, PCA kept 65% vs 46%
- These are NDCG@10 retention rates against full 1,536 dims, averaged over eight BEIR datasets.
- At 64 dims PCA kept 82% vs truncation's 71%.
- Only at 512 dims did truncation edge ahead, 98% vs 97%.
- The gap was small on qwen3-embedding-8b
- At 32 dims against full 4,096, PCA kept 71% and truncation 68%.
- At 128 dims both kept 91%.
- The author notes qwen3's stronger MRL training narrows PCA's lead.
- PCA isn't just riding on MRL training
- On ada-002, which wasn't trained with MRL, PCA still kept 59% at 32 dims.
Community Reactions
- Random rotation before quantization was suggested
- One commenter said a random rotation spreads information across dimensions and allows more aggressive quantization.
- They caveated that it may not apply if text embeddings lack that kind of structure.
- Another experiment found less uniform results
- A commenter who ran similar tests with many embedding models said the curves were far less uniform.
- They did not use API-based models.
- Original MRL paper's SVD baseline degraded at low dims
- A commenter noted Table 1 showed SVD comparable at d>=256 but much worse at d of 8, 32, 64.
- They asked whether the author investigated why the results differ.
- PCA scalability was raised as a concern
- A commenter said O(n^3) complexity makes PCA infeasible for massive datasets.
- They said MRL trades a little performance for guaranteed training and validation coverage.
How to Apply
- Compare truncation vs PCA on your own embeddings
- Today, sample 1,000 document embeddings from your corpus and fit PCA.
- Compare it with prefix truncation at the same dimensions using your query set.
- Compute NDCG@10 retention against full dimensions at 128, 64, and 32.
- Try PCA first if your model lacks MRL
- PCA on ada-002, which has no MRL training, kept 59% at 32 dims.
- Apply a PCA projection to cut storage without swapping models.
- Version the PCA matrix with the index
- Save the projection to a file and record its version in index metadata.
- Enforce the same version for both ingestion and queries.
- Re-validate in your real setup
- The author used exact search, unlike production setups with approximate indexes, BM25, and rerankers.
- Measure quality loss in a pipeline identical to production before adopting.
Try It
# Prompt to paste into Claude or ChatGPT (code generation)
Write a Python script that compares embedding dimension reduction methods.
- Input: numpy arrays doc_emb (N x D), query_emb (Q x D), and ground truth {{relevance format}}
- Method 1: keep the first d dims, then L2 re-normalize
- Method 2: fit sklearn PCA on {{1000}} sampled doc_emb rows, project docs and queries, then L2 re-normalize
- d in [512, 256, 128, 64, 32]
- Search with cosine similarity and compute NDCG@10
- Print a table of NDCG@10 at each d divided by NDCG@10 at full dimensions
Next step: add int8 quantization (documents only) and compare size vs quality.Terminology
Related Papers
You could have invented transformers from memory
Viewing linear, MLP and attention layers as memory stores: capacity goes ~64 to ~2,700 to over a million
Pointing AI at archives found a forgotten meteorite, lost rhinos, and more
Embedding search plus a cheap filter model surfaced unrecorded events in 400 years of archives
EmbeddingGemma 2: An open, lightweight multimodal embedding model
One open 740M model embeds text, images, audio and video into a single shared vector space
RAG-NAROK: Retrieval-Aware Knowledge Corpus Poisoning in RAG with Source-specific Refutation
Refutation documents targeting retrieved sources took top rank and evaded anomaly detectors up to 88.37%.
Text, Pixels, or Both? Evaluating Input Representations for Multimodal Document QA
Page images beat OCR text on accuracy but cost more; a question-only router cut latency 30%.
Microsoft exec called AI scraping 'the largest theft of labor in human history'
NYT lawsuit unredacted filings reveal Microsoft and OpenAI internal views on scraping