HNSW#
This is a wrapper for hnswlib, to load a CAGRA index as an immutable HNSW index. The loaded HNSW index is only compatible in cuVS, and can be searched using wrapper functions.
#include <raft/neighbors/hnsw.h>
Index search parameters#
-
typedef struct cuvsHnswSearchParams *cuvsHnswSearchParams_t#
-
cuvsError_t cuvsHnswSearchParamsCreate(cuvsHnswSearchParams_t *params)#
Allocate HNSW search params, and populate with default values.
- Parameters:
params – [in] cuvsHnswSearchParams_t to allocate
- Returns:
cuvsError_t
-
cuvsError_t cuvsHnswSearchParamsDestroy(cuvsHnswSearchParams_t params)#
De-allocate HNSW search params.
- Parameters:
params – [in] cuvsHnswSearchParams_t to de-allocate
- Returns:
cuvsError_t
-
struct cuvsHnswSearchParams#
- #include <hnsw.h>
Index#
-
typedef cuvsHnswIndex *cuvsHnswIndex_t#
-
cuvsError_t cuvsHnswIndexCreate(cuvsHnswIndex_t *index)#
Allocate HNSW index.
- Parameters:
index – [in] cuvsHnswIndex_t to allocate
- Returns:
HnswError_t
-
cuvsError_t cuvsHnswIndexDestroy(cuvsHnswIndex_t index)#
De-allocate HNSW index.
- Parameters:
index – [in] cuvsHnswIndex_t to de-allocate
-
struct cuvsHnswIndex#
- #include <hnsw.h>
Struct to hold address of cuvs::neighbors::Hnsw::index and its active trained dtype.
Index search#
-
cuvsError_t cuvsCagraSearch(cuvsResources_t res, cuvsCagraSearchParams_t params, cuvsCagraIndex_t index, DLManagedTensor *queries, DLManagedTensor *neighbors, DLManagedTensor *distances)
Search a CAGRA index with a
DLManagedTensor
which has underlyingDLDeviceType
equal tokDLCUDA
,kDLCUDAHost
,kDLCUDAManaged
. It is also important to note that the CAGRA Index must have been built with the same type ofqueries
, such thatindex.dtype.code == queries.dl_tensor.dtype.code
Types for input are:queries
: a.kDLDataType.code == kDLFloat
andkDLDataType.bits = 32
b.kDLDataType.code == kDLInt
andkDLDataType.bits = 8
c.kDLDataType.code == kDLUInt
andkDLDataType.bits = 8
neighbors
:kDLDataType.code == kDLUInt
andkDLDataType.bits = 32
distances
:kDLDataType.code == kDLFloat
andkDLDataType.bits = 32
#include <cuvs/core/c_api.h> #include <cuvs/neighbors/cagra.h> // Create cuvsResources_t cuvsResources_t res; cuvsError_t res_create_status = cuvsResourcesCreate(&res); // Assume a populated `DLManagedTensor` type here DLManagedTensor dataset; DLManagedTensor queries; DLManagedTensor neighbors; // Create default search params cuvsCagraSearchParams_t params; cuvsError_t params_create_status = cuvsCagraSearchParamsCreate(¶ms); // Search the `index` built using `cuvsCagraBuild` cuvsError_t search_status = cuvsCagraSearch(res, params, index, &queries, &neighbors, &distances); // de-allocate `params` and `res` cuvsError_t params_destroy_status = cuvsCagraSearchParamsDestroy(params); cuvsError_t res_destroy_status = cuvsResourcesDestroy(res);
- Parameters:
res – [in] cuvsResources_t opaque C handle
params – [in] cuvsCagraSearchParams_t used to search CAGRA index
index – [in] cuvsCagraIndex which has been returned by
cuvsCagraBuild
queries – [in] DLManagedTensor* queries dataset to search
neighbors – [out] DLManagedTensor* output
k
neighbors for queriesdistances – [out] DLManagedTensor* output
k
distances for queries
Index serialize#
Warning
doxygengroup: Cannot find group “hnsw_c_index_serialize” in doxygen xml output for project “cuvs” from directory: ../../cpp/doxygen/_xml/