Hasty Briefsbeta

Bilingual

Show HN: HNSW index for vector embeddings in approx 500 LOC

a year ago
  • #HNSW
  • #search
  • #C++
  • HNSW is a graph structure with levels that are sparsely populated at the top and densely populated at the bottom.
  • Nodes in a layer connect to nearby nodes on the same level.
  • Insertion involves picking a random level and inserting the node there and all levels below.
  • Searches start at the top level, descend, and track the K nearest nodes.
  • The implementation is a single-header, modern C++ library with about 500 lines of code.
  • It uses Eigen for SIMD acceleration to speed up distance calculations.
  • Example usage includes creating an index, adding vectors, and searching for nearest neighbors.