Hierarchical Navigable Small World (HNSW) is a graph-based approximate nearest neighbor (ANN) search algorithm that constructs a multi-layered, hierarchical graph to enable extremely fast and accurate similarity retrieval in high-dimensional spaces. It is a core indexing method in modern vector databases and Retrieval-Augmented Generation (RAG) systems. The algorithm's design, inspired by small-world network theory, provides a superior trade-off between query speed, recall accuracy, and memory efficiency compared to earlier ANN methods like Inverted File (IVF) or Product Quantization (PQ).
