Vector Search hard
Your HNSW index (M=16) reaches recall@10 of 91% at ef_search=64 with a p99 of 6 ms. The target is 97% recall within a 15 ms p99. A full rebuild takes 14 hours. What is the right tuning order?
- A Raise M on the live index; M controls neighbors visited per hop, so increasing it lifts recall with no rebuild.
- B Raise ef_construction alone, since recall depends on how the graph was built and query-time settings cannot move it.
- C Raise ef_search first and measure; rebuild with higher M or ef_construction only if the 15 ms budget runs out first.
- D Switch the index metric from cosine to L2, since L2 graphs reach higher recall at the same M and ef_search.
Answer: C. Raise ef_search first and measure; rebuild with higher M or ef_construction only if the 15 ms budget runs out first.
**ef_search** is a query-time knob that trades latency for recall without a rebuild. With p99 at 6 ms against a 15 ms budget, there is room to raise it. **M and ef_construction** are fixed at build time: raising them lifts the recall ceiling but costs memory and a 14-hour rebuild, so they are the right lever only when ef_search exhausts the latency budget before hitting the target. Option B ignores the cheaper, reversible knob.
One system design question a day, with spaced repetition so the ones you miss come back.
Get the appRelated questions
- You are building an IVF index on 20 million vectors. A teammate asks why the build needs a 'training' step before any vectors can be added. What is the reason?
- An HNSW index serves a marketplace where about 30% of listings are updated or removed each week. Each update is applied as a delete plus an insert, and deletes mark tombstones. Over a month, recall@10 drifts from 97% to 89% and p99 latency rises at the same ef_search. What is happening, and what should you do?
- Users delete documents in your primary database, but the deleted documents keep appearing in vector search results for hours. The vector index is rebuilt nightly. What is the best fix?
- Your embedding model outputs unnormalized vectors whose magnitudes vary widely. A teammate wants to switch the index from cosine similarity to dot product because it is cheaper to compute. What is the consequence?
- You are setting an SLO for a new ANN-backed recommendation search over 50 million vectors. A product manager asks for 100% recall@10 with single-digit millisecond latency. What is a realistic response?
- A B2B SaaS app serves 500 customers, and every query searches only one customer's documents. One large customer runs heavy batch queries that slow down search for everyone. Which sharding approach fits best?