advanced practice · system design prompt

Explain HNSW search on paper

Draw a 3-layer HNSW graph and trace a query: which layer it enters, how it greedily hops, when it descends, and where efSearch widens the search.

The mechanism

HNSW builds a layered proximity graph: sparse upper layers for long hops, dense lower layers for fine search. A query greedily walks toward the nearest neighbour, descending layers, so it touches a small neighbourhood instead of the whole set. Malkov & Yashunin report polylogarithmic search cost empirically — it is a measured scaling, not a proven bound.

Study HNSW

Expected evidence

A diagram + walkthrough showing O(log n) traversal instead of O(n) scan.

Try this drill in the practice workspace →

Hints when you need them
  • Upper layers = long hops; lower layers = fine search.
  • efSearch trades recall for latency.

Watch for these mistakes

  • Tuning efSearch/efConstruction blindly without a recall curve
  • Ignoring that HNSW is memory-hungry and hard to update/delete
  • Expecting exact results — it is approximate by design

Check the sources

Browse all practice briefs