Repository navigation
Description
Goals:
-
flexibility in creation
-
Neighbor querying API
-
Harmonize storage of backends’ querying indices
- use it in doublet detection and scanorama reimplementations
Current solution: method arg.
scanpy/scanpy/neighbors/__init__.py
Line 32 in ed8e140
| _Method = Literal['umap', 'gauss', 'rapids'] |
- if
use_dense_distances:sklearn.metrics.pairwise_distances - if
method == 'rapids':cuml.neighbors.NearestNeighbors - otherwise:
umap.umap_.nearest_neighbors - if
method == 'gauss': use umap distances, overwrite its connectivities
Evaluating options
See ann-benchmarks.com.
Build time vs query time is not straightforward, see erikbern/ann-benchmarks#207 (comment) and erikbern/ann-benchmarks#207 (comment)
If, however, you are simply interested in knn-graph construction then you can get that from pynndescent in less time than even the index construction time (since the prepare phase isn't required, but is a non-trivial part of the index construction time).
Plots for index building are on individual dataset pages, like glove-100-angular.
Used metrics
scanpy/scanpy/neighbors/__init__.py
Lines 35 to 56 in ed8e140
| _MetricSparseCapable = Literal[ | |
| 'cityblock', 'cosine', 'euclidean', 'l1', 'l2', 'manhattan' | |
| ] | |
| _MetricScipySpatial = Literal[ | |
| 'braycurtis', | |
| 'canberra', | |
| 'chebyshev', | |
| 'correlation', | |
| 'dice', | |
| 'hamming', | |
| 'jaccard', | |
| 'kulsinski', | |
| 'mahalanobis', | |
| 'minkowski', | |
| 'rogerstanimoto', | |
| 'russellrao', | |
| 'seuclidean', | |
| 'sokalmichener', | |
| 'sokalsneath', | |
| 'sqeuclidean', | |
| 'yule', | |
| ] |
Interesting:
| Name | Demo | wheels: Platforms | wheels: Python | Search speed | Index build |
|---|---|---|---|---|---|
| NMSLIB | 6 notebooks | Linux wheels | Outdated (3.9) | top | slow |
| ScaNN | notebook | All wheels | Slightly outdated (3.10) | very fast | middling |
| Faiss | wiki | –* | –* | middling to very fast | faiss-ivf: top |
*no official package on PyPI
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
[-]nearest neighbors (backend flexibility)[/-][+]Add new nearest neighbor backend[/+][-]Add new nearest neighbor backend[/-][+]Add approximate nearest neighbor backend[/+]adamgayoso commentedon Jun 22, 2023
faiss was reasonably easy to install via conda and has fairly easy to use gpu support which is nice
flying-sheep commentedon Jun 23, 2023
We’re thinking about making the backend configurable through something like https://github.com/frankier/sklearn-ann (that specific one doesn’t seem maintained though). A recipe for this is found here: https://scikit-learn.org/stable/auto_examples/neighbors/approximate_nearest_neighbors.html#sphx-glr-auto-examples-neighbors-approximate-nearest-neighbors-py
Faiss does seem nice as an option, but a hard dependency on something that isn’t on PyPI is out of the question.