hnswlib

active

by nmslib contributors · since 2017 · also known as nmslib hnswlib

Header-only C++ HNSW library with Python bindings, from the authors of the HNSW algorithm.

vectorembedded libraryopen source (permissive)mature

Overview

hnswlib is the reference implementation of Hierarchical Navigable Small World graphs, maintained under the nmslib organisation with contributions from HNSW co-author Yury Malkov. It is a small header-only C++ library with Python bindings that supports incremental inserts, deletions via marking, filtering callbacks and saving/loading indexes, using L2, inner product or cosine distance. Many early vector databases and RAG tools embedded it directly, and it remains a common baseline. It is a library with no metadata store or server, and releases are infrequent (0.9.0 in March 2026, 0.10 in release candidates).

Strengths & trade-offs

Strengths

  • +Reference HNSW implementation with excellent recall/speed trade-offs
  • +Header-only and dependency-free
  • +Incremental inserts and soft deletes
  • +Simple Python API used by many tools

Trade-offs

  • −RAM-only index, no quantization
  • −No metadata storage or server
  • −Slow release cadence
  • −Single distance family per index

Great for

  • +Embedding HNSW in applications
  • +Baseline for ANN benchmarks
  • +Small in-process semantic search

Think twice for

  • −Datasets larger than RAM
  • −Teams needing a database with filters and CRUD

Capabilities

Native or official first-party support · 2 of 25 tracked

✓Vector search
✓In-memory
–Transactions
–Joins
–Secondary indexes
–Full-text search
–Geospatial
–JSON
–Change data capture
–Triggers
–Stored procedures
–Materialized views
–TTL / expiry
–Pub/Sub
–Columnar storage
–Durable persistence
–Compression
–Encryption at rest
–Role-based access
–Time travel
–Branching
–Online schema changes
–Streaming ingest
–Offline sync
–Runs in WebAssembly

Scale & consistency

Comfortable data size
Medium · ≤ 10 TB
Horizontal scaling
Manual
Multi-region
No
Transactions
None
Consistency
Strong
Schema
Schemaless
Architecture
Embedded, In memory
Query languages
Library API

Whole index lives in RAM in one process; tens to hundreds of millions of vectors on a large machine.

Deployment

Self-hosted Vendor-managed cloud Serverless Embedded Edge Kubernetes operator

Ecosystem

apis & protocolsC++, Python
client languagesC++, Python

Alternatives to hnswlib

Compare all→
FaissVector44.7

Meta's C++/Python library for fast dense-vector similarity search and clustering, CPU and GPU.

hnswlib vs faiss →
USearchVector23.1

Single-header C++ HNSW library with SIMD distance kernels and bindings for a dozen languages.

hnswlib vs usearch →
AnnoyVector15.3

Spotify's memory-mapped random-projection-tree ANN library; stable but no longer evolving.

hnswlib vs annoy →
ScaNNVector6.3

Google Research's ANN library using anisotropic quantization; the tech behind Vertex AI and AlloyDB vectors.

hnswlib vs scann →
QdrantVector35.9

Rust vector search engine with rich payload filtering, quantization and a managed cloud.

hnswlib vs qdrant →
ValdVector5.6

Kubernetes-native distributed vector search engine built on Yahoo Japan's NGT.

hnswlib vs vald →

hnswlib FAQ

What is hnswlib?

hnswlib is a vector database by nmslib contributors, first released in 2017. hnswlib is the reference implementation of Hierarchical Navigable Small World graphs, maintained under the nmslib organisation with contributions from HNSW co-author Yury Malkov. It is a small header-only C++ library with Python bindings that supports incremental inserts, deletions via marking, filtering callbacks and saving/loading indexes, using L2, inner product or cosine distance. Many early vector databases and RAG tools embedded it directly, and it remains a common baseline. It is a library with no metadata store or server, and releases are infrequent (0.9.0 in March 2026, 0.10 in release candidates).

Is hnswlib open source?

Yes. hnswlib is open source. License: Apache License 2.0.

Does hnswlib support ACID transactions?

No. hnswlib does not provide ACID transactions; its consistency model is strong.

Does hnswlib scale horizontally?

hnswlib has no built-in sharding; scaling out means partitioning data in your application. It is comfortable at medium scale (≤ 10 TB).

How can I run hnswlib?

You can self-host it and embed it in your application.

What is hnswlib best for?

hnswlib is a strong fit for embedding HNSW in applications, baseline for ANN benchmarks and small in-process semantic search. Think twice for datasets larger than RAM.

What are the best alternatives to hnswlib?

Common alternatives to hnswlib include Faiss, USearch, Annoy, ScaNN and Qdrant. The right choice depends on your workload, scale and hosting; WhichDB's smart match ranks them against your requirements.

How popular is hnswlib?

hnswlib ranks #211 of 844 databases on the WhichDB Score (15.5/100), and #12 among vector databases. The score combines public adoption signals such as package downloads, GitHub activity, job posts and developer discussion.