Which statement about the HNSW parameters M, efConstruction and efSearch is correct?
Show the answer and explanation
Correct answer: D, M and efConstruction are build-time settings that shape graph connectivity, memory and build cost, while efSearch is a query-time setting you can tune per request without a rebuild.
Explanation Vector Databases
HNSW (Hierarchical Navigable Small World) builds a multi-layer proximity graph. A query enters at the sparse top layer, greedily moves towards the query vector, and descends to the dense bottom layer, where it keeps a candidate list of size efSearch and returns the best k.
| Parameter | Set at | Effect | Typical values |
|---|---|---|---|
M | build | links per node (2M at layer 0): higher recall ceiling, more memory, slower build | 16–64 |
efConstruction | build | candidate list while inserting: better graph quality, slower build | 100–500 |
efSearch (ef) | query | candidate list while searching (≥ k): recall ↑, latency ↑ | 40–500 |
Because efSearch is a query-time knob, you can use different values per request, e.g. a higher value for an offline batch job or a premium tier. In pgvector it is the session setting hnsw.ef_search; in FAISS it is index.hnsw.efSearch.
Why the other statements are wrong: they swap the build-time and query-time roles of efSearch and M, confuse efConstruction with k and efSearch with the number of links per node, or claim M has no effect on recall or memory. Memory grows roughly linearly with M because every node stores up to 2M neighbour IDs at the bottom layer, and recall improves because the graph has more routes to the true neighbours.
Other practical points: HNSW is memory-resident, deletes are usually soft (tombstones) and degrade the graph over time, and very restrictive metadata filters can disconnect the traversal.
Interview tip: describe tuning as "choose M and efConstruction once for the recall ceiling and memory budget, then tune efSearch to hit the latency SLA".