Bruteforce#
2026-09-27
22 min read time
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/brute_force.hpp>
Dense indices support half inputs with float distances, float inputs
with float distances, and double inputs with double distances.
Double indices retain FP64 precision in norms, distance arithmetic, selection,
and serialization. Dataset and query types must match; neighbor IDs are
int64_t. Sparse CSR indices also support double values and distances,
with int CSR indices and neighbor IDs.
Dense builds accept host row-major data or device row-major/column-major data. Queries may use either device layout. Bitmap and bitset filtering requires row-major queries and supports expanded L2 (squared or square root), inner product, and cosine. These restrictions are the same for all supported types.
The dense index_params.metric_arg and sparse build metric argument remain
float; their values are promoted for double distance arithmetic. FP64 does
not require a particular AMD GPU architecture, although its throughput varies
by device. FP64 support here is limited to the C++ API; C and Python bindings
do not yet accept double inputs.
namespace cuvs::neighbors::bruteforce
Index#
-
template<typename T, typename DistT = 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
DistT – distance and norm type. Supported combinations are half/float, float/float, and double/double.
Public Functions
- index(
- raft::resources const &handle
Construct an empty index.
Constructs an empty index. This index will either need to be trained with
buildor loaded from a saved copy withdeserialize
- index(
- raft::resources const &res,
- raft::host_matrix_view<const T, int64_t, raft::row_major> dataset_view,
- std::optional<raft::device_vector<DistT, int64_t>> &&norms,
- cuvs::distance::DistanceType metric,
- DistT 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 copy the host dataset onto the device, and take ownership of any precaculated norms.
- index(
- raft::resources const &res,
- raft::device_matrix_view<const T, int64_t, raft::row_major> dataset_view,
- std::optional<raft::device_vector<DistT, int64_t>> &&norms,
- cuvs::distance::DistanceType metric,
- DistT 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, but will move any norms supplied.
- 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 DistT, int64_t>> norms_view,
- cuvs::distance::DistanceType metric,
- DistT metric_arg = 0.0
Construct a brute force index from dataset
This class stores a non-owning reference to the dataset and norms. Having precomputed norms gives us a performance advantage at query time.
- index(
- raft::resources const &res,
- raft::device_matrix_view<const T, int64_t, raft::col_major> dataset_view,
- std::optional<raft::device_vector<DistT, int64_t>> &&norms,
- cuvs::distance::DistanceType metric,
- DistT 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, but will move any norms supplied.
- index(
- raft::resources const &res,
- raft::device_matrix_view<const T, int64_t, raft::col_major> dataset_view,
- std::optional<raft::device_vector_view<const DistT, int64_t>> norms_view,
- cuvs::distance::DistanceType metric,
- DistT metric_arg = 0.0
Construct a brute force index from dataset
This class stores a non-owning reference to the dataset and norms, with the dataset being supplied on device in a col_major format
- 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(
Distance metric used for retrieval
- inline size_t size(
Total length of the index (number of vectors).
- inline size_t dim(
Dimensionality of the data.
- inline raft::device_matrix_view<const T, int64_t, raft::row_major> dataset(
Dataset [size, dim]
- inline raft::device_vector_view<const DistT, int64_t, raft::row_major> norms(
Dataset norms
- inline bool has_norms(
Whether ot not this index has dataset norms
Index build#
- auto build(
- raft::resources const &handle,
- const cuvs::neighbors::brute_force::index_params &index_params,
- raft::device_matrix_view<const float, int64_t, raft::row_major> dataset
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 brute_force::index_params index_params; auto index = brute_force::build(handle, index_params, dataset);
- Parameters:
handle – [in]
index_params – parameters such as the distance metric to use
dataset – [in] a device pointer to a row-major matrix [n_rows, dim]
- Returns:
the constructed brute-force index
- auto build(
- raft::resources const &handle,
- const cuvs::neighbors::brute_force::index_params &index_params,
- raft::device_matrix_view<const double, int64_t, raft::row_major> dataset
- auto build(
- raft::resources const &handle,
- const cuvs::neighbors::brute_force::index_params &index_params,
- raft::host_matrix_view<const float, int64_t, raft::row_major> dataset
Build the index from the dataset for efficient search.
- Parameters:
handle – [in]
index_params – parameters such as the distance metric to use
dataset – [in] a host pointer to a row-major matrix [n_rows, dim]
- Returns:
the constructed brute-force index
- auto build(
- raft::resources const &handle,
- const cuvs::neighbors::brute_force::index_params &index_params,
- raft::host_matrix_view<const double, int64_t, raft::row_major> dataset
- 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
- auto build(
- raft::resources const &handle,
- raft::device_matrix_view<const double, int64_t, raft::row_major> dataset,
- cuvs::distance::DistanceType metric = cuvs::distance::DistanceType::L2Unexpanded,
- double metric_arg = 0
- auto build(
- raft::resources const &handle,
- const cuvs::neighbors::brute_force::index_params &index_params,
- raft::device_matrix_view<const half, int64_t, raft::row_major> dataset
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 brute_force::index_params index_params; auto index = brute_force::build(handle, index_params, dataset);
- Parameters:
handle – [in]
index_params – parameters such as the distance metric to use
dataset – [in] a device pointer to a row-major matrix [n_rows, dim]
- Returns:
the constructed brute force index
- auto build(
- raft::resources const &handle,
- const cuvs::neighbors::brute_force::index_params &index_params,
- raft::host_matrix_view<const half, int64_t, raft::row_major> dataset
Build the index from the dataset for efficient search.
- Parameters:
handle – [in]
index_params – parameters such as the distance metric to use
dataset – [in] a host pointer to a row-major matrix [n_rows, dim]
- Returns:
the constructed brute-force index
- auto build(
- raft::resources const &handle,
- raft::device_matrix_view<const half, int64_t, raft::row_major> dataset,
- cuvs::distance::DistanceType metric = cuvs::distance::DistanceType::L2Unexpanded,
- float metric_arg = 0
- auto build(
- raft::resources const &handle,
- const cuvs::neighbors::brute_force::index_params &index_params,
- raft::device_matrix_view<const float, int64_t, raft::col_major> dataset
Build the index from the dataset for efficient search.
Usage example:
brute_force::index_params index_params; auto index = brute_force::build(handle, index_params, dataset);
- Parameters:
handle – [in]
index_params – parameters such as the distance metric to use
dataset – [in] a device pointer to a col-major matrix [n_rows, dim]
- Returns:
the constructed brute force index
- auto build(
- raft::resources const &handle,
- const cuvs::neighbors::brute_force::index_params &index_params,
- raft::device_matrix_view<const double, int64_t, raft::col_major> dataset
- auto build(
- raft::resources const &handle,
- raft::device_matrix_view<const float, int64_t, raft::col_major> dataset,
- cuvs::distance::DistanceType metric = cuvs::distance::DistanceType::L2Unexpanded,
- float metric_arg = 0
- auto build(
- raft::resources const &handle,
- raft::device_matrix_view<const double, int64_t, raft::col_major> dataset,
- cuvs::distance::DistanceType metric = cuvs::distance::DistanceType::L2Unexpanded,
- double metric_arg = 0
- auto build(
- raft::resources const &handle,
- const cuvs::neighbors::brute_force::index_params &index_params,
- raft::device_matrix_view<const half, int64_t, raft::col_major> dataset
Build the index from the dataset for efficient search.
Usage example:
brute_force::index_params index_params; auto index = brute_force::build(handle, index_params, dataset);
- Parameters:
handle – [in]
index_params – parameters such as the distance metric to use
dataset – [in] a device pointer to a col-major matrix [n_rows, dim]
- Returns:
the constructed brute force index
Index search#
- void search(
- raft::resources const &handle,
- const cuvs::neighbors::brute_force::search_params ¶ms,
- const cuvs::neighbors::brute_force::index<float, float> &index,
- raft::device_matrix_view<const float, int64_t, raft::row_major> queries,
- raft::device_matrix_view<int64_t, int64_t, raft::row_major> neighbors,
- raft::device_matrix_view<float, int64_t, raft::row_major> distances,
- const cuvs::neighbors::filtering::base_filter &sample_filter = cuvs::neighbors::filtering::none_sample_filter{}
Search ANN using the constructed index.
See the brute_force::build documentation for a usage example.
Note, this function requires a temporary buffer to store intermediate results between cuda kernel calls, which may lead to undesirable allocations and slowdown. To alleviate the problem, you can pass a pool memory resource or a large enough pre-allocated memory resource to reduce or eliminate entirely allocations happening within
search.Usage example:
using namespace cuvs::neighbors; // use default index parameters brute_force::index_params index_params; // create and fill the index from a [N, D] dataset brute_force::index_params index_params; auto index = brute_force::build(handle, index_params, dataset); // use default search parameters brute_force::search_params search_params; // create a bitset to filter the search auto removed_indices = raft::make_device_vector<int64_t, int64_t>(res, n_removed_indices); raft::core::bitset<std::uint32_t, int64_t> removed_indices_bitset( res, removed_indices.view(), dataset.extent(0)); // search K nearest neighbours according to a bitset auto neighbors = raft::make_device_matrix<uint32_t>(res, n_queries, k); auto distances = raft::make_device_matrix<float>(res, n_queries, k); auto filter = filtering::bitset_filter(removed_indices_bitset.view()); brute_force::search(res, search_params, index, queries, neighbors, distances, filter);
Supports two types of filters:
Bitset Filter: A shared filter where each bit corresponds to a dataset element. All queries share the same filter, with a logical shape of
[1, index->size()].Bitmap Filter: A per-query filter with a logical shape of
[n_queries, index->size()], where each bit indicates whether a specific dataset element should be considered for a particular query. (1 for inclusion, 0 for exclusion).
The default value is
none_sample_filter, which applies no filtering.
- Parameters:
handle – [in]
params – [in] parameters configuring the search
index – [in] brute-force constructed index
queries – [in] a device pointer to a row-major matrix [n_queries, index->dim()]
neighbors – [out] a device pointer to the indices of the neighbors in the source dataset [n_queries, k]
distances – [out] a device pointer to the distances to the selected neighbors [n_queries, k]
sample_filter – [in] An optional device filter that restricts which dataset elements should be considered for each query.
- void search(
- raft::resources const &handle,
- const cuvs::neighbors::brute_force::search_params ¶ms,
- const cuvs::neighbors::brute_force::index<double, double> &index,
- raft::device_matrix_view<const double, int64_t, raft::row_major> queries,
- raft::device_matrix_view<int64_t, int64_t, raft::row_major> neighbors,
- raft::device_matrix_view<double, int64_t, raft::row_major> distances,
- const cuvs::neighbors::filtering::base_filter &sample_filter = cuvs::neighbors::filtering::none_sample_filter{}
- void search(
- raft::resources const &handle,
- const cuvs::neighbors::brute_force::index<float, float> &index,
- raft::device_matrix_view<const float, int64_t, raft::row_major> queries,
- raft::device_matrix_view<int64_t, int64_t, raft::row_major> neighbors,
- raft::device_matrix_view<float, int64_t, raft::row_major> distances,
- const cuvs::neighbors::filtering::base_filter &sample_filter = cuvs::neighbors::filtering::none_sample_filter{}
- void search(
- raft::resources const &handle,
- const cuvs::neighbors::brute_force::index<double, double> &index,
- raft::device_matrix_view<const double, int64_t, raft::row_major> queries,
- raft::device_matrix_view<int64_t, int64_t, raft::row_major> neighbors,
- raft::device_matrix_view<double, int64_t, raft::row_major> distances,
- const cuvs::neighbors::filtering::base_filter &sample_filter = cuvs::neighbors::filtering::none_sample_filter{}
- void search(
- raft::resources const &handle,
- const cuvs::neighbors::brute_force::search_params ¶ms,
- const cuvs::neighbors::brute_force::index<half, float> &index,
- raft::device_matrix_view<const half, int64_t, raft::row_major> queries,
- raft::device_matrix_view<int64_t, int64_t, raft::row_major> neighbors,
- raft::device_matrix_view<float, int64_t, raft::row_major> distances,
- const cuvs::neighbors::filtering::base_filter &sample_filter = cuvs::neighbors::filtering::none_sample_filter{}
Search ANN using the constructed index.
See the brute_force::build documentation for a usage example.
Note, this function requires a temporary buffer to store intermediate results between cuda kernel calls, which may lead to undesirable allocations and slowdown. To alleviate the problem, you can pass a pool memory resource or a large enough pre-allocated memory resource to reduce or eliminate entirely allocations happening within
search.Usage example:
using namespace cuvs::neighbors; // use default index parameters brute_force::index_params index_params; // create and fill the index from a [N, D] dataset brute_force::index_params index_params; auto index = brute_force::build(handle, index_params, dataset); // use default search parameters brute_force::search_params search_params; // create a bitset to filter the search auto removed_indices = raft::make_device_vector<int64_t, int64_t>(res, n_removed_indices); raft::core::bitset<std::uint32_t, int64_t> removed_indices_bitset( res, removed_indices.view(), dataset.extent(0)); // search K nearest neighbours according to a bitset auto neighbors = raft::make_device_matrix<uint32_t>(res, n_queries, k); auto distances = raft::make_device_matrix<half>(res, n_queries, k); auto filter = filtering::bitset_filter(removed_indices_bitset.view()); brute_force::search(res, search_params, index, queries, neighbors, distances, filter);
Supports two types of filters:
Bitset Filter: A shared filter where each bit corresponds to a dataset element. All queries share the same filter, with a logical shape of
[1, index->size()].Bitmap Filter: A per-query filter with a logical shape of
[n_queries, index->size()], where each bit indicates whether a specific dataset element should be considered for a particular query. (1 for inclusion, 0 for exclusion).
The default value is
none_sample_filter, which applies no filtering.
- Parameters:
handle – [in]
params – [in] parameters configuring the search
index – [in] ivf-flat constructed index
queries – [in] a device pointer to a row-major matrix [n_queries, index->dim()]
neighbors – [out] a device pointer to the indices of the neighbors in the source dataset [n_queries, k]
distances – [out] a device pointer to the distances to the selected neighbors [n_queries, k]
sample_filter – [in] An optional device filter that restricts which dataset elements should be considered for each query.
- void search(
- raft::resources const &handle,
- const cuvs::neighbors::brute_force::index<half, float> &index,
- raft::device_matrix_view<const half, int64_t, raft::row_major> queries,
- raft::device_matrix_view<int64_t, int64_t, raft::row_major> neighbors,
- raft::device_matrix_view<float, int64_t, raft::row_major> distances,
- const cuvs::neighbors::filtering::base_filter &sample_filter = cuvs::neighbors::filtering::none_sample_filter{}
- void search(
- raft::resources const &handle,
- const cuvs::neighbors::brute_force::search_params ¶ms,
- const cuvs::neighbors::brute_force::index<float, float> &index,
- raft::device_matrix_view<const float, int64_t, raft::col_major> queries,
- raft::device_matrix_view<int64_t, int64_t, raft::row_major> neighbors,
- raft::device_matrix_view<float, int64_t, raft::row_major> distances,
- const cuvs::neighbors::filtering::base_filter &sample_filter = cuvs::neighbors::filtering::none_sample_filter{}
Search ANN using the constructed index.
See the brute_force::build documentation for a usage example.
Note, this function requires a temporary buffer to store intermediate results between cuda kernel calls, which may lead to undesirable allocations and slowdown. To alleviate the problem, you can pass a pool memory resource or a large enough pre-allocated memory resource to reduce or eliminate entirely allocations happening within
search.Usage example:
using namespace cuvs::neighbors; // use default index parameters brute_force::index_params index_params; // create and fill the index from a [N, D] dataset brute_force::index_params index_params; auto index = brute_force::build(handle, index_params, dataset); // use default search parameters brute_force::search_params search_params; // create a bitset to filter the search auto removed_indices = raft::make_device_vector<int64_t, int64_t>(res, n_removed_indices); raft::core::bitset<std::uint32_t, int64_t> removed_indices_bitset( res, removed_indices.view(), dataset.extent(0)); // search K nearest neighbours according to a bitset auto neighbors = raft::make_device_matrix<uint32_t>(res, n_queries, k); auto distances = raft::make_device_matrix<float>(res, n_queries, k); auto filter = filtering::bitset_filter(removed_indices_bitset.view()); brute_force::search(res, search_params, index, queries, neighbors, distances, filter);
Supports two types of filters:
Bitset Filter: A shared filter where each bit corresponds to a dataset element. All queries share the same filter, with a logical shape of
[1, index->size()].Bitmap Filter: A per-query filter with a logical shape of
[n_queries, index->size()], where each bit indicates whether a specific dataset element should be considered for a particular query. (1 for inclusion, 0 for exclusion).
The default value is
none_sample_filter, which applies no filtering.
- Parameters:
handle – [in]
params – [in] parameters configuring the search
index – [in] bruteforce constructed index
queries – [in] a device pointer to a col-major matrix [n_queries, index->dim()]
neighbors – [out] a device pointer to the indices of the neighbors in the source dataset [n_queries, k]
distances – [out] a device pointer to the distances to the selected neighbors [n_queries, k]
sample_filter – [in] An optional device filter that restricts which dataset elements should be considered for each query.
- void search(
- raft::resources const &handle,
- const cuvs::neighbors::brute_force::search_params ¶ms,
- const cuvs::neighbors::brute_force::index<double, double> &index,
- raft::device_matrix_view<const double, int64_t, raft::col_major> queries,
- raft::device_matrix_view<int64_t, int64_t, raft::row_major> neighbors,
- raft::device_matrix_view<double, int64_t, raft::row_major> distances,
- const cuvs::neighbors::filtering::base_filter &sample_filter = cuvs::neighbors::filtering::none_sample_filter{}
- void search(
- raft::resources const &handle,
- const cuvs::neighbors::brute_force::index<float, float> &index,
- raft::device_matrix_view<const float, int64_t, raft::col_major> queries,
- raft::device_matrix_view<int64_t, int64_t, raft::row_major> neighbors,
- raft::device_matrix_view<float, int64_t, raft::row_major> distances,
- const cuvs::neighbors::filtering::base_filter &sample_filter = cuvs::neighbors::filtering::none_sample_filter{}
- void search(
- raft::resources const &handle,
- const cuvs::neighbors::brute_force::index<double, double> &index,
- raft::device_matrix_view<const double, int64_t, raft::col_major> queries,
- raft::device_matrix_view<int64_t, int64_t, raft::row_major> neighbors,
- raft::device_matrix_view<double, int64_t, raft::row_major> distances,
- const cuvs::neighbors::filtering::base_filter &sample_filter = cuvs::neighbors::filtering::none_sample_filter{}
- void search(
- raft::resources const &handle,
- const cuvs::neighbors::brute_force::search_params ¶ms,
- const cuvs::neighbors::brute_force::index<half, float> &index,
- raft::device_matrix_view<const half, int64_t, raft::col_major> queries,
- raft::device_matrix_view<int64_t, int64_t, raft::row_major> neighbors,
- raft::device_matrix_view<float, int64_t, raft::row_major> distances,
- const cuvs::neighbors::filtering::base_filter &sample_filter = cuvs::neighbors::filtering::none_sample_filter{}
Search ANN using the constructed index.
See the brute_force::build documentation for a usage example.
Note, this function requires a temporary buffer to store intermediate results between cuda kernel calls, which may lead to undesirable allocations and slowdown. To alleviate the problem, you can pass a pool memory resource or a large enough pre-allocated memory resource to reduce or eliminate entirely allocations happening within
search.Usage example:
using namespace cuvs::neighbors; // use default index parameters brute_force::index_params index_params; // create and fill the index from a [N, D] dataset brute_force::index_params index_params; auto index = brute_force::build(handle, index_params, dataset); // use default search parameters brute_force::search_params search_params; // create a bitset to filter the search auto removed_indices = raft::make_device_vector<int64_t, int64_t>(res, n_removed_indices); raft::core::bitset<std::uint32_t, int64_t> removed_indices_bitset( res, removed_indices.view(), dataset.extent(0)); // search K nearest neighbours according to a bitset auto neighbors = raft::make_device_matrix<uint32_t>(res, n_queries, k); auto distances = raft::make_device_matrix<half>(res, n_queries, k); auto filter = filtering::bitset_filter(removed_indices_bitset.view()); brute_force::search(res, search_params, index, queries, neighbors, distances, filter);
Supports two types of filters:
Bitset Filter: A shared filter where each bit corresponds to a dataset element. All queries share the same filter, with a logical shape of
[1, index->size()].Bitmap Filter: A per-query filter with a logical shape of
[n_queries, index->size()], where each bit indicates whether a specific dataset element should be considered for a particular query. (1 for inclusion, 0 for exclusion).
The default value is
none_sample_filter, which applies no filtering.
- Parameters:
handle – [in]
params – [in] parameters configuring the search
index – [in] bruteforce constructed index
queries – [in] a device pointer to a col-major matrix [n_queries, index->dim()]
neighbors – [out] a device pointer to the indices of the neighbors in the source dataset [n_queries, k]
distances – [out] a device pointer to the distances to the selected neighbors [n_queries, k]
sample_filter – [in] An optional device filter that restricts which dataset elements should be considered for each query.
- void search(
- raft::resources const &handle,
- const cuvs::neighbors::brute_force::index<half, float> &index,
- raft::device_matrix_view<const half, int64_t, raft::col_major> queries,
- raft::device_matrix_view<int64_t, int64_t, raft::row_major> neighbors,
- raft::device_matrix_view<float, int64_t, raft::row_major> distances,
- const cuvs::neighbors::filtering::base_filter &sample_filter = cuvs::neighbors::filtering::none_sample_filter{}
Index serialize#
- void serialize(
- raft::resources const &handle,
- const std::string &filename,
- const cuvs::neighbors::brute_force::index<half, float> &index,
- bool include_dataset = true
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 <raft/core/resources.hpp> #include <cuvs/neighbors/brute_force.hpp> raft::resources handle; // create a string with a filepath std::string filename("/path/to/index"); // create an index with `auto index = brute_force::build(...);` cuvs::neighbors::brute_force::serialize(handle, filename, index);
- Template Parameters:
T – data element type
- Parameters:
handle – [in] the raft handle
filename – [in] the file name for saving the index
index – [in] brute force index
include_dataset – [in] whether to include the dataset in the serialized output
- void serialize(
- raft::resources const &handle,
- const std::string &filename,
- const cuvs::neighbors::brute_force::index<float, float> &index,
- bool include_dataset = true
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 <raft/core/resources.hpp> #include <cuvs/neighbors/brute_force.hpp> raft::resources handle; // create a string with a filepath std::string filename("/path/to/index"); // create an index with `auto index = brute_force::build(...);` cuvs::neighbors::brute_force::serialize(handle, filename, index);
- Template Parameters:
T – data element type
- Parameters:
handle – [in] the raft handle
filename – [in] the file name for saving the index
index – [in] brute force index
include_dataset – [in] whether to include the dataset in the serialized output
- void serialize(
- raft::resources const &handle,
- const std::string &filename,
- const cuvs::neighbors::brute_force::index<double, double> &index,
- bool include_dataset = true
- void serialize(
- raft::resources const &handle,
- std::ostream &os,
- const cuvs::neighbors::brute_force::index<half, float> &index,
- bool include_dataset = true
Write the index to an output stream 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 <raft/core/resources.hpp> #include <cuvs/neighbors/brute_force.hpp> raft::resources handle; // create an output stream std::ostream os(std::cout.rdbuf()); // create an index with `auto index = cuvs::neighbors::brute_force::build(...);` cuvs::neighbors::brute_force::serialize(handle, os, index);
- Parameters:
handle – [in] the raft handle
os – [in] output stream
index – [in] brute force index
include_dataset – [in] Whether or not to write out the dataset to the file.
- void serialize(
- raft::resources const &handle,
- std::ostream &os,
- const cuvs::neighbors::brute_force::index<float, float> &index,
- bool include_dataset = true
Write the index to an output stream 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 <raft/core/resources.hpp> #include <cuvs/neighbors/brute_force.hpp> raft::resources handle; // create an output stream std::ostream os(std::cout.rdbuf()); // create an index with `auto index = cuvs::neighbors::brute_force::build(...);` cuvs::neighbors::brute_force::serialize(handle, os, index);
- Parameters:
handle – [in] the raft handle
os – [in] output stream
index – [in] brute force index
include_dataset – [in] Whether or not to write out the dataset to the file.
- void serialize(
- raft::resources const &handle,
- std::ostream &os,
- const cuvs::neighbors::brute_force::index<double, double> &index,
- bool include_dataset = true
- void deserialize(
- raft::resources const &handle,
- const std::string &filename,
- cuvs::neighbors::brute_force::index<half, float> *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 <raft/core/resources.hpp> #include <cuvs/neighbors/brute_force.hpp> raft::resources handle; // create a string with a filepath std::string filename("/path/to/index"); using T = half; // data element type brute_force::index<T, float> index(handle); cuvs::neighbors::brute_force::deserialize(handle, filename, index);
- Parameters:
handle – [in] the raft handle
filename – [in] the name of the file that stores the index
index – [out] brute force index
- void deserialize(
- raft::resources const &handle,
- const std::string &filename,
- cuvs::neighbors::brute_force::index<float, float> *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 <raft/core/resources.hpp> #include <cuvs/neighbors/brute_force.hpp> raft::resources handle; // create a string with a filepath std::string filename("/path/to/index"); using T = float; // data element type brute_force::index<T, float> index(handle); cuvs::neighbors::brute_force::deserialize(handle, filename, index);
- Parameters:
handle – [in] the raft handle
filename – [in] the name of the file that stores the index
index – [out] brute force index
- void deserialize(
- raft::resources const &handle,
- const std::string &filename,
- cuvs::neighbors::brute_force::index<double, double> *index
- void deserialize(
- raft::resources const &handle,
- std::istream &is,
- cuvs::neighbors::brute_force::index<half, float> *index
Load index from input stream 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 <raft/core/resources.hpp> #include <cuvs/neighbors/brute_force.hpp> raft::resources handle; // create an input stream std::istream is(std::cin.rdbuf()); using T = half; // data element type brute_force::index<T, float> index(handle); cuvs::neighbors::brute_force::deserialize(handle, is, index);
- Parameters:
handle – [in] the raft handle
is – [in] input stream
index – [out] brute force index
- void deserialize(
- raft::resources const &handle,
- std::istream &is,
- cuvs::neighbors::brute_force::index<float, float> *index
Load index from input stream 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 <raft/core/resources.hpp> #include <cuvs/neighbors/brute_force.hpp> raft::resources handle; // create an input stream std::istream is(std::cin.rdbuf()); using T = float; // data element type brute_force::index<T, float> index(handle); cuvs::neighbors::brute_force::deserialize(handle, is, index);
- Parameters:
handle – [in] the raft handle
is – [in] input stream
index – [out] brute force index