How can PCA or random projection be used to compress dense vector embeddings for nearest-neighbor search?
Quick Overview
Explain how PCA and random projection reduce the size of dense embeddings for nearest-neighbor search and how the two compare. Tests the Johnson-Lindenstrauss lemma, sign projections for binary codes, quantization with re-ranking, and choosing the target dimension from measured recall.
How can PCA or random projection be used to compress dense vector embeddings for nearest-neighbor search?
Role: Machine Learning Engineer
Category: Machine Learning
Difficulty: medium
Interview Round: Other
How can PCA or random projection be used to compress dense vector embeddings for nearest-neighbor search?
Assume you serve a large corpus of high-dimensional embeddings (for example 768 dimensions) and want to cut memory and query cost without losing too much retrieval quality. Explain how each method would be applied, how they compare, and how you would decide how far to compress.
```hint What each method needs
Consider what each method has to see before it can project a vector, and what that implies when the data or the embedding model changes.
```
```hint Measuring the damage
Ask how you would know the compressed index is good enough. What would you compare its results against?
```
### What a Strong Answer Covers
- How PCA compression is fit and applied consistently to the corpus and the queries, and why the spectrum of typical embeddings makes it effective
- How random projection works, what the Johnson-Lindenstrauss lemma guarantees, and how sign projections produce binary codes
- The trade-offs between the two: accuracy per dimension, training, drift, and the target dimension each needs
- How dimensionality reduction combines with quantization and full-precision re-ranking in a real index
- How to choose the target dimension from measured recall against exact search
### Follow-up Questions
- The embedding model is retrained every month. How do you keep a PCA-compressed index consistent?
- How does OPQ differ from applying PCA before product quantization?
- When would you choose binary codes from sign projections over a PCA plus PQ index?
- How would you compress embeddings when the search metric is raw, unnormalized inner product?
Overview: Explain how PCA and random projection reduce the size of dense embeddings for nearest-neighbor search and how the two compare. Tests the Johnson-Lindenstrauss lemma, sign projections for binary codes, quantization with re-ranking, and choosing the target dimension from measured recall.
How can PCA or random projection be used to compress dense vector embeddings for nearest-neighbor search?
Assume you serve a large corpus of high-dimensional embeddings (for example 768 dimensions) and want to cut memory and query cost without losing too much retrieval quality. Explain how each method would be applied, how they compare, and how you would decide how far to compress.
What a Strong Answer Covers Guidance
How PCA compression is fit and applied consistently to the corpus and the queries, and why the spectrum of typical embeddings makes it effective
How random projection works, what the Johnson-Lindenstrauss lemma guarantees, and how sign projections produce binary codes
The trade-offs between the two: accuracy per dimension, training, drift, and the target dimension each needs
How dimensionality reduction combines with quantization and full-precision re-ranking in a real index
How to choose the target dimension from measured recall against exact search
Follow-up Questions Guidance
The embedding model is retrained every month. How do you keep a PCA-compressed index consistent?
How does OPQ differ from applying PCA before product quantization?
When would you choose binary codes from sign projections over a PCA plus PQ index?
How would you compress embeddings when the search metric is raw, unnormalized inner product?