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 underlying DLDeviceType equal to kDLCUDA, kDLCUDAHost, kDLCUDAManaged, or kDLCPU. Also, acceptable underlying types are:

  1. kDLDataType.code == kDLFloat and kDLDataType.bits = 32

  2. kDLDataType.code == kDLFloat and kDLDataType.bits = 16

#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 serialize#

cuvsError_t cuvsBruteForceSerialize(
cuvsResources_t res,
const char *filename,
cuvsBruteForceIndex_t index
)#

Save the index to file. The serialization format can be subject to changes, therefore loading an index saved with a previous version of cuvs is not guaranteed to work.

#include <cuvs/neighbors/brute_force.h>

// Create cuvsResources_t
cuvsResources_t res;
cuvsError_t res_create_status = cuvsResourcesCreate(&res);

// create an index with `cuvsBruteforceBuild`
cuvsBruteForceSerialize(res, "/path/to/index", index);
Parameters:
  • res[in] cuvsResources_t opaque C handle

  • filename[in] the file name for saving the index

  • index[in] BRUTEFORCE index

cuvsError_t cuvsBruteForceDeserialize(
cuvsResources_t res,
const char *filename,
cuvsBruteForceIndex_t index
)#

Load index from file. The serialization format can be subject to changes, therefore loading an index saved with a previous version of cuvs is not guaranteed to work.

#include <cuvs/neighbors/brute_force.h>

// Create cuvsResources_t
cuvsResources_t res;
cuvsError_t res_create_status = cuvsResourcesCreate(&res);

// Deserialize an index previously built with `cuvsBruteforceBuild`
cuvsBruteForceIndex_t index;
cuvsBruteForceIndexCreate(&index);
cuvsBruteForceDeserialize(res, "/path/to/index", index);
Parameters:
  • res[in] cuvsResources_t opaque C handle

  • filename[in] the name of the file that stores the index

  • index[out] BRUTEFORCE index loaded disk