In the world of AI, more isn't always better. When building search systems, choosing the right number of dimensions for your embeddings is a high-stakes balancing act between precision and cost.
The Dimensionality Dilemma
When we talk about embeddings in machine learning, we are
essentially talking about turning data—like text or images—into long lists of numbers called vectors. The length of these lists is the dimensionality. A higher dimensionality means the model can capture more nuanced, subtle relationships between pieces of data, which theoretically leads to better search results. However, there is a massive catch: every single dimension you add increases the amount of memory your system needs to hold those vectors and the computational power required to search through them. It is the classic engineering struggle of maximizing performance while minimizing overhead.
Accuracy vs. Efficiency
The relationship between dimensionality and retrieval accuracy, often measured by metrics like nDCG (Normalized Discounted Cumulative Gain), is not a straight line upward. Instead, it follows a curve of diminishing returns. For many modern models, such as the Gemini-embedding-2, you might find that the model hits a performance plateau relatively early. For instance, in certain scientific retrieval benchmarks, a model might reach nearly its full retrieval potential at just 768 dimensions, even if its maximum capacity is 3,072 dimensions. This means that jumping from 768 to 3,072 dimensions might only yield a tiny fraction of a percent improvement in accuracy, while simultaneously ballooning your storage requirements.
The Hidden Cost of Storage
Storage isn't just about the raw numbers; it is about how those numbers live in your database. In a production environment using tools like PostgreSQL with pgvector, the footprint of your data is split between the raw vectors and the specialized indexes used to make searching fast, such as HNSW (Hierarchical Navigable Small World) indexes. As you increase dimensionality, the size of these indexes grows linearly. If you are managing millions of data chunks, moving from a low-dimensional vector to a high-dimensional one can mean the difference between a database that fits comfortably in your server's RAM and one that is so massive it requires expensive, high-speed disk storage, significantly slowing down your application.
The Magic of Quantization
To fight these rising costs, engineers use a trick called quantization. Instead of using high-precision 32-bit floats to store every number, they might switch to 16-bit floats (often called halfvec). This simple move can cut your storage and index size in half with virtually zero loss in retrieval accuracy. In some cases, you can even truncate vectors down to much smaller sizes—like 256 dimensions—and still retain over 97 percent of the peak performance. This allows for massive savings; a 256-dimension vector can be up to 24 times smaller than a full-sized 3,072-dimension vector, making it a powerhouse for cost-sensitive applications.













