GEMINI LABJP
NANOLITE — Nano Banana 2 Lite is here: Google's fastest and most cost-efficient Gemini Image model, made for running lightweight image generation cheaplyOMNIFLASH — Gemini Omni Flash is in public preview, a natively multimodal model that lets enterprises and developers build custom, dynamic video workflowsAGENTS — Managed Agents expand with background: true for async server-side runs and polling, remote MCP server integration, and refreshing credentials across interactionsMEMORY — The Memory Bank IngestEvents API is generally available, decoupling event ingestion from memory generation so you can stream content continuouslyTHROUGHPUT — Provisioned Throughput now lets you submit up to seven pending orders for the same model and regionDEPRECATE — Image generation models shut down on August 17, and the Grok 4.1 family on the Gemini Enterprise Agent Platform on August 20NANOLITE — Nano Banana 2 Lite is here: Google's fastest and most cost-efficient Gemini Image model, made for running lightweight image generation cheaplyOMNIFLASH — Gemini Omni Flash is in public preview, a natively multimodal model that lets enterprises and developers build custom, dynamic video workflowsAGENTS — Managed Agents expand with background: true for async server-side runs and polling, remote MCP server integration, and refreshing credentials across interactionsMEMORY — The Memory Bank IngestEvents API is generally available, decoupling event ingestion from memory generation so you can stream content continuouslyTHROUGHPUT — Provisioned Throughput now lets you submit up to seven pending orders for the same model and regionDEPRECATE — Image generation models shut down on August 17, and the Grok 4.1 family on the Gemini Enterprise Agent Platform on August 20
Articles/Advanced
Advanced/2026-06-01Advanced

Trimming Gemini Embeddings from 3072 to 768 Dimensions: A Matryoshka Approach to Cutting Vector DB Cost and Latency

gemini-embedding-001 returns 3072-dimensional vectors, but thanks to Matryoshka representation you can keep only the leading dimensions with almost no quality loss. This is a design for trimming to 768 to cut vector DB storage and latency, including the re-normalization pitfall and coarse-to-fine search code.

Gemini API192Embedding3Vector Search2RAG14Cost Optimization13Production32

Premium Article

Trimming Gemini Embeddings from 3072 to 768 Dimensions: A Matryoshka Approach to Cutting Vector DB Cost and Latency

A vector search feature shows its true nature not the day you build it, but half a year later. Across the apps I have run since 2014, I use embeddings for semantic clustering of store reviews and for categorizing wallpaper images. For the first few thousand records, nothing goes wrong. Then one day, once the count has climbed past 100,000 and toward 300,000, you notice that the vector database bill and the search response-time graph have both crept quietly but unmistakably upward.

When that happened to me, the first thing I reached for was not a faster database, nor a different index type. It was making each individual vector smaller. gemini-embedding-001 returns 3072-dimensional vectors by default. Trim that to 768 and storage drops to roughly a quarter, while distance computation gets lighter almost in proportion to the dimension count. And this is not blind truncation. Thanks to a mechanism called Matryoshka representation, keeping only the leading dimensions preserves most of the meaning.

In this article I want to make that "trim the dimensions" decision something you do with evidence rather than a hunch. We will build it up with working code, all the way through the easily missed step of re-normalization and a two-stage search that filters coarsely with 768 and refines with 3072.

Where 3072 Dimensions Quietly Add Up

The cost of embeddings is often imagined as something that happens only at the moment you call the API. In reality, the costs after generation last far longer.

The clearest one is storage. A single 3072-dimensional vector stored as float32 takes 12,288 bytes, roughly 12 KB. At 300,000 records, the vectors alone come to about 3.5 GB. Many managed vector databases bill on stored volume and resident memory, so that 3.5 GB lands directly on your monthly cost. Drop to 768 and each record is about 3 KB, totaling roughly 0.9 GB. That is about a 75% reduction in storage.

The second is latency. Nearest-neighbor distance computation, whether dot product or cosine similarity, costs work proportional to the dimension count. Even graph-based indexes like HNSW repeat a dimension-sized dot product on every hop, so cutting dimensions to a quarter brings the per-hop work, in principle, down toward a quarter as well. In my own setup, the p95 latency of review search dropped visibly.

The third is memory bandwidth. This one is easy to overlook, but in large-scale search the bandwidth the CPU spends loading vectors becomes the bottleneck itself. The fewer bytes per record, the more candidates you can evaluate in the same window of time.

So 3072 dimensions may be "the best number," but it is not "always the optimal number." The question is how far you can trim without losing quality.

Why the Leading Dimensions Are Enough: Matryoshka Representation

If you truncate a vector from an ordinary embedding model partway through, the remaining part is meaningless. Because information is spread evenly across all dimensions, discarding the tail leaves the head unable to reconstruct anything.

What makes gemini-embedding-001 different is that it is trained with Matryoshka Representation Learning (MRL, named after the nesting dolls). During training, the model is penalized for poor performance not only at the full 3072 dimensions, but also on "truncated" vectors at the leading 768, 1024, 1536, and 2048 dimensions. The result is that the most important semantic information is packed into the front of the vector. It is the same idea as a nesting doll: even the outermost shell alone tells you the overall shape.

This shows up in public benchmarks. The overall MTEB score is 68.17 at both 3072 and 1536 dimensions, and 67.99 even at 768, meaning the gap from trimming all the way to 768 is tiny. I compared 3072 and 768 on a review-classification task myself, and felt no practical difference in how the clusters separated.

Here I think of my grandfather, who was a temple carpenter. He used to say that working with one's hands is a form of devotion, but more than anything he prized the eye for knowing what to cut away. Trimming dimensions is the opposite of being careless. It is discerning what is essential and where the ornament begins. The way I understand it, Matryoshka has the model do that discernment for you in advance.

For reference, the successor gemini-embedding-2-preview, released in preview in March 2026, carries the same MRL property. I am writing this around gemini-embedding-001 as the stable model you can rely on in production for a long time, but the design thinking for trimming dimensions carries straight over to the newer model.

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
Understand why Matryoshka representation lets the leading dimensions alone carry the meaning, giving you a real basis for trimming 3072 to 768
Lock down the L2 re-normalization that is mandatory after truncation, and see in code exactly why skipping it breaks search silently
Implement coarse-to-fine search that filters with 768 and re-ranks with 3072, cutting storage and latency while protecting accuracy
Secure payment via Stripe · Cancel anytime

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Gemini Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • Copy-paste ready implementation code
  • New advanced guides published daily
  • $5/mo or $10 for lifetime access
View Membership →

Related Articles

Advanced2026-05-31
The Day You Switch Gemini Embedding Models: Designing a Zero-Downtime Reindex
Upgrade your embedding model and every vector you ever stored becomes incompatible. Here is a dual-index design for re-embedding hundreds of thousands of vectors without downtime, complete with a resumable reindex job and a query-side abstraction layer.
Advanced2026-07-15
A near-miss label won't fix itself on retry — a normalization layer for closed-vocabulary classification
When responseSchema enum returns an out-of-set label, retrying tends to return the same near-miss. From a wallpaper app's 30-category batch, here is the distribution of how labels miss, plus a normalization layer built on an alias table and gemini-embedding-2 nearest-neighbor, with measured results.
Advanced2026-07-10
The Day We Went From 30 Categories to 34 — Reclassifying 1,180 Assets Instead of 8,142
Adding categories to a taxonomy does not require reclassifying everything. Here is how embeddings and confidence margins narrowed a backfill from 8,142 assets to 1,180, with the numbers.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links
See all →