Embedding Dimensions, Truncation and Matryoshka
What you lose by shrinking a vector, measured — and when the storage saving is worth it.
Embedding dimensions are the length of the dense vector each chunk or query becomes in RAG (e.g., 384 vs 1536 vs 3072 floats). Dimension count sets the capacity for nuance and the linear bill for storage, memory, and similarity-search compute downstream.
How do embedding dimensions affect storage and retrieval cost?
Embedding dimensions affect cost mostly linearly because you store and compare one value per dimension.
The structural storage model is: bytes ≈ vector_count × dimensions × bytes_per_value. For the common case of float32 embeddings (4 bytes per value), the worked example below shows the scale:
| Dimensions | Float32 bytes | Approx. storage |
|---|---|---|
| 384 | 384 × 4 × 1,000,000 | ~1.5 GB |
| 1536 | 1536 × 4 × 1,000,000 | ~6.1 GB |
| 3072 | 3072 × 4 × 1,000,000 | ~12.3 GB |
Retrieval latency follows the same structural direction: every candidate-vs-query comparison does more arithmetic as dimensions rise. OpenAI’s embedding release also explicitly links larger embedding models to higher efficiency and cost trade-offs across dimensions (OpenAI, 2024).
Operational gotcha
Exact numbers depend on your storage type (float32 vs float16/int8), ANN index choice, and hardware. The linear scaling direction is the stable part; measure your end-to-end latency/throughput on your own setup.
What is Matryoshka Representation Learning?
Matryoshka Representation Learning (MRL) trains embeddings so that prefixes of the vector stay useful when you truncate the tail—like nesting dolls.
MRL is the mechanism that makes “shorter embedding with similar meaning” credible: training applies constraints across multiple compression levels so earlier dimensions carry the strongest ranking signal. Kusupati et al. introduced the technique (arXiv:2205.13147, 2022), and Sentence-Transformers popularized the training loss as MatryoshkaLoss (SBERT docs / example code).
OpenAI’s text-embedding-3 family uses a technique that enables shortening embeddings by passing a dimensions parameter, and OpenAI explicitly points back to the MRL paper (OpenAI, 2024).
How do you truncate embedding dimensions safely?
Safe truncation keeps RAG correct by (1) using the provider’s shortening API for MRL-trained models, and (2) re-normalizing if you slice manually.
Use this checklist:
- Prefer the provider’s shortening parameter. OpenAI embeddings let you pass dimensions to request a shorter output directly, rather than shortening after the fact (OpenAI, 2024).
- Normalize after manual slicing. If you change dimensions by slicing vectors yourself, re-apply L2 normalization before storing/searching (OpenAI embeddings guide; Voyage docs; Sentence Transformers usage notes).
- Use MRL models for “Matryoshka-style” truncation. Matryoshka-style truncation is trained to preserve meaning in the prefix; non-MRL slicing can degrade quality more sharply (Sentence Transformers truncation guide).
- Expect quality trade-offs and verify. OpenAI reports that shortening text-embedding-3-large to 256 still outperformed the unshortened ada-002 at 1536 on MTEB (OpenAI, 2024).
Don’t mix truncation styles
MRL-trained truncation is not the same as arbitrary slicing. If you truncate a model that was not trained for prefix usefulness, you can see sharp retrieval quality drops even when the vectors remain the right shape.
When should you shrink embedding dimensions?
You should shrink dimensions when storage/RAM/latency constraints are real and your MRL-based truncation preserves your retrieval metric on your own labeled queries.
In practice, the decision looks like this:
- Shrink for cost/latency budgets first. Smaller vectors reduce similarity-search arithmetic and typically reduce memory footprint (Particula discusses linear storage scaling across dimension sizes).
- Keep full width when fine distinctions matter. If your retrieval target depends on subtle entity/code differences, higher dimensionality can help—but you should validate the accuracy gain vs the cost/latency loss.
- Never “hope” without measurement. Dimension choice is a retrieval-quality experiment: run Recall@k / nDCG@k across a small grid of candidate widths on your corpus.
- For MRL + binary quantization, watch provider constraints. Microsoft’s Azure AI Search recommends truncationDimension of 1,024 or higher when using binary quantization with MRL, and warns that dimensionality below 1,000 degrades search quality (Microsoft Learn, as-of 2026 page).
What happens if embedding dimensions do not match?
Embedding dimension mismatch is a hard compatibility problem: the index is built for one vector shape, and queries must use the same shape.
Sentence-Transformers truncation guidance states that a vector index created for (for example) 768 dimensions cannot accept 128-dimension query vectors without being rebuilt or recreated (Simplified Guide, 2024).
Signature: you either get shape/config errors, or you silently run the wrong distance computation path and see “empty / nonsense” rankings after a dimension change. If dimensions drift over time (model version changes, orchestration defaults change), treat it as embedding drift and route to Embedding Drift.
How do you choose embedding dimensions for RAG?
You choose dimensions by finding the smallest width that meets a retrieval-quality target on a labeled query set, then measuring the cost/latency trade-off.
A practical procedure:
- Start with provider defaults. OpenAI’s default vector lengths are 1536 for text-embedding-3-small and 3072 for text-embedding-3-large (OpenAI embeddings guide).
- Test a truncated grid (if MRL-compatible). Evaluate widths like 256, 384, 512, 768, and your full width until gains plateau.
- Measure on your corpus. Track Recall@k / nDCG@k against the same held-out queries, alongside ingest and query throughput.
- Decouple “model choice” from “width choice.” Model identity is covered in Embedding Models; this page owns the width trade.
Example baseline sizes
Common starting points include efficient sentence-transformer baselines around 384 dimensions (e.g., all-MiniLM-L6-v2) and larger widths (Particula discusses typical production ranges).
How do you implement dimension truncation?
You implement truncation by requesting shorter embeddings at encode time and configuring your vector store schema to the resulting width.
At a high level:
- Embed-time configuration: set OpenAI’s dimensions parameter (or Voyage-style output_dimension) when creating embeddings.
- Index/schema configuration: set the vector field dimensions in your vector DB collection/index to match the stored width.
- Migration rule: if the stored dimension changes, rebuild/recreate (or re-index) the affected index/collection.
For a runnable, pinned end-to-end pipeline template, see building the pipeline.
What are embedding dimensions in RAG?
Embedding dimensions are the length of the dense vector each chunk or query becomes in RAG (for example, 384, 1536, or 3072). Dimensions set how much signal the embedding can store and they also drive linear storage and similarity-search cost downstream.
Does higher always mean better retrieval?
Higher dimensions do not always mean better retrieval. You should pick the smallest width that meets your Recall@k / nDCG target on your labeled queries, because larger vectors increase storage and per-comparison compute and can offer diminishing returns (and sometimes you pay latency/quality trade-offs for little gain).
Can I truncate after generating embeddings?
You can truncate after generating only if you follow the right rules for the embedding model you used. For MRL-trained models, it’s better to request a shorter output at encode time (e.g., OpenAI’s dimensions parameter). If you slice manually, you must ensure the query and index use the same dimensions and re-normalize so cosine/dot-product behaves correctly.
Do I renormalize after truncating?
Yes—if you manually change dimensions (e.g., by slicing/truncating and then using the vectors for search), you should re-apply L2 normalization before storing and querying. OpenAI’s embeddings guide explicitly notes normalization requirements when you change dimensions after generation.
What size is text-embedding-3-small / large?
OpenAI’s text-embedding-3-small defaults to 1536 dimensions, and text-embedding-3-large defaults to 3072 dimensions. Both models can be shortened via the dimensions parameter.