cswork / libraryOpen practice workspace

Articles

Embedding Dimension Interview Questions: Matryoshka Truncation and Retrieval Quality

Practice embedding dimension interview questions with Matryoshka truncation, normalization, ranking checks, and an exact-versus-ANN evaluation design.

Your retrieval index stores 768-dimensional embeddings. A teammate proposes keeping the first 192 coordinates to cut vector storage by four. The arithmetic is correct for raw float32 values. The claim that retrieval quality will remain unchanged needs a different kind of evidence.

Embedding dimension interview questions test whether you can separate a smaller representation from a reliable retrieval system. You need to verify that the model supports useful truncation, preserve query-document compatibility, and distinguish representation loss from approximate-search errors.

Evidence boundary: The Matryoshka Representation Learning paper, Sentence Transformers documentation, and Faiss documentation support the mechanics cited below. Recommendations are editorial inference, not candidate reports or a benchmark of a production embedding model.

What makes Matryoshka truncation different from cutting any vector?

Research fact: Matryoshka Representation Learning trains nested representations so that prefixes at multiple dimensions remain useful. Its published results concern the authors’ models, tasks, and evaluations; they do not establish a universal quality guarantee for every embedding model or dataset.

Official implementation fact: Sentence Transformers’ Matryoshka guide describes applying a loss at multiple truncated dimensions and combining those losses. A trained model can then produce a selected prefix representation at inference.

An ordinary embedding model may distribute useful information throughout its coordinates. The first 192 values are not automatically the most informative values. Selecting a prefix is also different from PCA, a learned projection, or quantizing every coordinate.

A good opening answer asks: which checkpoint, which supported dimensions, which task, and which measured quality target? A model name containing “embedding” is insufficient evidence. Preserve the documentation or model card that supports the intended configuration.

For an original migration case, the current model was trained only at full dimension, while a proposed replacement supports nested prefixes. Comparing them at 192 dimensions changes both the checkpoint and the representation size. You cannot attribute the resulting difference to dimension alone.

Editorial inference: First compare dimensions within the same compatible checkpoint. Evaluate model replacement separately, or design an experiment that clearly labels both factors. Otherwise, an apparent compression improvement may simply reflect a better model.

Why should truncation and normalization be separate steps?

Cosine similarity divides a dot product by both vector norms. If you keep a prefix of a unit-length full vector, the prefix generally does not still have unit length.

Official implementation fact: Faiss explains that normalized vectors with inner-product search implement cosine similarity, and that both database and query vectors should be normalized. See Faiss metric types and distances.

For the cosine-based original examples here, the intended pipeline is:

compatible embedding → first d coordinates → check norm → normalize prefix → search.

Perform the same transformation for queries and documents. Normalizing the full vector before truncation does not guarantee a normalized prefix afterward. If you use a cosine function that divides by prefix norms itself, do not confuse that with raw inner-product search over the truncated values.

A zero-norm prefix needs deliberate handling because cosine similarity is undefined. Silently returning NaNs or dividing by a tiny epsilon can produce misleading rankings. Treat malformed vectors and zero prefixes as observable errors or a documented fallback, then test that behavior.

The metric choice matters. If the model’s intended score is an unnormalized dot product, forcing normalization changes its semantics. The instruction is not “normalize everything”; it is “make representation processing agree with the chosen model and index metric.”

Record this compatibility tuple for the original migration: checkpoint version, preprocessing, query/document prompting where required, dimension, normalization rule, metric, and index generation. Equal dimensions alone do not prove compatible vector spaces.

Can truncation reverse the nearest-neighbor ranking?

Yes. Here is an original toy-vector counterexample, not a Matryoshka-model benchmark:

query = [1.0, 0.0, 1.0, 0.0]
A     = [1.0, 0.0, 0.0, 0.0]
B     = [0.8, 0.2, 1.0, 0.0]

At full dimension, cosine similarity is approximately 0.707107 for A and 0.981981 for B. B ranks first. Keeping only the first two coordinates gives cosine 1.0 for A and approximately 0.970143 for B. A now ranks first.

ConfigurationCosine with ACosine with BFirst result
Full four coordinates0.7071070.981981B
First two coordinates1.0000000.970143A

The omitted third coordinate contained information that favored B. Renormalization makes cosine scoring consistent for the new representation; it does not restore that information.

A compact implementation reproduces the trace:

import numpy as np

q = np.array([1.0, 0.0, 1.0, 0.0])
docs = np.array([[1.0, 0.0, 0.0, 0.0],
                 [0.8, 0.2, 1.0, 0.0]])

def scores(d):
    query = q[:d]
    vectors = docs[:, :d]
    query = query / np.linalg.norm(query)
    vectors = vectors / np.linalg.norm(vectors, axis=1, keepdims=True)
    return vectors @ query

full = scores(4)
prefix = scores(2)
assert np.argmax(full) == 1
assert np.argmax(prefix) == 0

This example refutes a universal claim that arbitrary prefix truncation preserves rankings. It does not refute Matryoshka training, which changes how representations are learned. Nor does it prove that a particular production model will lose useful recall at 192 dimensions.

In an interview, state what the counterexample establishes and what it cannot establish. That boundary is part of the answer.

How do you separate dimension loss from ANN loss?

A retrieval result can change because the representation changed, because approximate nearest-neighbor search missed candidates, or because preprocessing, filters, or corpus contents changed.

Use this original evaluation matrix with the same queries, documents, filters, relevance labels, and checkpoint:

RepresentationExact searchANN search
Full dimensionRepresentation baselineFull-vector ANN behavior
Truncated dimensionTruncation under exact scoringCombined truncation and ANN behavior

Compare full exact against truncated exact to examine the representation change without approximation. Compare ANN against exact at the same dimension to examine approximation. Compare deployed configurations for the combined user-visible effect.

These differences need not add linearly. The truncated representation changes geometry, which can also change how an ANN configuration behaves. Retune the index where appropriate, and disclose whether the comparison uses equal settings, equal latency budgets, or equal memory budgets.

Two different metrics are often called recall. Relevance recall at k asks how many labeled relevant documents were returned. ANN recall at k asks how many exact nearest neighbors for the same representation were recovered. A system can recover exact neighbors perfectly while those neighbors are irrelevant to users.

Editorial inference: Report both when they answer different failure questions. Use relevance metrics such as recall or ranking quality with a documented judgment scheme, and approximation metrics against a same-dimension exact baseline. State how ties, duplicate documents, missing judgments, and empty relevant sets are handled.

Keep query slices visible. Short identifiers, rare entities, multilingual queries, and queries requiring subtle distinctions may react differently to truncation. Those are hypotheses for evaluation, not guaranteed failure categories.

A global average that improves can still hide a regression in an important slice. Preserve per-query comparisons so you can inspect changed rankings instead of reporting only one aggregate score.

What costs actually shrink with fewer dimensions?

Here is an original storage calculation for one million vectors, float32 values, and no additional storage overhead:

  • At 768 dimensions: 1,000,000 × 768 × 4 = 3,072,000,000 bytes, or 3.072 decimal GB.
  • At 192 dimensions: 1,000,000 × 192 × 4 = 768,000,000 bytes, or 0.768 decimal GB.

The raw vector array is four times smaller. The complete index also includes graph or quantization structures, identifiers, metadata, allocator overhead, replicas, and other components. Its total storage ratio need not be four.

Lower dimension can reduce vector arithmetic and data movement, but end-to-end retrieval latency also includes filtering, network calls, candidate traversal, reranking, and document loading. Measure the complete workload rather than promising a fourfold latency improvement from the raw storage ratio.

Official implementation fact: Sentence Transformers notes that reducing the output embedding dimensions does not by itself make the underlying model’s training or inference faster or smaller. Its Matryoshka guide separates encoder costs from processing and storing the resulting embeddings.

For an original deployment answer, identify which stage dominates today. If encoder inference consumes most of the request budget, a smaller stored prefix may have little effect on total response time. If large exact scans dominate, reducing vector length may matter more. Neither statement replaces a benchmark.

Also distinguish precision reduction from dimension reduction. Float16, quantization, and fewer coordinates are different changes with different quality and infrastructure implications. Testing them simultaneously without separate baselines makes the result difficult to diagnose.

Can a small prefix retrieve candidates for a larger reranker?

A cascade can use a short prefix for candidate generation and a larger representation for reranking. The MRL paper investigates coarse-to-fine applications of nested representations. Its results support that design direction within the studied settings, not a guarantee for your corpus.

The original design question is: how many candidates must the first stage retain to preserve useful documents for the second stage? A reranker cannot recover a relevant document that never reached its candidate set.

If you retain full vectors for reranking, include their storage and loading cost. Keeping only the short prefix does not allow you to reconstruct arbitrary omitted coordinates. Re-encoding documents later introduces encoder work and versioning concerns.

Editorial inference: Evaluate candidate-set relevance recall alongside final ranking quality and latency. Compare several candidate counts using a fixed query set. A cascade is useful only if its combined cost-quality trade-off meets the requirement.

Scores can change with dimension, so a similarity threshold calibrated at 768 dimensions should not be copied blindly to 192. Recheck threshold-based decisions, deduplication, and confidence displays under the new configuration.

For migration, build a compatible index generation, verify query routing to that generation, and keep rollback possible. Mixing full-vector documents with prefix queries or switching the query checkpoint before rebuilding documents can create meaningless comparisons even if an API accepts the payload.

Sources and Further Reading