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.
pip install pynndescentVerified import paths — ran on the pinned version, not inferred.
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.
Remove the `n_search_trees` parameter from `NNDescent` initialization. The library will automatically choose an appropriate value.
Upgrade `pynndescent` to version `0.5.13` or newer, or ensure `numpy` version is compatible with your `pynndescent` installation.
Ensure your Python environment is running Python 3.8 or newer. Consider upgrading to Python 3.12 or 3.13 for full compatibility.
Upgrade `pynndescent` to version `0.5.9` or newer, which includes fixes for these issues.
Profile your application after upgrading to identify any performance regressions. Consider pre-calculating distances or optimizing custom distance functions if performance becomes an issue.
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.
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.
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.
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.
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.