Bruteforce#
The bruteforce method is running the KNN algorithm. It performs an extensive search, and in contrast to ANN methods produces an exact result.
#include <raft/neighbors/bruteforce.h>
Index#
-
typedef cuvsBruteForceIndex *cuvsBruteForceIndex_t#
-
cuvsError_t cuvsBruteForceIndexCreate(cuvsBruteForceIndex_t *index)#
Allocate BRUTEFORCE index.
- Parameters:
index – [in] cuvsBruteForceIndex_t to allocate
- Returns:
cuvsError_t
-
cuvsError_t cuvsBruteForceIndexDestroy(cuvsBruteForceIndex_t index)#
De-allocate BRUTEFORCE index.
- Parameters:
index – [in] cuvsBruteForceIndex_t to de-allocate
-
struct cuvsBruteForceIndex#
- #include <brute_force.h>
Struct to hold address of cuvs::neighbors::brute_force::index and its active trained dtype.
Index build#
-
cuvsError_t cuvsBruteForceBuild(cuvsResources_t res, DLManagedTensor *dataset, cuvsDistanceType metric, float metric_arg, cuvsBruteForceIndex_t index)#
Build a BRUTEFORCE index with a
DLManagedTensor
which has underlyingDLDeviceType
equal tokDLCUDA
,kDLCUDAHost
,kDLCUDAManaged
, orkDLCPU
. Also, acceptable underlying types are:kDLDataType.code == kDLFloat
andkDLDataType.bits = 32
kDLDataType.code == kDLInt
andkDLDataType.bits = 8
kDLDataType.code == kDLUInt
andkDLDataType.bits = 8
#include <cuvs/core/c_api.h> #include <cuvs/neighbors/brute_force.h> // Create cuvsResources_t cuvsResources_t res; cuvsError_t res_create_status = cuvsResourcesCreate(&res); // Assume a populated `DLManagedTensor` type here DLManagedTensor dataset; // Create BRUTEFORCE index cuvsBruteForceIndex_t index; cuvsError_t index_create_status = cuvsBruteForceIndexCreate(&index); // Build the BRUTEFORCE Index cuvsError_t build_status = cuvsBruteForceBuild(res, &dataset_tensor, L2Expanded, 0.f, index); // de-allocate `index` and `res` cuvsError_t index_destroy_status = cuvsBruteForceIndexDestroy(index); cuvsError_t res_destroy_status = cuvsResourcesDestroy(res);
- Parameters:
res – [in] cuvsResources_t opaque C handle
dataset – [in] DLManagedTensor* training dataset
metric – [in] metric
metric_arg – [in] metric_arg
index – [out] cuvsBruteForceIndex_t Newly built BRUTEFORCE index
- Returns:
cuvsError_t
Index search#
-
cuvsError_t cuvsBruteForceSearch(cuvsResources_t res, cuvsBruteForceIndex_t index, DLManagedTensor *queries, DLManagedTensor *neighbors, DLManagedTensor *distances, cuvsFilter prefilter)#
Search a BRUTEFORCE index with a
DLManagedTensor
which has underlyingDLDeviceType
equal tokDLCUDA
,kDLCUDAHost
,kDLCUDAManaged
. It is also important to note that the BRUTEFORCE index must have been built with the same type ofqueries
, such thatindex.dtype.code == queries.dl_tensor.dtype.code
Types for input are:queries
:kDLDataType.code == kDLFloat
andkDLDataType.bits = 32
neighbors
:kDLDataType.code == kDLUInt
andkDLDataType.bits = 32
distances
:kDLDataType.code == kDLFloat
andkDLDataType.bits = 32
#include <cuvs/core/c_api.h> #include <cuvs/neighbors/brute_force.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; DLManagedTensor bitmap; cuvsFilter prefilter{(uintptr_t)&bitmap, BITMAP}; // Search the `index` built using `cuvsBruteForceBuild` cuvsError_t search_status = cuvsBruteForceSearch(res, index, &queries, &neighbors, &distances, prefilter); // de-allocate `res` cuvsError_t res_destroy_status = cuvsResourcesDestroy(res);
- Parameters:
res – [in] cuvsResources_t opaque C handle
index – [in] cuvsBruteForceIndex which has been returned by
cuvsBruteForceBuild
queries – [in] DLManagedTensor* queries dataset to search
neighbors – [out] DLManagedTensor* output
k
neighbors for queriesdistances – [out] DLManagedTensor* output
k
distances for queriesprefilter – [in] cuvsFilter input prefilter that can be used to filter queries and neighbors based on the given bitmap.
Index serialize#
Warning
doxygengroup: Cannot find group “bruteforce_c_index_serialize” in doxygen xml output for project “cuvs” from directory: ../../cpp/doxygen/_xml/