RAG & Retrieval·Question 18 of 100Intermediate

What are the tradeoffs of embedding dimensionality, and what are Matryoshka embeddings?

Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.

Model answer: the part to lead with

Dimensionality buys representational capacity and costs memory, latency, and money - linearly. Every vector of d float32 dims is 4d bytes: at 100M chunks, 768-dim vectors are ~300GB of raw vectors while 3072-dim is ~1.2TB, before index overhead - and HNSW wants that in RAM. Distance computation, network transfer, and storage bills all scale the same way. Quality, meanwhile, improves sublinearly: the jump from 256→768 dims usually matters; 1536→3072 is often a small single-digit retrieval-metric gain. Past a point, extra dims encode redundancy rather than useful distinctions, and for a narrow domain a well-trained 768-dim model routinely beats a generic 3072-dim one.

Full worked answer

Dimensionality buys representational capacity and costs memory, latency, and money - linearly. Every vector of d float32 dims is 4d bytes: at 100M chunks, 768-dim vectors are ~300GB of raw vectors while 3072-dim is ~1.2TB, before index overhead - and HNSW wants that in RAM. Distance computation, network transfer, and storage bills all scale the same way. Quality, meanwhile, improves sublinearly: the jump from 256→768 dims usually matters; 1536→3072 is often a small single-digit retrieval-metric gain. Past a point, extra dims encode redundancy rather than useful distinctions, and for a narrow domain a well-trained 768-dim model routinely beats a generic 3072-dim one.

Matryoshka Representation Learning (MRL) changes the deal: the model is trained with losses applied to nested prefixes of the vector (first 64, 128, 256... dims), so information is packed front-loaded by importance and any prefix is itself a usable embedding. Truncate a 3072-dim Matryoshka vector to 512 dims, renormalize, and you retain most retrieval quality - unlike truncating a conventionally trained embedding, which is lossy in an uncontrolled way. OpenAI's text-embedding-3 models expose this directly via the dimensions parameter, and many open-weight embedders now train with MRL.

The production pattern this unlocks is adaptive/coarse-to-fine retrieval: store short vectors (e.g., 256-512 dims) in the hot ANN index for a cheap wide first pass, then rescore the top candidates with full-dimension vectors fetched from cheaper storage - most of the quality at a fraction of the RAM. It also pairs with quantization (int8/binary) for compound savings.

Decision guidance: pick dimensionality by measuring recall@k on your own eval set at several truncation points, then choose the smallest dim whose recall loss you can't detect - memory saved there converts directly into more replicas, bigger corpora, or lower latency.

What a good answer covers

  • Dimensionality buys representational capacity and costs memory, latency, and money - linearly
  • Every vector of d float32 dims is 4d bytes
  • Distance computation, network transfer, and storage bills all scale the same way
  • Quality, meanwhile, improves sublinearly
  • Past a point, extra dims encode redundancy rather than useful distinctions, and for a narrow domain a…

Key terms: linearly · Matryoshka Representation Learning (MRL) · adaptive/coarse-to-fine retrieval

Interviewer follow-ups to expect

  1. Why must you renormalize after truncating?

  2. How would you combine Matryoshka truncation with int8 or binary quantization?

  3. At what corpus scale does dimensionality start dominating your infra bill?

Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep