Episode 3 of 3 · 12:25
HNSW Algorithm Explained: Hierarchical Navigable Small World Graph for ANN Search
What this episode covers
HNSW, the index behind vector search in pgvector, Qdrant, Weaviate and Elasticsearch, taken apart on a real graph: why exact search stops scaling, the navigable small world graph and greedy routing (and where it gets stuck), the layers and how a node's top layer is drawn, how search descends to layer 0 and runs a beam of size ef, how insertion picks neighbours with the selection heuristic and prunes full nodes, and what M, ef_construction and ef trade, measured with hnswlib on the book's 629 bge-m3 vectors.
At the end: you can tell what M, ef_construction and ef cost and buy in recall, memory and speed, checked against exact search with recall at 10.