Zenaique

Pick an embedding dimension for a 50M doc index with a 10 GB RAM budget

Short answer·Hard·4.0 · 0·~3 min·Asked atAppleDatarobotRoblox·Relevant atElasticHugging FaceNeo4jRedis
Attempt it

You're standing up an embedding based retrieval system over 50,000,000 documents on a single node with 10 GB of available RAM. You need to fit the vectors in memory (HNSW requires this) with some headroom for graph edges. Walk through how you'd pick the embedding dimension and what compromises you make.

Free · 2 AI evals / day
TL;DR

Combine Matryoshka truncation with binary or int8 quantization, size the result against an HNSW 2x overhead, then validate recall on a labeled set.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

Imagine you have a small suitcase and far too many shirts. You have three tricks. You can pick fewer shirts. You can roll each shirt tighter. You can squash them into a vacuum bag. One trick alone is not enough to close the lid. Combine two of them and the suitcase finally shuts. Then you take the shirts out, wear them, and check whether they still look good before you head to the airport. Otherwise you arrive at the wedding wearing wrinkled rags. Same with packing your search index. Pick the cleanup steps, stack them carefully, then double check the outfits look right before the big trip.

Key concepts

Concept explanation~2 min read

Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.

This is a classic capacity question. The trap is to anchor on a familiar dim (1536) without doing the storage arithmetic. The real work is reasoning across three levers (dim, per-dim precision, and graph architecture) and landing on a configuration that fits the budget while staying within an acceptable recall envelope.

The walkthrough below does the math, names the levers, picks a defensible configuration, and ends with the validation step that turns a guess into an engineering decision.

The storage arithmetic

Raw float32 baseline

For 50M docs at d dimensions in float32:

bytes=Nd4=50106d4\text{bytes} = N \cdot d \cdot 4 = 50 \cdot 10^6 \cdot d \cdot 4

At d = 1024 that is 205 GB. At d = 256 it is 51 GB. Both blow the 10 GB budget by an order of magnitude.

Per-precision cost table

PrecisionBytes per dimAt d=1024, 50M docsAt d=512, 50M docs
float324205 GB102 GB
float162102 GB51 GB
int8151 GB26 GB
binary0.1256.4 GB3.2 GB

Only the binary row fits comfortably at d = 1024. Int8 fits only at very low dims that lose too much recall.

HNSW edge overhead

HNSW stores M neighbors per node. At default M = 32 the overhead is roughly 256 bytes per node, or ~13 GB for 50M nodes. That number itself exceeds the budget at this scale before you even count the vectors. Setting M = 16 cuts it to ~6 GB, M = 12 to ~4.5 GB. M trades recall for memory.

The three levers and their recall costs
Sizing a defensible configuration
When to abandon HNSW
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.

Real products, models, and research that use this idea.

  • Pinecone Serverless 2026 uses Matryoshka truncation + binary quant as a default budget configuration.
  • OpenAI text-embedding-3-large at 3072 dims with binary quant via libraries like sentence-transformers + faiss-binary.
Sign in to see more production examples.

What an interviewer would ask next. Try answering before peeking at the approach.

QWhere exactly is the 2x HNSW overhead coming from?
A

Each node stores M edges at the bottom layer and a smaller M0 on upper layers, plus link IDs and neighbor distances. At M=32, that is roughly 256 bytes per node, comparable to a 256-d int8 vector.

2 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

Forgetting that HNSW graph edges roughly double the per-vector footprint, so a 'fits in RAM' calculation that ignores graph overhead misses by 2x.

Sign in to see all red flags and common mistakes.

60 second bullets to scan on the way to the call.

  • Bytes-per-vector math for float32, int8, and binary

  • HNSW edge overhead at typical M values

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
Why is cosine similarity preferred over Euclidean distance for text embeddings?
Flashcard·Easy