Concept guide · Embeddings and vector search
How does HNSW work at a high level?
A slower explanation for when the short interview answer is not enough. Start with the intuition, then connect it to the technical idea and the way an interviewer expects you to reason about it.
ML area
Generative AI → HNSW indexes
Interview format
Advanced · Scenario
Question
GENAI-039
Start with the idea
In simple terms
HNSW builds a navigable graph over vectors. Search starts in a sparse upper layer, moves toward promising neighbours, then searches denser lower layers to find nearby vectors without scanning everything.
Make it concrete
A query enters the graph at a coarse location, hops toward closer vectors, and spends more search effort only in the promising neighbourhood.
Build the answer
How to approach it
- 1Describe the layered graph and why it avoids a full scan.
- 2Connect construction and search parameters to recall, memory, and latency.
- 3Mention that metadata filters can change the effective search problem.
Go one level deeper
The technical explanation
HNSW exposes a practical trade-off between graph connectivity, construction effort, search effort, memory, and recall. More connections or a wider search budget can improve recall but cost more resources. Filtered search can be harder than unfiltered search because valid neighbours may be excluded; the index and payload strategy must be evaluated together rather than tuning HNSW in isolation.
Say this in the interview
HNSW builds navigable layers of connected vector points and searches from coarse upper layers toward a local neighbourhood in lower layers. More connections and search effort often improve recall but increase memory and latency. The exact tuning names vary by database, so evaluate the index on your workload.
Keep preparing