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 <cuvs/neighbors/bruteforce.hpp>

namespace cuvs::neighbors::bruteforce

Index#

template<typename T>
struct index : public cuvs::neighbors::index#
#include <brute_force.hpp>

Brute Force index.

The index stores the dataset and norms for the dataset in device memory.

Template Parameters:

T – data element type

Public Functions

index(raft::resources const &res, raft::host_matrix_view<const T, int64_t, raft::row_major> dataset_view, std::optional<raft::device_vector<T, int64_t>> &&norms, cuvs::distance::DistanceType metric, T metric_arg = 0.0)#

Construct a brute force index from dataset

Constructs a brute force index from a dataset. This lets us precompute norms for the dataset, providing a speed benefit over doing this at query time. This index will store a non-owning reference to the dataset.

index(raft::resources const &res, raft::device_matrix_view<const T, int64_t, raft::row_major> dataset_view, std::optional<raft::device_vector<T, int64_t>> &&norms, cuvs::distance::DistanceType metric, T metric_arg = 0.0)#

Construct a brute force index from dataset

Constructs a brute force index from a dataset. This lets us precompute norms for the dataset, providing a speed benefit over doing this at query time. The dataset will be copied to the device and the index will own the device memory.

index(raft::resources const &res, raft::device_matrix_view<const T, int64_t, raft::row_major> dataset_view, std::optional<raft::device_vector_view<const T, int64_t>> norms_view, cuvs::distance::DistanceType metric, T metric_arg = 0.0)#

Construct a brute force index from dataset

This class stores a non-owning reference to the dataset and norms here. Having precomputed norms gives us a performance advantage at query time.

void update_dataset(raft::resources const &res, raft::device_matrix_view<const T, int64_t, raft::row_major> dataset)#

Replace the dataset with a new dataset.

void update_dataset(raft::resources const &res, raft::host_matrix_view<const T, int64_t, raft::row_major> dataset)#

Replace the dataset with a new dataset.

We create a copy of the dataset on the device. The index manages the lifetime of this copy.

inline cuvs::distance::DistanceType metric() const noexcept#

Distance metric used for retrieval

inline T metric_arg() const noexcept#

Metric argument

inline size_t size() const noexcept#

Total length of the index (number of vectors).

inline size_t dim() const noexcept#

Dimensionality of the data.

inline raft::device_matrix_view<const T, int64_t, raft::row_major> dataset() const noexcept#

Dataset [size, dim]

inline raft::device_vector_view<const T, int64_t, raft::row_major> norms() const#

Dataset norms

inline bool has_norms() const noexcept#

Whether ot not this index has dataset norms

Index build#

auto build(raft::resources const &handle, raft::device_matrix_view<const float, int64_t, raft::row_major> dataset, cuvs::distance::DistanceType metric = cuvs::distance::DistanceType::L2Unexpanded, float metric_arg = 0) -> cuvs::neighbors::brute_force::index<float>#

Build the index from the dataset for efficient search.

Usage example:

using namespace cuvs::neighbors;
// create and fill the index from a [N, D] dataset
auto index = brute_force::build(handle, dataset, metric);

Parameters:
  • handle[in]

  • dataset[in] a device pointer to a row-major matrix [n_rows, dim]

  • metric[in] cuvs::distance::DistanceType

  • metric_arg[in] metric argument

Returns:

the constructed ivf-flat index