暴力搜索#
暴力搜索方法运行KNN算法。它执行穷举搜索,与ANN方法相反,产生精确结果。
#include <cuvs/neighbors/brute_force.hpp>
命名空间 cuvs::neighbors::brute_force
索引#
-
template<typename T, typename DistT = T>
struct index : public cuvs::neighbors::index# - #include <brute_force.hpp>
暴力搜索索引。
该索引在设备内存中存储数据集及其范数。
- 模板参数:
T – 数据元素类型
公有函数
-
index(raft::resources const &handle)#
构造一个空索引。
构造一个空索引。该索引将需要通过
build
进行训练,或通过deserialize
从保存的副本加载。
- 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
从数据集中构造一个暴力搜索索引
从数据集中构造一个暴力搜索索引。这使我们能够预先计算数据集的范数,从而在查询时提供速度优势。此索引将把主机数据集复制到设备上,并拥有任何预计算范数的所有权。
- 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
从数据集中构造一个暴力搜索索引
从数据集中构造一个暴力搜索索引。这使我们能够预先计算数据集的范数,从而在查询时提供速度优势。此索引将存储对数据集的非拥有引用,但会移动提供的任何范数。
- 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
从数据集中构造一个暴力搜索索引
此类存储对数据集和范数的非拥有引用。预计算范数可在查询时提供性能优势。
- 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
从数据集中构造一个暴力搜索索引
从数据集中构造一个暴力搜索索引。这使我们能够预先计算数据集的范数,从而在查询时提供速度优势。此索引将存储对数据集的非拥有引用,但会移动提供的任何范数。
- 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
从数据集中构造一个暴力搜索索引
此类存储对数据集和范数的非拥有引用,其中数据集以列主序格式在设备上提供。
- void update_dataset(
- raft::resources const &res,
- raft::device_matrix_view<const T, int64_t, raft::row_major> dataset
用新数据集替换数据集。
- void update_dataset(
- raft::resources const &res,
- raft::host_matrix_view<const T, int64_t, raft::row_major> dataset
用新数据集替换数据集。
我们在设备上创建数据集的副本。索引管理此副本的生命周期。
-
inline cuvs::distance::DistanceType metric() const noexcept#
用于检索的距离度量
-
inline size_t size() const noexcept#
索引总长度(向量数量)。
-
inline size_t dim() const noexcept#
数据的维度。
- inline raft::device_matrix_view<const T, int64_t, raft::row_major> dataset(
数据集 [size, dim]
-
inline bool has_norms() const noexcept#
此索引是否包含数据集范数
索引构建#
- cuvs::neighbors::brute_force::index<float, float> 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
从数据集中构建索引以进行高效搜索。
使用示例
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);
- 参数:
handle – [in]
index_params – 索引参数,例如要使用的距离度量
dataset – [in] 指向行主序矩阵 [n_rows, dim] 的设备指针
- 返回:
构建的暴力搜索索引
- cuvs::neighbors::brute_force::index<float, float> 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
从数据集中构建索引以进行高效搜索。
- 参数:
handle – [in]
index_params – 索引参数,例如要使用的距离度量
dataset – [in] 指向行主序矩阵 [n_rows, dim] 的主机指针
- 返回:
构建的暴力搜索索引
- cuvs::neighbors::brute_force::index<float, float> 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<half, float> 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
从数据集中构建索引以进行高效搜索。
使用示例
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);
- 参数:
handle – [in]
index_params – 索引参数,例如要使用的距离度量
dataset – [in] 指向行主序矩阵 [n_rows, dim] 的设备指针
- 返回:
构建的暴力搜索索引
- cuvs::neighbors::brute_force::index<half, float> 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
从数据集中构建索引以进行高效搜索。
- 参数:
handle – [in]
index_params – 索引参数,例如要使用的距离度量
dataset – [in] 指向行主序矩阵 [n_rows, dim] 的主机指针
- 返回:
构建的暴力搜索索引
- cuvs::neighbors::brute_force::index<half, float> 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
- cuvs::neighbors::brute_force::index<float, float> 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
从数据集中构建索引以进行高效搜索。
使用示例
brute_force::index_params index_params; auto index = brute_force::build(handle, index_params, dataset);
- 参数:
handle – [in]
index_params – 索引参数,例如要使用的距离度量
dataset – [in] 指向行主序矩阵 [n_rows, dim] 的设备指针
- 返回:
构建的暴力搜索索引
- cuvs::neighbors::brute_force::index<float, float> 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
- cuvs::neighbors::brute_force::index<half, float> 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
从数据集中构建索引以进行高效搜索。
使用示例
brute_force::index_params index_params; auto index = brute_force::build(handle, index_params, dataset);
- 参数:
handle – [in]
index_params – 索引参数,例如要使用的距离度量
dataset – [in] 指向行主序矩阵 [n_rows, dim] 的设备指针
- 返回:
构建的暴力搜索索引
索引搜索#
- 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{}
使用构建的索引搜索ANN。
有关使用示例,请参阅brute_force::build文档。
请注意,此函数需要一个临时缓冲区来存储 CUDA 内核调用之间的中间结果,这可能会导致不希望的内存分配和速度变慢。为了缓解此问题,您可以传递一个内存池资源或足够大的预分配内存资源,以减少或完全消除
search
函数内部发生的内存分配。使用示例
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);
支持两种类型的过滤器
位集过滤器 (Bitset Filter): 一种共享过滤器,其中每个位对应一个数据集元素。所有查询共享相同的过滤器,其逻辑形状为
[1, index->size()]
。位图过滤器 (Bitmap Filter): 一种按查询划分的过滤器,其逻辑形状为
[n_queries, index->size()]
,其中每个位指示对于特定查询是否应考虑特定的数据集元素(1 表示包含,0 表示排除)。
默认值为
none_sample_filter
,表示不应用过滤。
- 参数:
handle – [in]
params – [in] 配置搜索的参数
index – [in] 构建的暴力搜索索引
queries – [in] 指向行主序矩阵 [n_queries, index->dim()] 的设备指针
neighbors – [out] 指向源数据集中邻居索引的设备指针 [n_queries, k]
distances – [out] 指向选定邻居距离的设备指针 [n_queries, k]
sample_filter – [in] 一个可选的设备过滤器,用于限制每个查询应考虑哪些数据集元素。
- 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::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{}
使用构建的索引搜索ANN。
有关使用示例,请参阅brute_force::build文档。
请注意,此函数需要一个临时缓冲区来存储 CUDA 内核调用之间的中间结果,这可能会导致不希望的内存分配和速度变慢。为了缓解此问题,您可以传递一个内存池资源或足够大的预分配内存资源,以减少或完全消除
search
函数内部发生的内存分配。使用示例
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);
支持两种类型的过滤器
位集过滤器 (Bitset Filter): 一种共享过滤器,其中每个位对应一个数据集元素。所有查询共享相同的过滤器,其逻辑形状为
[1, index->size()]
。位图过滤器 (Bitmap Filter): 一种按查询划分的过滤器,其逻辑形状为
[n_queries, index->size()]
,其中每个位指示对于特定查询是否应考虑特定的数据集元素(1 表示包含,0 表示排除)。
默认值为
none_sample_filter
,表示不应用过滤。
- 参数:
handle – [in]
params – [in] 配置搜索的参数
index – [in] 构建的ivf-flat索引
queries – [in] 指向行主序矩阵 [n_queries, index->dim()] 的设备指针
neighbors – [out] 指向源数据集中邻居索引的设备指针 [n_queries, k]
distances – [out] 指向选定邻居距离的设备指针 [n_queries, k]
sample_filter – [in] 一个可选的设备过滤器,用于限制每个查询应考虑哪些数据集元素。
- 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{}
使用构建的索引搜索ANN。
有关使用示例,请参阅brute_force::build文档。
请注意,此函数需要一个临时缓冲区来存储 CUDA 内核调用之间的中间结果,这可能会导致不希望的内存分配和速度变慢。为了缓解此问题,您可以传递一个内存池资源或足够大的预分配内存资源,以减少或完全消除
search
函数内部发生的内存分配。使用示例
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);
支持两种类型的过滤器
位集过滤器 (Bitset Filter): 一种共享过滤器,其中每个位对应一个数据集元素。所有查询共享相同的过滤器,其逻辑形状为
[1, index->size()]
。位图过滤器 (Bitmap Filter): 一种按查询划分的过滤器,其逻辑形状为
[n_queries, index->size()]
,其中每个位指示对于特定查询是否应考虑特定的数据集元素(1 表示包含,0 表示排除)。
默认值为
none_sample_filter
,表示不应用过滤。
- 参数:
handle – [in]
params – [in] 配置搜索的参数
index – [in] 构建的暴力搜索索引
queries – [in] 指向列主序矩阵 [n_queries, index->dim()] 的设备指针
neighbors – [out] 指向源数据集中邻居索引的设备指针 [n_queries, k]
distances – [out] 指向选定邻居距离的设备指针 [n_queries, k]
sample_filter – [in] 一个可选的设备过滤器,用于限制每个查询应考虑哪些数据集元素。
- 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::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{}
使用构建的索引搜索ANN。
有关使用示例,请参阅brute_force::build文档。
请注意,此函数需要一个临时缓冲区来存储 CUDA 内核调用之间的中间结果,这可能会导致不希望的内存分配和速度变慢。为了缓解此问题,您可以传递一个内存池资源或足够大的预分配内存资源,以减少或完全消除
search
函数内部发生的内存分配。使用示例
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);
支持两种类型的过滤器
位集过滤器 (Bitset Filter): 一种共享过滤器,其中每个位对应一个数据集元素。所有查询共享相同的过滤器,其逻辑形状为
[1, index->size()]
。位图过滤器 (Bitmap Filter): 一种按查询划分的过滤器,其逻辑形状为
[n_queries, index->size()]
,其中每个位指示对于特定查询是否应考虑特定的数据集元素(1 表示包含,0 表示排除)。
默认值为
none_sample_filter
,表示不应用过滤。
- 参数:
handle – [in]
params – [in] 配置搜索的参数
index – [in] 构建的暴力搜索索引
queries – [in] 指向列主序矩阵 [n_queries, index->dim()] 的设备指针
neighbors – [out] 指向源数据集中邻居索引的设备指针 [n_queries, k]
distances – [out] 指向选定邻居距离的设备指针 [n_queries, k]
sample_filter – [in] 一个可选的设备过滤器,用于限制每个查询应考虑哪些数据集元素。
- 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{}
索引序列化#
- void serialize(
- raft::resources const &handle,
- const std::string &filename,
- const cuvs::neighbors::brute_force::index<half, float> &index,
- bool include_dataset = true
将索引保存到文件。序列化格式可能会发生变化,因此不保证加载使用 cuvs 之前版本保存的索引能够正常工作。
#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);
- 模板参数:
T – 数据元素类型
- 参数:
handle – [in] raft 句柄
filename – [in] 用于保存索引的文件名
index – [in] 暴力搜索索引
include_dataset – [in] 是否在序列化输出中包含数据集
- void serialize(
- raft::resources const &handle,
- const std::string &filename,
- const cuvs::neighbors::brute_force::index<float, float> &index,
- bool include_dataset = true
将索引保存到文件。序列化格式可能会发生变化,因此不保证加载使用 cuvs 之前版本保存的索引能够正常工作。
#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);
- 模板参数:
T – 数据元素类型
- 参数:
handle – [in] raft 句柄
filename – [in] 用于保存索引的文件名
index – [in] 暴力搜索索引
include_dataset – [in] 是否在序列化输出中包含数据集
- void serialize(
- raft::resources const &handle,
- std::ostream &os,
- const cuvs::neighbors::brute_force::index<half, float> &index,
- bool include_dataset = true
将索引写入输出流。序列化格式可能会发生变化,因此不保证加载使用 cuvs 之前版本保存的索引能够正常工作。
#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);
- 参数:
handle – [in] raft 句柄
os – [in] 输出流
index – [in] 暴力搜索索引
include_dataset – [in] 是否将数据集写入文件。
- void serialize(
- raft::resources const &handle,
- std::ostream &os,
- const cuvs::neighbors::brute_force::index<float, float> &index,
- bool include_dataset = true
将索引写入输出流。序列化格式可能会发生变化,因此不保证加载使用 cuvs 之前版本保存的索引能够正常工作。
#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);
- 参数:
handle – [in] raft 句柄
os – [in] 输出流
index – [in] 暴力搜索索引
include_dataset – [in] 是否将数据集写入文件。
- void deserialize(
- raft::resources const &handle,
- const std::string &filename,
- cuvs::neighbors::brute_force::index<half, float> *index
从文件加载索引。序列化格式可能会发生变化,因此不保证加载使用 cuvs 之前版本保存的索引能够正常工作。
#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);
- 参数:
handle – [in] raft 句柄
filename – [in] 存储索引的文件名
index – [out] 暴力搜索索引
- void deserialize(
- raft::resources const &handle,
- const std::string &filename,
- cuvs::neighbors::brute_force::index<float, float> *index
从文件加载索引。序列化格式可能会发生变化,因此不保证加载使用 cuvs 之前版本保存的索引能够正常工作。
#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);
- 参数:
handle – [in] raft 句柄
filename – [in] 存储索引的文件名
index – [out] 暴力搜索索引
- void deserialize(
- raft::resources const &handle,
- std::istream &is,
- cuvs::neighbors::brute_force::index<half, float> *index
从输入流加载索引。序列化格式可能会发生变化,因此不保证加载使用 cuvs 之前版本保存的索引能够正常工作。
#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);
- 参数:
handle – [in] raft 句柄
is – [in] 输入流
index – [out] 暴力搜索索引
- void deserialize(
- raft::resources const &handle,
- std::istream &is,
- cuvs::neighbors::brute_force::index<float, float> *index
从输入流加载索引。序列化格式可能会发生变化,因此不保证加载使用 cuvs 之前版本保存的索引能够正常工作。
#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);
- 参数:
handle – [in] raft 句柄
is – [in] 输入流
index – [out] 暴力搜索索引