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 { ... } 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 { ... };

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.

1CUVS_EXPORT cuvsError_t cuvsAllNeighborsIndexParamsCreate(cuvsAllNeighborsIndexParams_t* index_params);

Parameters

NameDirectionTypeDescription
index_paramsoutcuvsAllNeighborsIndexParams_t*Pointer to allocated index_params struct

Returns

CUVS_EXPORT cuvsError_t

cuvsAllNeighborsIndexParamsDestroy

Destroy an all-neighbors index parameters struct.

1CUVS_EXPORT cuvsError_t cuvsAllNeighborsIndexParamsDestroy(cuvsAllNeighborsIndexParams_t index_params);

Parameters

NameDirectionTypeDescription
index_paramsincuvsAllNeighborsIndexParams_tIndex parameters struct to destroy

Returns

CUVS_EXPORT cuvsError_t

All-neighbors C-API build

cuvsAllNeighborsBuild

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

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

resources 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
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

CUVS_EXPORT cuvsError_t