All Neighbors

View as Markdown

Python module: cuvs.neighbors.all_neighbors

AllNeighborsParams

1cdef class AllNeighborsParams

Parameters for all-neighbors k-NN graph building.

Parameters

NameTypeDescription
algostr or cuvsAllNeighborsAlgoAlgorithm to use for local k-NN graph building. Options: “brute_force”, “ivf_pq”, “nn_descent”
overlap_factorint, default=2Number of clusters each point is assigned to (must be < n_clusters)
n_clustersint, default=1Number of clusters/batches to partition the dataset into (> overlap_factor). Use n_clusters>1 to distribute the work across GPUs.
metricstr or cuvsDistanceType, default="sqeuclidean"Distance metric to use for graph construction
ivf_pq_paramscuvs.neighbors.ivf_pq.IndexParams, optionalIVF-PQ specific parameters (used when algo=“ivf_pq”)
nn_descent_paramscuvs.neighbors.nn_descent.IndexParams, optionalNN-Descent specific parameters (used when algo=“nn_descent”)

Constructor

1def __init__(self, *, algo="nn_descent", overlap_factor=2, n_clusters=1, metric="sqeuclidean", ivf_pq_params=None, nn_descent_params=None)

Members

NameKind
get_handlemethod
algoproperty
overlap_factorproperty
n_clustersproperty
metricproperty

get_handle

1def get_handle(self)

Get a pointer to the underlying C object.

algo

1def algo(self)

Algorithm used for local k-NN graph building.

overlap_factor

1def overlap_factor(self)

Number of clusters each point is assigned to.

n_clusters

1def n_clusters(self)

Number of clusters/batches to partition the dataset into.

metric

1def metric(self)

Distance metric used for graph construction.

build

@auto_convert_output

1def build(dataset, k, params, *, indices=None, distances=None, core_distances=None, alpha=1.0, resources=None)

All-neighbors allows building an approximate all-neighbors knn graph. Given a full dataset, it finds nearest neighbors for all the training vectors in the dataset.

Parameters

NameTypeDescription
datasetarray_likeTraining dataset to build the k-NN graph for. Can be provided on host (for multi-GPU build) or device (for single-GPU build). Host vs device location is automatically detected. Supported dtype: float32
kintNumber of nearest neighbors to find for each point
paramsAllNeighborsParamsParameters object containing all build settings including algorithm choice and algorithm-specific parameters.
indicesarray_like, optionalOptional output buffer for indices [num_rows x k] on device (int64). If not provided, will be allocated automatically.
distancesarray_like, optionalOptional output buffer for distances [num_rows x k] on device (float32)
core_distancesarray_like, optionalOptional output buffer for core distances [num_rows] on device (float32). Requires distances parameter to be provided.
alphafloat, default=1.0Mutual-reachability scaling; used only when core_distances is provided
resourcesResources or MultiGpuResources, optionalCUDA resources to use for the operation. If not provided, a default Resources object will be created. Use MultiGpuResources to enable multi-GPU execution across multiple devices.

Returns

NameTypeDescription
indicesarray_likek-NN indices for each point [num_rows x k], always on device. If indices buffer was provided, returns the same array filled with results.
distancesarray_like or Nonek-NN distances if distances buffer was provided, None otherwise
core_distancesarray_like or NoneCore distances if core_distances buffer was provided, None otherwise