nmslib/hnswlib

Header-only C++/python library for fast approximate nearest neighbors

What it solves

hnswlib is a fast, lightweight implementation of the Hierarchical Navigable Small World (HNSW) algorithm for approximate nearest neighbor (ANN) search. It allows users to efficiently find the closest vectors in a large dataset based on distance metrics like L2, Inner Product, or Cosine distance, avoiding the need for a slow exhaustive search.

How it works

The library implements HNSW, a graph-based approach to nearest neighbor search. It organizes vectors into a hierarchical structure of graphs, allowing for fast navigation to the closest points. The library provides a header-only C++ implementation with Python bindings, supporting incremental index construction, element updates, and deletions.

Who it’s for

It is designed for developers building applications that require high-performance vector search, such as recommendation systems, image retrieval, or RAG (Retrieval-Augmented Generation) pipelines, who need a lightweight tool with minimal dependencies.

Highlights

  • Lightweight Design: Header-only C++ 11 implementation with no external dependencies.
  • Flexible Interfaces: Native support for C++ and Python, with external community support for Java and R.
  • Dynamic Indexing: Full support for incremental construction, updating existing elements, and marking elements for deletion.
  • Customizable: Supports custom user-defined distance metrics in C++.
  • Efficiency: Lower memory footprint and faster build times compared to other implementations like nmslib.

Related

  • Project
  • Project
  • Project
  • Project