Skip to content
aicoolies logo
hnswlib logo

hnswlib

Header-only C++ implementation of HNSW for fast approximate nearest-neighbor search.

hnswlib is a header-only C++ library implementing the Hierarchical Navigable Small World (HNSW) graph algorithm for approximate nearest-neighbor search, with Python bindings and a tiny dependency footprint. Originally developed by the nmslib team, it has become the default HNSW implementation embedded inside many vector databases and search products. Engineers use it directly when they want HNSW retrieval without pulling in a heavyweight vector DB.

About hnswlib

hnswlib is the canonical open-source implementation of the HNSW algorithm — a graph-based ANN structure that delivers state-of-the-art recall-versus-latency curves for in-memory vector search. The library is intentionally minimal: header-only C++ for the core, lightweight Python bindings for everyday use, and an interface focused on building, querying, saving, and loading indexes without ceremony.

The library has spread far beyond standalone use because of how cleanly it embeds. Vector databases including Milvus, Weaviate, Qdrant, and pgvector have either integrated hnswlib directly or based their HNSW implementations on its data structures and tuning conventions. For ML teams that need a single-process, in-memory index attached to a Python service, hnswlib is the path of least resistance — pip install, build the index, query in milliseconds.

Where hnswlib stops short is at the system layer. It is a single-machine library, not a distributed search engine: no sharding, replication, or persistence beyond a flat-file dump and reload. Development cadence has slowed compared to its early years, with fewer commits in 2024 and 2025, but the library remains stable and widely deployed. Apache-2.0 licensed.

Pricing & Platform Specs

Pricing Summary

hnswlib is a fast, header-only C++ approximate nearest neighbor search library with Python bindings, fully open-source under the Apache-2.0 license at zero cost.

Supported Platforms

Header-only C++ with Python bindings; cross-platform.

Explore categories, tags & use cases

High-performance vector database written in Rust for similarity search at scale.

Qdrant is a high-performance vector similarity search engine and database written in Rust. Designed for production-grade AI applications with advanced filtering, payload indexing, and distributed deployment. Supports billion-scale vector collections with sub-second query times. Popular choice for RAG, recommendation systems, and anomaly detection.

freemiumOpen Source

Open-source vector database for AI-native applications and semantic search.

Weaviate is an open-source vector database purpose-built for AI applications. Supports vector, keyword, and hybrid search with built-in vectorization modules for OpenAI, Cohere, Hugging Face, and more. Used for RAG pipelines, semantic search, recommendation engines, and multimodal search. Written in Go for high performance.

freemiumOpen Source

GPU-accelerated open-source vector database

Milvus is an open-source vector database with 45K+ GitHub stars for billion-scale similarity search. Features GPU-accelerated indexing, hybrid search combining vector and scalar filtering, multi-tenancy, partitioning, and horizontal scaling. Supports HNSW, IVF, DiskANN, and GPU index types. SDKs for Python, Java, Go, and Node.js. Zilliz Cloud offers a managed version. A production-grade foundation for RAG pipelines and recommendation systems at enterprise scale.

freemiumOpen Source

Embedding-first search and discovery engine for AI-powered product experiences.

Marqo is an open-source tensor search engine that combines embedding generation and vector search in a single API, removing the need to manage separate embedding pipelines and vector databases. Built for product discovery and multi-modal search, it lets teams index text, images, and structured data together, returning ranked results based on semantic similarity rather than keyword overlap.

freemiumOpen Source

Cloud-native distributed vector search engine built for Kubernetes with automatic indexing and horizontal scaling.

Vald is a highly scalable distributed approximate nearest neighbor (ANN) vector search engine designed for cloud-native, Kubernetes-based architectures. Maintained by LY Corporation and listed in the CNCF Landscape, it uses the NGT algorithm (developed at Yahoo Japan), supports automatic incremental index backup, and handles billion-scale datasets across loosely coupled microservice components that scale horizontally via Helm.

Open Source

Community experience

Sources & verification

Sources checked
Content verified

Verification dates are editorial checks. Routine CMS saves and automatic updatedAt timestamps do not advance them.

FAQ

What is hnswlib?

hnswlib is a header-only C++ library implementing the Hierarchical Navigable Small World (HNSW) graph algorithm for approximate nearest-neighbor search, with Python bindings and a tiny dependency footprint. Originally developed by the nmslib team, it has become the default HNSW implementation embedded inside many vector databases and search products. Engineers use it directly when they want HNSW retrieval without pulling in a heavyweight vector DB.

Is hnswlib free?

Yes — hnswlib is open source and free to use. hnswlib is a fast, header-only C++ approximate nearest neighbor search library with Python bindings, fully open-source under the Apache-2.0 license at zero cost.

Is hnswlib open source?

Yes — hnswlib is open source.

Is hnswlib still maintained?

Yes — hnswlib is active. Its listing was last verified on August 26, 2026.

What are the best hnswlib alternatives?

The first editor-selected hnswlib alternatives are Qdrant, Weaviate, Milvus, and more.