A C++ library for large-scale approximate nearest neighbor vector search, with index build, search, and distributed serving toolkits.
lmcinnes/pynndescent
A pure-Python approximate nearest neighbor search library built on Nearest Neighbor Descent, with broad distance metric support.
- Stars
- 975
- Forks
- 116
- Open issues
- 90
- Last commit
- yesterday
What is it?
PyNNDescent builds a k-nearest-neighbor graph and answers approximate nearest neighbor queries over it. It implements Nearest Neighbor Descent, using random projection trees for initialisation and pruning long edges of triangles in the graph to improve the result. It is aimed at workloads where high accuracy, roughly 80% to 100% recall, is wanted.
The interface is small: build an index with NNDescent(data), then call index.query(query_data, k=15). Indexes can be pickled to disk. The library supports a wide range of metrics out of the box, including Euclidean, Manhattan, cosine, Hamming, Jaccard and Wasserstein, along with user-defined distance functions.
It is installable with pip or conda and integrates with scikit-learn, including a KNeighborTransformer that can replace other nearest neighbor components.
Key features
- 01Builds k-nearest-neighbor graphs with Nearest Neighbor Descent and random projection tree initialisation.
- 02Supports many built-in distance metrics, including binary and probability metrics.
- 03Accepts custom user-defined distance functions.
- 04Offers a minimal API with index construction and k-NN querying.
- 05Integrates with scikit-learn as a KNeighborTransformer.
Use cases
- Finding similar items in high-dimensional embedding vectors for search or recommendation.
- Running nearest neighbor computations inside scikit-learn pipelines.
- Building k-NN graphs for downstream tasks such as clustering or manifold learning.
- Searching with non-Euclidean metrics such as cosine, Jaccard or Wasserstein distance.
Quick start
- 1
Install the package with pip
pip install pynndescent - 2
Build a search index on your data and query it for 15 nearest neighbors
Things to know
- The README says the project is still young and its documentation is still growing.
- It targets high-accuracy approximate search (80%-100% accuracy), not exact search.
Topics
FAQ
- What is pynndescent?
- A pure-Python approximate nearest neighbor search library built on Nearest Neighbor Descent, with broad distance metric support. PyNNDescent builds a k-nearest-neighbor graph and answers approximate nearest neighbor queries over it. It implements Nearest Neighbor Descent, using random projection trees for initialisation and pruning long edges of triangles in the graph to improve the result. It is aimed at workloads where high accuracy, roughly 80% to 100% recall, is wanted.
- Is pynndescent free to use? What license does it have?
- pynndescent is open source under the BSD-2-Clause license. Check the license terms before using it in commercial products.
- Is pynndescent still maintained?
- Actively maintained. The last commit to pynndescent was on Nov 6, 2026.
- What can I use pynndescent for?
- Finding similar items in high-dimensional embedding vectors for search or recommendation. Running nearest neighbor computations inside scikit-learn pipelines. Building k-NN graphs for downstream tasks such as clustering or manifold learning. Searching with non-Euclidean metrics such as cosine, Jaccard or Wasserstein distance.
- How do I install pynndescent?
- Install the package with pip: pip install pynndescent Build a search index on your data and query it for 15 nearest neighbors
- Where can I get pynndescent?
- The source code and installation instructions are on GitHub: https://github.com/lmcinnes/pynndescent
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
Open-source vector similarity search extension for Postgres, storing and querying embeddings alongside your relational data.
An embedded retrieval library and database for multimodal AI, offering vector, full-text and SQL search over data stored in the Lance format.
An AI-native database for LLM applications, offering hybrid search over dense vectors, sparse vectors, tensors and full-text.
A C++ library and command-line tool for fast approximate nearest neighbor search over high-dimensional vectors, using graph and tree indexes.
Header-only C++ library with Python bindings for fast approximate nearest neighbor search using the HNSW graph algorithm.