NN Descent

View as Markdown

Python module: cuvs.neighbors.nn_descent

Index

1cdef class Index

NN-Descent index object. This object stores the trained NN-Descent index, which can be used to get the NN-Descent graph and distances after building

Members

NameKind
trainedproperty
graphproperty
distancesproperty

trained

1def trained(self)

graph

1def graph(self)

distances

1def distances(self)

IndexParams

1cdef class IndexParams

Parameters to build NN-Descent Index

Parameters

NameTypeDescription
metricstr, default = "sqeuclidean"String denoting the metric type. Supported metrics are l2, euclidean, sqeuclidean, inner_product, cosine, and bitwise_hamming (bitwise_hamming is for int8 and uint8 data types only)
graph_degreeintFor an input dataset of dimensions (N, D), determines the final dimensions of the all-neighbors knn graph which turns out to be of dimensions (N, graph_degree)
intermediate_graph_degreeintInternally, nn-descent builds an all-neighbors knn graph of dimensions (N, intermediate_graph_degree) before selecting the final graph_degree neighbors. It’s recommended that intermediate_graph_degree >= 1.5 * graph_degree
max_iterationsintThe number of iterations that nn-descent will refine the graph for. More iterations produce a better quality graph at cost of performance
termination_thresholdfloatThe delta at which nn-descent will terminate its iterations
return_distancesboolWhether to return distances array
dist_comp_dtypestr, default = "auto"Dtype to use for distance computation. Supported dtypes are auto, fp32, and fp16 auto automatically determines the best dtype for distance computation based on the dataset dimensions. fp32 uses fp32 distance computation for better precision at the cost of performance and memory usage. This option is only valid when data type is fp32. fp16 uses fp16 distance computation for better performance and memory usage at the cost of precision.

Constructor

1def __init__(self, *, metric=None, metric_arg=None, graph_degree=None, intermediate_graph_degree=None, max_iterations=None, termination_threshold=None, return_distances=None, dist_comp_dtype="auto" )

Members

NameKind
metricproperty
metric_argproperty
graph_degreeproperty
intermediate_graph_degreeproperty
max_iterationsproperty
termination_thresholdproperty
get_handlemethod

metric

1def metric(self)

metric_arg

1def metric_arg(self)

graph_degree

1def graph_degree(self)

intermediate_graph_degree

1def intermediate_graph_degree(self)

max_iterations

1def max_iterations(self)

termination_threshold

1def termination_threshold(self)

get_handle

1def get_handle(self)

Get a pointer to the underlying C object.

build

@auto_sync_resources

1def build(IndexParams index_params, dataset, graph=None, resources=None)

Build KNN graph from the dataset

Parameters

NameTypeDescription
index_paramscuvs.neighbors.nn_descent.IndexParams
datasetArray interface compliant matrix, on either host or device memorySupported dtype [float, int8, uint8]
graphOptional host matrix for storing output graph
resourcescuvs.common.Resources, optional

Returns

NameTypeDescription
indexcuvs.neighbors.nn_descent.Index

Examples

1>>> import cupy as cp
2>>> from cuvs.neighbors import nn_descent
3>>> n_samples = 50000
4>>> n_features = 50
5>>> n_queries = 1000
6>>> k = 10
7>>> dataset = cp.random.random_sample((n_samples, n_features),
8... dtype=cp.float32)
9>>> build_params = nn_descent.IndexParams(metric="sqeuclidean")
10>>> index = nn_descent.build(build_params, dataset)
11>>> graph = index.graph