All Neighbors

View as Markdown

Source header: cuvs/neighbors/all_neighbors.h

All-neighbors C-API build parameters

cuvsAllNeighborsAlgo

Graph build algorithm selection.

1typedef enum {
2 CUVS_ALL_NEIGHBORS_ALGO_BRUTE_FORCE = 0,
3 CUVS_ALL_NEIGHBORS_ALGO_IVF_PQ = 1,
4 CUVS_ALL_NEIGHBORS_ALGO_NN_DESCENT = 2
5} cuvsAllNeighborsAlgo;

Values

NameValue
CUVS_ALL_NEIGHBORS_ALGO_BRUTE_FORCE0
CUVS_ALL_NEIGHBORS_ALGO_IVF_PQ1
CUVS_ALL_NEIGHBORS_ALGO_NN_DESCENT2

cuvsAllNeighborsIndexParams

Parameters controlling SNMG all-neighbors build.

1struct cuvsAllNeighborsIndexParams {
2 cuvsAllNeighborsAlgo algo;
3 size_t overlap_factor;
4 size_t n_clusters;
5 cuvsDistanceType metric;
6 cuvsIvfPqIndexParams_t ivf_pq_params;
7 cuvsNNDescentIndexParams_t nn_descent_params;
8};

Fields

NameTypeDescription
algocuvsAllNeighborsAlgo
overlap_factorsize_t
n_clusterssize_t
metriccuvsDistanceType
ivf_pq_paramscuvsIvfPqIndexParams_t
nn_descent_paramscuvsNNDescentIndexParams_t

cuvsAllNeighborsIndexParamsCreate

Create a default all-neighbors index parameters struct.

1cuvsError_t cuvsAllNeighborsIndexParamsCreate(cuvsAllNeighborsIndexParams_t* index_params);

Parameters

NameDirectionTypeDescription
index_paramsoutcuvsAllNeighborsIndexParams_t*Pointer to allocated index_params struct

Returns

cuvsError_t

cuvsAllNeighborsIndexParamsDestroy

Destroy an all-neighbors index parameters struct.

1cuvsError_t cuvsAllNeighborsIndexParamsDestroy(cuvsAllNeighborsIndexParams_t index_params);

Parameters

NameDirectionTypeDescription
index_paramsincuvsAllNeighborsIndexParams_tIndex parameters struct to destroy

Returns

cuvsError_t

All-neighbors C-API build

cuvsAllNeighborsBuild

Build an all-neighbors k-NN graph automatically detecting host vs device dataset.

1cuvsError_t cuvsAllNeighborsBuild(cuvsResources_t res,
2cuvsAllNeighborsIndexParams_t params,
3DLManagedTensor* dataset,
4DLManagedTensor* indices,
5DLManagedTensor* distances,
6DLManagedTensor* core_distances,
7float alpha);

The function automatically detects whether the dataset is host-resident or device-resident and calls the appropriate implementation. For host datasets, it partitions data into n_clusters clusters and assigns each row to overlap_factor nearest clusters. For device datasets, n_clusters must be 1 (no batching); overlap_factor is ignored. Outputs always reside in device memory.

Parameters

NameDirectionTypeDescription
resincuvsResources_tCan be a SNMG multi-GPU resources (cuvsResources_t) or single-GPU resources
paramsincuvsAllNeighborsIndexParams_tBuild parameters (see cuvsAllNeighborsIndexParams)
datasetinDLManagedTensor*2D tensor [num_rows x dim] on host or device (auto-detected)
indicesoutDLManagedTensor*2D tensor [num_rows x k] on device (int64)
distancesoutDLManagedTensor*Optional 2D tensor [num_rows x k] on device (float32); can be NULL
core_distancesoutDLManagedTensor*Optional 1D tensor [num_rows] on device (float32); can be NULL
alphainfloatMutual-reachability scaling; used only when core_distances is provided

Returns

cuvsError_t