Brute Force

View as Markdown

Source header: cuvs/neighbors/brute_force.h

Bruteforce index

cuvsBruteForceIndex

Struct to hold address of cuvs::neighbors::brute_force::index and its active trained dtype

1typedef struct { ... } cuvsBruteForceIndex;

Fields

NameTypeDescription
addruintptr_t
dtypeDLDataType

cuvsBruteForceIndexCreate

Allocate BRUTEFORCE index

1CUVS_EXPORT cuvsError_t cuvsBruteForceIndexCreate(cuvsBruteForceIndex_t* index);

Parameters

NameDirectionTypeDescription
indexincuvsBruteForceIndex_t*cuvsBruteForceIndex_t to allocate

Returns

CUVS_EXPORT cuvsError_t

cuvsBruteForceIndexDestroy

De-allocate BRUTEFORCE index

1CUVS_EXPORT cuvsError_t cuvsBruteForceIndexDestroy(cuvsBruteForceIndex_t index);

Parameters

NameDirectionTypeDescription
indexincuvsBruteForceIndex_tcuvsBruteForceIndex_t to de-allocate

Returns

CUVS_EXPORT cuvsError_t

Bruteforce index build

cuvsBruteForceBuild

Build a BRUTEFORCE index with a DLManagedTensor which has underlying

1CUVS_EXPORT cuvsError_t cuvsBruteForceBuild(cuvsResources_t res,
2DLManagedTensor* dataset,
3cuvsDistanceType metric,
4float metric_arg,
5cuvsBruteForceIndex_t index);

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

Parameters

NameDirectionTypeDescription
resincuvsResources_tcuvsResources_t opaque C handle
datasetinDLManagedTensor*DLManagedTensor* training dataset
metricincuvsDistanceTypemetric
metric_arginfloatmetric_arg
indexoutcuvsBruteForceIndex_tcuvsBruteForceIndex_t Newly built BRUTEFORCE index

Returns

CUVS_EXPORT cuvsError_t

cuvsBruteForceSearch

Search a BRUTEFORCE index with a DLManagedTensor which has underlying

1CUVS_EXPORT cuvsError_t cuvsBruteForceSearch(cuvsResources_t res,
2cuvsBruteForceIndex_t index,
3DLManagedTensor* queries,
4DLManagedTensor* neighbors,
5DLManagedTensor* distances,
6cuvsFilter prefilter);

DLDeviceType equal to kDLCUDA, kDLCUDAHost, kDLCUDAManaged. It is also important to note that the BRUTEFORCE index must have been built with the same type of queries, such that index.dtype.code == queries.dl_tensor.dtype.code Types for input are:

  1. queries: kDLDataType.code == kDLFloat and kDLDataType.bits = 32 or kDLDataType.bits = 16
  2. neighbors: kDLDataType.code == kDLUInt and kDLDataType.bits = 32
  3. distances: kDLDataType.code == kDLFloat and kDLDataType.bits = 32

Parameters

NameDirectionTypeDescription
resincuvsResources_tcuvsResources_t opaque C handle
indexincuvsBruteForceIndex_tcuvsBruteForceIndex which has been returned by cuvsBruteForceBuild
queriesinDLManagedTensor*DLManagedTensor* queries dataset to search
neighborsoutDLManagedTensor*DLManagedTensor* output k neighbors for queries
distancesoutDLManagedTensor*DLManagedTensor* output k distances for queries
prefilterincuvsFiltercuvsFilter input prefilter that can be used to filter queries and neighbors based on the given bitmap.

Returns

CUVS_EXPORT cuvsError_t

BRUTEFORCE C-API serialize functions

cuvsBruteForceSerialize

Save the index to file.

1CUVS_EXPORT cuvsError_t cuvsBruteForceSerialize(cuvsResources_t res,
2const char* filename,
3cuvsBruteForceIndex_t index);

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

Parameters

NameDirectionTypeDescription
resincuvsResources_tcuvsResources_t opaque C handle
filenameinconst char*the file name for saving the index
indexincuvsBruteForceIndex_tBRUTEFORCE index

Returns

CUVS_EXPORT cuvsError_t

cuvsBruteForceDeserialize

Load index from file.

1CUVS_EXPORT cuvsError_t cuvsBruteForceDeserialize(cuvsResources_t res,
2const char* filename,
3cuvsBruteForceIndex_t index);

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

Parameters

NameDirectionTypeDescription
resincuvsResources_tcuvsResources_t opaque C handle
filenameinconst char*the name of the file that stores the index
indexoutcuvsBruteForceIndex_tBRUTEFORCE index loaded disk

Returns

CUVS_EXPORT cuvsError_t