{"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":"python","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,"search_vec":"'0.6.0':50 'algorithm':77 'approxim':19,73 'cadenc':57 'construct':28 'current':47 'descent':17 'distanc':35 'fast':10 'flexibl':12 'graph':27,76 'implement':13 'input':39 'integr':41 'k':25 'k-neighbor-graph':24 'learn':45,70 'librari':6 'machin':69 'maintain':53 'matrix':38 'metric':36 'minor':60 'nearest':15,20,67,74 'neighbor':16,21,26,68,75 'patch':61 'provid':8 'pynndesc':1,2 'python':5 'regular':55 'releas':56 'scikit':44 'scikit-learn':43 'search':22,72 'sever':59 'similar':71 'spars':37 'support':30 'throughout':64 'updat':63 'varieti':33 'version':48 'wide':32 'year':66","created_at":"2026-04-09T18:48:49.948543+00:00","updated_at":"2026-04-16T18:34:57.443351+00:00","problems":[{"fix":"Ensure 'pynndescent' is installed and updated to a compatible version, usually by running `pip install --upgrade pynndescent umap-learn`. If directly importing, the correct path is typically `from pynndescent.pynndescent_ import NNDescent` though this is usually handled internally by dependent libraries.","cause":"This error often occurs when an older version of 'umap-learn' or other libraries attempts to import 'NNDescent' directly from the top-level 'pynndescent' package, or if 'pynndescent' is not installed or is an incompatible version.","error":"ImportError: cannot import name 'NNDescent' from 'pynndescent'"},{"fix":"Call the `.prepare()` method on the `NNDescent` object after initialization to build the search graph. If loading a pickled object, ensure the 'pynndescent' version used for loading matches the version used for saving.","cause":"This error indicates that the `neighbor_graph` attribute is being accessed before the approximate nearest neighbor graph has been constructed, or if a saved model from an incompatible 'pynndescent' version is being loaded.","error":"AttributeError: 'NNDescent' object has no attribute 'neighbor_graph'"},{"fix":"Check the official 'pynndescent' documentation for compatible Numba and Python versions. Update Numba (`pip install --upgrade numba`) or downgrade to a version explicitly supported by your 'pynndescent' and Python setup.","cause":"This Numba `TypingError` typically arises from incompatibilities between the installed Numba version and the Python version, or specific features used within 'pynndescent' that conflict with the Numba runtime. It can also stem from Numba-related issues when using certain distance metrics or large datasets.","error":"TypingError: Failed in nopython mode pipeline (step: nopython frontend)"},{"fix":"Review your input data for uniformity or very low variance dimensions. Try adjusting the `n_trees` or `leaf_size` parameters for the `NNDescent` constructor, or in some cases, setting `tree_init=False` if random projection tree initialization is not essential for your use case.","cause":"This error occurs during the initialization of random projection trees within 'pynndescent' (specifically in `rp_trees.py`) when the algorithm cannot construct hyperplanes with sufficient dimensions. This can happen with particular input data characteristics or when parameters related to tree construction (like `n_trees`) are unsuitable.","error":"ValueError: No hyperplanes of adequate size were found!"},{"fix":"Ensure 'pynndescent' is correctly installed using `pip install pynndescent` or `conda install -c conda-forge pynndescent`. Verify that your Python virtual environment (if used) is active and that your package cache is not corrupted.","cause":"This error means that Python's package manager cannot locate the 'pynndescent' distribution. This usually indicates an incomplete or incorrect installation of 'pynndescent', issues with the Python environment (e.g., virtual environment not activated), or a broken 'pkg_resources' mechanism.","error":"DistributionNotFound: The 'pynndescent' distribution was not found and is required by the application."}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.6.0","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"http://github.com/lmcinnes/pynndescent","docs":null,"changelog":null,"pypi":"https://pypi.org/project/pynndescent/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["ai-ml","data","vector-search"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-28","next_check":"2026-07-28","install_tag":null}}