Skip to content
mentoor

Topic 3 of 5 · 5 min read

Dimensions, precision and storage cost

Goal: Calculate index storage for a given corpus and dimension, and choose a truncation or quantization level that meets a recall target.

An index costs vectors times dimensions times bytes per number, so you can cut storage by using fewer dimensions or fewer bytes, and you check the recall loss on your own test before you ship it. The arithmetic is simple. The only unknown is how much quality you lose.

Check yourself · 1 of 3

Roughly how big is a float32 index of 2,000,000 vectors with 768 dimensions?

Choose one answer

Why it matters

Vector search is usually held in memory for speed. A corpus that fits on a laptop at one setting may need a large server at another. Storage also drives query time and cloud bills. Teams that never run the sum meet the cost after launch.

The sum

Storage in bytes = number of vectors x dimensions x bytes per value, plus index overhead.

  • float32 uses 4 bytes per value. 1,000,000 chunks at 1,536 dimensions is 1,000,000 x 1,536 x 4 = about 6.1 GB.
  • int8 (scalar quantization) uses 1 byte per value: about 4 times smaller, 1.5 GB for the same index.
  • Binary quantization uses 1 bit per value: about 32 times smaller, roughly 0.19 GB. The Hugging Face quantization article reports that these reductions keep a large share of retrieval quality, and that binary is often paired with rescoring the top results using higher precision vectors.
  • Truncating dimensions. Models trained with Matryoshka Representation Learning put the most useful information in the first dimensions, so you can keep, say, the first 512 of 1,536 and re-normalise. Some hosted APIs expose this as a dimensions parameter. Only do it with models documented to support it; cutting a normal model's vector blindly can hurt badly.

How to choose

  1. State the recall target from your test set (for example recall@10 of at least 0.90).
  2. Measure full-size vectors first, then each cheaper setting on the same questions.
  3. Pick the cheapest setting that still meets the target, and note the margin.
  4. Repeat the check when the corpus grows or the model changes.

Before and after

Before: "Use the largest vectors, storage is cheap."

At ten times the corpus the index no longer fits in memory.

After: "Truncate to 512 dimensions and store int8: 1,000,000 x 512 x 1 byte = about 0.5 GB. Recall@10 dropped from 0.93 to 0.91 on our 30 questions, which meets the 0.90 target."

What goes wrong

  • Truncating a model that was not trained for it.
  • Quantizing without re-testing, so a recall drop is found by users.
  • Forgetting overhead: the index structure and metadata add to the raw vector size.

Examples

Storage table for 1,000,000 chunks

Setting Dimensions Bytes per value Raw size
float32 1,536 4 6.1 GB
float32 truncated 512 4 2.0 GB
int8 truncated 512 1 0.5 GB
binary 1,536 0.125 0.19 GB

Truncation with a hosted API

resp = client.embeddings.create(
    model="text-embedding-3-small",
    input=chunks,
    dimensions=512,
)

The vectors in the index and the query vectors must use the same value.

Key points

  • Storage is vectors times dimensions times bytes per value, plus overhead.
  • int8 shrinks a float32 index by about 4 times and binary by about 32 times.
  • Matryoshka-trained models can be truncated; other models should not be.
  • Choose the cheapest setting that still meets a recall target measured on your own questions.
  • Re-measure recall after any change to dimensions, precision or model.

Common mistakes

  • Cutting dimensions of a model that was not trained to be truncated.
  • Skipping the recall test after quantizing.
  • Mixing vectors of different dimensions in one index.
  • Counting only raw vector bytes and ignoring index overhead.

Check yourself · 2 of 3

Which change cuts index size by about four times?

Choose one answer

Check yourself · 3 of 3

A team truncates an older non-Matryoshka model from 1,024 to 256 dimensions. What should they expect?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic