HNSWlib

C++ headers and Python bindings for CPU vector search using HNSW proximity graphs.

Open SourceSelf HostedOffline Capable
0.0 (0)

About

Approximate nearest-neighbor lookup on layered small-world graphs, the HNSW algorithm, is the whole job here, delivered as C++ headers you drop into a project plus a pip-installable Python module. You choose squared L2, inner product, or cosine distance, set the graph degree M and the ef_construction build parameter, add vectors in multithreaded batches, then query with a tunable ef value that trades recall against speed. Indexes grow incrementally and can be resized; re-adding a label updates its vector, deleted items can be masked and their slots reused, queries accept a label filter, and Python indexes save to disk or pickle. C++ users can plug in custom distance functions and run multi-vector or epsilon searches, while R and Java bindings come from outside projects. The code is Apache-2.0, needs nothing beyond a C++11 compiler, and runs entirely on CPU. A 0.10 release candidate in September 2026 added an exception-free C++ API and stream serialization. It suits engineers embedding vector search inside their own service or library rather than running a separate database.

Should you use HNSWlib?

Pick it when

Pick HNSWlib when you want in-process HNSW search with no dependencies beyond C++11, and the index must accept inserts, updates, and deletions as data changes, with picklable Python indexes that are easy to save and reload.

Look elsewhere when

Skip it if the index will not fit in RAM or you need a metadata store, replication, or an API: it is a bare algorithm library. FAISS adds quantization for bigger data, and Voyager wraps the same core with first-class Java support.

Alternatives to HNSWlib

  • Voyager

    Built on HNSWlib with added speed and convenience plus matching Java and Python bindings; a better fit for JVM services than raw HNSWlib.

  • USearch

    Also HNSW in a single header, adding f16, i8, and binary precision, memory-mapped serving from disk, and bindings for about ten languages.

  • FAISS

    Adds IVF and product quantization for collections that outgrow RAM, plus GPU indexes; heavier and more tuning-intensive than one header file.

  • Annoy

    Read-only memory-mapped indexes shared across processes with low overhead; no incremental updates, so it only fits build-once serving.

Reviews (0)

Leave a Review

No reviews yet. Be the first to review!

Details

Price
Free
Platform
Local/Desktop
Difficulty
Intermediate (3/5)
License
Apache-2.0
Added
Apr 3, 2026

Tags