{"id":2224,"library":"pynndescent","title":"PyNNDescent","description":"PyNNDescent is a Python library that provides a fast and flexible implementation of Nearest Neighbor Descent for approximate nearest neighbor search and k-neighbor-graph construction. It supports a wide variety of distance metrics, sparse matrix inputs, and integrates with Scikit-learn. The current version is 0.6.0, and it maintains a regular release cadence with several minor patches and updates throughout the year.","status":"active","version":"0.6.0","language":"en","source_language":"en","source_url":"https://github.com/lmcinnes/pynndescent","tags":["nearest neighbors","machine learning","similarity search","approximate nearest neighbors","graph algorithm"],"install":[{"cmd":"pip install pynndescent","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core numerical operations.","package":"numpy","optional":false},{"reason":"Scientific computing and sparse matrix support.","package":"scipy","optional":false},{"reason":"Integration with scikit-learn pipelines, required for PyNNDescentTransformer.","package":"scikit-learn","optional":false},{"reason":"JIT compilation for performance optimization, especially for custom distance metrics.","package":"numba","optional":false}],"imports":[{"symbol":"NNDescent","correct":"from pynndescent import NNDescent"},{"note":"Used for scikit-learn pipeline integration.","symbol":"PyNNDescentTransformer","correct":"from pynndescent import PyNNDescentTransformer"}],"quickstart":{"code":"import numpy as np\nfrom pynndescent import NNDescent\n\n# Generate some sample data\ndata = np.random.rand(1000, 64).astype(np.float32)\n\n# Build the NNDescent index\n# n_neighbors specifies the number of neighbors to find for each point\n# verbose=True shows progress\nindex = NNDescent(data, n_neighbors=15, verbose=True)\n\n# Build the index (computes the nearest neighbor graph)\nindex.prepare()\n\n# Query the index for the 5 nearest neighbors of new data\nquery_data = np.random.rand(10, 64).astype(np.float32)\nneighbors, distances = index.query(query_data, k=5)\n\nprint(\"Shape of neighbors (query_points, k):\"), print(neighbors.shape)\nprint(\"Shape of distances (query_points, k):\"), print(distances.shape)\nprint(\"First query point's 5 nearest neighbor indices:\"), print(neighbors[0])\nprint(\"First query point's 5 nearest neighbor distances:\"), print(distances[0])","lang":"python","description":"This quickstart demonstrates how to initialize `NNDescent` with training data, prepare the index, and then query for approximate nearest neighbors. It generates random data for demonstration purposes."},"warnings":[{"fix":"Remove the `n_search_trees` parameter from `NNDescent` initialization. The library will automatically choose an appropriate value.","message":"The `n_search_trees` parameter in `NNDescent` has been deprecated. While it may still work, it's recommended to rely on the default or other parameters for controlling initialization.","severity":"deprecated","affected_versions":">=0.5.5"},{"fix":"Upgrade `pynndescent` to version `0.5.13` or newer, or ensure `numpy` version is compatible with your `pynndescent` installation.","message":"For NumPy versions 2.0 and above, `np.infty` has been replaced with `np.inf`. PyNNDescent versions `0.5.13` and later include patches for compatibility. If using an older version of PyNNDescent with newer NumPy, this could lead to issues.","severity":"gotcha","affected_versions":"<0.5.13"},{"fix":"Ensure your Python environment is running Python 3.8 or newer. Consider upgrading to Python 3.12 or 3.13 for full compatibility.","message":"Version `0.6.0` removed support for End-of-Life Python versions and officially added support for Python 3.12 and 3.13. If you are on an older Python version, this update may break your environment.","severity":"breaking","affected_versions":"0.6.0"},{"fix":"Upgrade `pynndescent` to version `0.5.9` or newer, which includes fixes for these issues.","message":"Earlier versions (`<0.5.9`) had bugs causing infinite recursion during random projection tree generation, especially for certain datasets or configurations. This could lead to crashes or hanging processes.","severity":"gotcha","affected_versions":"<0.5.9"},{"fix":"Profile your application after upgrading to identify any performance regressions. Consider pre-calculating distances or optimizing custom distance functions if performance becomes an issue.","message":"In `0.5.11`, caching for functions that take distance metrics as arguments was removed. If your application relied on this caching for performance, you might observe a change in execution time after upgrading.","severity":"gotcha","affected_versions":">=0.5.11"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}