分布式 ANN#
SNMG(单节点多 GPU)ANN API 提供了一组函数,用于在多个 GPU 上部署 ANN 索引。
#include <cuvs/neighbors/mg.hpp>
namespace cuvs::neighbors::mg
索引构建参数#
搜索参数#
-
enum replicated_search_mode#
使用复制索引时的搜索模式
值
-
enumerator LOAD_BALANCER#
搜索查询被分割以在 GPU 上保持均衡负载
-
enumerator ROUND_ROBIN#
每个搜索查询由一个 GPU 以轮询方式处理
-
enumerator LOAD_BALANCER#
-
enum sharded_merge_mode#
使用分片索引时的合并模式
值
-
enumerator MERGE_ON_ROOT_RANK#
搜索批次在根级别合并
-
enumerator TREE_MERGE#
搜索批次以树状归约方式合并
-
enumerator MERGE_ON_ROOT_RANK#
-
template<typename Upstream>
struct search_params : public Upstream# - #include <mg.hpp>
搜索参数
公有成员
-
cuvs::neighbors::mg::replicated_search_mode search_mode = LOAD_BALANCER#
复制搜索模式
-
cuvs::neighbors::mg::sharded_merge_mode merge_mode = TREE_MERGE#
分片合并模式
-
cuvs::neighbors::mg::replicated_search_mode search_mode = LOAD_BALANCER#
索引构建#
- index<ivf_flat::index<float, int64_t>, float, int64_t> build(
- const raft::device_resources &handle,
- const mg::index_params<ivf_flat::index_params> &index_params,
- raft::host_matrix_view<const float, int64_t, row_major> index_dataset
构建一个多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<ivf_flat::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset);
- 参数:
handle – [输入]
index_params – 配置索引构建
index_dataset – [输入] 主机上的行主序矩阵 [n_rows, dim]
- 返回:
构建的 IVF-Flat MG 索引
- index<ivf_flat::index<int8_t, int64_t>, int8_t, int64_t> build(
- const raft::device_resources &handle,
- const mg::index_params<ivf_flat::index_params> &index_params,
- raft::host_matrix_view<const int8_t, int64_t, row_major> index_dataset
构建一个多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<ivf_flat::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset);
- 参数:
handle – [输入]
index_params – 配置索引构建
index_dataset – [输入] 主机上的行主序矩阵 [n_rows, dim]
- 返回:
构建的 IVF-Flat MG 索引
- index<ivf_flat::index<uint8_t, int64_t>, uint8_t, int64_t> build(
- const raft::device_resources &handle,
- const mg::index_params<ivf_flat::index_params> &index_params,
- raft::host_matrix_view<const uint8_t, int64_t, row_major> index_dataset
构建一个多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<ivf_flat::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset);
- 参数:
handle – [输入]
index_params – 配置索引构建
index_dataset – [输入] 主机上的行主序矩阵 [n_rows, dim]
- 返回:
构建的 IVF-Flat MG 索引
- index<ivf_pq::index<int64_t>, float, int64_t> build(
- const raft::device_resources &handle,
- const mg::index_params<ivf_pq::index_params> &index_params,
- raft::host_matrix_view<const float, int64_t, row_major> index_dataset
构建一个多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<ivf_pq::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset);
- 参数:
handle – [输入]
index_params – 配置索引构建
index_dataset – [输入] 主机上的行主序矩阵 [n_rows, dim]
- 返回:
构建的 IVF-PQ MG 索引
- index<ivf_pq::index<int64_t>, half, int64_t> build(
- const raft::device_resources &handle,
- const mg::index_params<ivf_pq::index_params> &index_params,
- raft::host_matrix_view<const half, int64_t, row_major> index_dataset
构建一个多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<ivf_pq::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset);
- 参数:
handle – [输入]
index_params – 配置索引构建
index_dataset – [输入] 主机上的行主序矩阵 [n_rows, dim]
- 返回:
构建的 IVF-PQ MG 索引
- index<ivf_pq::index<int64_t>, int8_t, int64_t> build(
- const raft::device_resources &handle,
- const mg::index_params<ivf_pq::index_params> &index_params,
- raft::host_matrix_view<const int8_t, int64_t, row_major> index_dataset
构建一个多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<ivf_pq::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset);
- 参数:
handle – [输入]
index_params – 配置索引构建
index_dataset – [输入] 主机上的行主序矩阵 [n_rows, dim]
- 返回:
构建的 IVF-PQ MG 索引
- index<ivf_pq::index<int64_t>, uint8_t, int64_t> build(
- const raft::device_resources &handle,
- const mg::index_params<ivf_pq::index_params> &index_params,
- raft::host_matrix_view<const uint8_t, int64_t, row_major> index_dataset
构建一个多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<ivf_pq::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset);
- 参数:
handle – [输入]
index_params – 配置索引构建
index_dataset – [输入] 主机上的行主序矩阵 [n_rows, dim]
- 返回:
构建的 IVF-PQ MG 索引
- index<cagra::index<float, uint32_t>, float, uint32_t> build(
- const raft::device_resources &handle,
- const mg::index_params<cagra::index_params> &index_params,
- raft::host_matrix_view<const float, int64_t, row_major> index_dataset
构建一个多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<cagra::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset);
- 参数:
handle – [输入]
index_params – 配置索引构建
index_dataset – [输入] 主机上的行主序矩阵 [n_rows, dim]
- 返回:
构建的 CAGRA MG 索引
- index<cagra::index<half, uint32_t>, half, uint32_t> build(
- const raft::device_resources &handle,
- const mg::index_params<cagra::index_params> &index_params,
- raft::host_matrix_view<const half, int64_t, row_major> index_dataset
构建一个多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<cagra::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset);
- 参数:
handle – [输入]
index_params – 配置索引构建
index_dataset – [输入] 主机上的行主序矩阵 [n_rows, dim]
- 返回:
构建的 CAGRA MG 索引
- index<cagra::index<int8_t, uint32_t>, int8_t, uint32_t> build(
- const raft::device_resources &handle,
- const mg::index_params<cagra::index_params> &index_params,
- raft::host_matrix_view<const int8_t, int64_t, row_major> index_dataset
构建一个多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<cagra::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset);
- 参数:
handle – [输入]
index_params – 配置索引构建
index_dataset – [输入] 主机上的行主序矩阵 [n_rows, dim]
- 返回:
构建的 CAGRA MG 索引
- index<cagra::index<uint8_t, uint32_t>, uint8_t, uint32_t> build(
- const raft::device_resources &handle,
- const mg::index_params<cagra::index_params> &index_params,
- raft::host_matrix_view<const uint8_t, int64_t, row_major> index_dataset
构建一个多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<cagra::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset);
- 参数:
handle – [输入]
index_params – 配置索引构建
index_dataset – [输入] 主机上的行主序矩阵 [n_rows, dim]
- 返回:
构建的 CAGRA MG 索引
索引扩展#
- void extend(
- const raft::device_resources &handle,
- index<ivf_flat::index<float, int64_t>, float, int64_t> &index,
- raft::host_matrix_view<const float, int64_t, row_major> new_vectors,
- std::optional<raft::host_vector_view<const int64_t, int64_t>> new_indices
扩展一个多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<ivf_flat::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset); cuvs::neighbors::mg::extend(handle, index, new_vectors, std::nullopt);
- 参数:
handle – [输入]
index – [输入] 预构建的索引
new_vectors – [输入] 主机上的行主序矩阵 [n_rows, dim]
new_indices – [输入] 主机上的可选向量 [n_rows],
std::nullopt
表示默认连续范围[0...n_rows)
- void extend(
- const raft::device_resources &handle,
- index<ivf_flat::index<int8_t, int64_t>, int8_t, int64_t> &index,
- raft::host_matrix_view<const int8_t, int64_t, row_major> new_vectors,
- std::optional<raft::host_vector_view<const int64_t, int64_t>> new_indices
扩展一个多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<ivf_flat::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset); cuvs::neighbors::mg::extend(handle, index, new_vectors, std::nullopt);
- 参数:
handle – [输入]
index – [输入] 预构建的索引
new_vectors – [输入] 主机上的行主序矩阵 [n_rows, dim]
new_indices – [输入] 主机上的可选向量 [n_rows],
std::nullopt
表示默认连续范围[0...n_rows)
- void extend(
- const raft::device_resources &handle,
- index<ivf_flat::index<uint8_t, int64_t>, uint8_t, int64_t> &index,
- raft::host_matrix_view<const uint8_t, int64_t, row_major> new_vectors,
- std::optional<raft::host_vector_view<const int64_t, int64_t>> new_indices
扩展一个多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<ivf_flat::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset); cuvs::neighbors::mg::extend(handle, index, new_vectors, std::nullopt);
- 参数:
handle – [输入]
index – [输入] 预构建的索引
new_vectors – [输入] 主机上的行主序矩阵 [n_rows, dim]
new_indices – [输入] 主机上的可选向量 [n_rows],
std::nullopt
表示默认连续范围[0...n_rows)
- void extend(
- const raft::device_resources &handle,
- index<ivf_pq::index<int64_t>, float, int64_t> &index,
- raft::host_matrix_view<const float, int64_t, row_major> new_vectors,
- std::optional<raft::host_vector_view<const int64_t, int64_t>> new_indices
扩展一个多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<ivf_pq::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset); cuvs::neighbors::mg::extend(handle, index, new_vectors, std::nullopt);
- 参数:
handle – [输入]
index – [输入] 预构建的索引
new_vectors – [输入] 主机上的行主序矩阵 [n_rows, dim]
new_indices – [输入] 主机上的可选向量 [n_rows],
std::nullopt
表示默认连续范围[0...n_rows)
- void extend(
- const raft::device_resources &handle,
- index<ivf_pq::index<int64_t>, half, int64_t> &index,
- raft::host_matrix_view<const half, int64_t, row_major> new_vectors,
- std::optional<raft::host_vector_view<const int64_t, int64_t>> new_indices
扩展一个多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<ivf_pq::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset); cuvs::neighbors::mg::extend(handle, index, new_vectors, std::nullopt);
- 参数:
handle – [输入]
index – [输入] 预构建的索引
new_vectors – [输入] 主机上的行主序矩阵 [n_rows, dim]
new_indices – [输入] 主机上的可选向量 [n_rows],
std::nullopt
表示默认连续范围[0...n_rows)
- void extend(
- const raft::device_resources &handle,
- index<ivf_pq::index<int64_t>, int8_t, int64_t> &index,
- raft::host_matrix_view<const int8_t, int64_t, row_major> new_vectors,
- std::optional<raft::host_vector_view<const int64_t, int64_t>> new_indices
扩展一个多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<ivf_pq::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset); cuvs::neighbors::mg::extend(handle, index, new_vectors, std::nullopt);
- 参数:
handle – [输入]
index – [输入] 预构建的索引
new_vectors – [输入] 主机上的行主序矩阵 [n_rows, dim]
new_indices – [输入] 主机上的可选向量 [n_rows],
std::nullopt
表示默认连续范围[0...n_rows)
- void extend(
- const raft::device_resources &handle,
- index<ivf_pq::index<int64_t>, uint8_t, int64_t> &index,
- raft::host_matrix_view<const uint8_t, int64_t, row_major> new_vectors,
- std::optional<raft::host_vector_view<const int64_t, int64_t>> new_indices
扩展一个多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<ivf_pq::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset); cuvs::neighbors::mg::extend(handle, index, new_vectors, std::nullopt);
- 参数:
handle – [输入]
index – [输入] 预构建的索引
new_vectors – [输入] 主机上的行主序矩阵 [n_rows, dim]
new_indices – [输入] 主机上的可选向量 [n_rows],
std::nullopt
表示默认连续范围[0...n_rows)
- void extend(
- const raft::device_resources &handle,
- index<cagra::index<float, uint32_t>, float, uint32_t> &index,
- raft::host_matrix_view<const float, int64_t, row_major> new_vectors,
- std::optional<raft::host_vector_view<const uint32_t, int64_t>> new_indices
扩展一个多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<cagra::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset); cuvs::neighbors::mg::extend(handle, index, new_vectors, std::nullopt);
- 参数:
handle – [输入]
index – [输入] 预构建的索引
new_vectors – [输入] 主机上的行主序矩阵 [n_rows, dim]
new_indices – [输入] 主机上的可选向量 [n_rows],
std::nullopt
表示默认连续范围[0...n_rows)
- void extend(
- const raft::device_resources &handle,
- index<cagra::index<half, uint32_t>, half, uint32_t> &index,
- raft::host_matrix_view<const half, int64_t, row_major> new_vectors,
- std::optional<raft::host_vector_view<const uint32_t, int64_t>> new_indices
扩展一个多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<cagra::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset); cuvs::neighbors::mg::extend(handle, index, new_vectors, std::nullopt);
- 参数:
handle – [输入]
index – [输入] 预构建的索引
new_vectors – [输入] 主机上的行主序矩阵 [n_rows, dim]
new_indices – [输入] 主机上的可选向量 [n_rows],
std::nullopt
表示默认连续范围[0...n_rows)
- void extend(
- const raft::device_resources &handle,
- index<cagra::index<int8_t, uint32_t>, int8_t, uint32_t> &index,
- raft::host_matrix_view<const int8_t, int64_t, row_major> new_vectors,
- std::optional<raft::host_vector_view<const uint32_t, int64_t>> new_indices
扩展一个多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<cagra::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset); cuvs::neighbors::mg::extend(handle, index, new_vectors, std::nullopt);
- 参数:
handle – [输入]
index – [输入] 预构建的索引
new_vectors – [输入] 主机上的行主序矩阵 [n_rows, dim]
new_indices – [输入] 主机上的可选向量 [n_rows],
std::nullopt
表示默认连续范围[0...n_rows)
- void extend(
- const raft::device_resources &handle,
- index<cagra::index<uint8_t, uint32_t>, uint8_t, uint32_t> &index,
- raft::host_matrix_view<const uint8_t, int64_t, row_major> new_vectors,
- std::optional<raft::host_vector_view<const uint32_t, int64_t>> new_indices
扩展一个多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<cagra::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset); cuvs::neighbors::mg::extend(handle, index, new_vectors, std::nullopt);
- 参数:
handle – [输入]
index – [输入] 预构建的索引
new_vectors – [输入] 主机上的行主序矩阵 [n_rows, dim]
new_indices – [输入] 主机上的可选向量 [n_rows],
std::nullopt
表示默认连续范围[0...n_rows)
索引搜索#
- void search(
- const raft::device_resources &handle,
- const index<ivf_flat::index<float, int64_t>, float, int64_t> &index,
- const mg::search_params<ivf_flat::search_params> &search_params,
- raft::host_matrix_view<const float, int64_t, row_major> queries,
- raft::host_matrix_view<int64_t, int64_t, row_major> neighbors,
- raft::host_matrix_view<float, int64_t, row_major> distances,
- int64_t n_rows_per_batch = DEFAULT_SEARCH_BATCH_SIZE
搜索一个多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<ivf_flat::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset); cuvs::neighbors::mg::search_params<ivf_flat::search_params> search_params; cuvs::neighbors::mg::search(handle, index, search_params, queries, neighbors, distances);
- 参数:
handle – [输入]
index – [输入] 预构建的索引
search_params – 配置索引搜索
queries – [输入] 主机上的行主序矩阵 [n_rows, dim]
neighbors – [输出] 主机上的行主序矩阵 [n_rows, n_neighbors]
distances – [输出] 主机上的行主序矩阵 [n_rows, n_neighbors]
n_rows_per_batch – [输入](可选)搜索批次大小
- void search(
- const raft::device_resources &handle,
- const index<ivf_flat::index<int8_t, int64_t>, int8_t, int64_t> &index,
- const mg::search_params<ivf_flat::search_params> &search_params,
- raft::host_matrix_view<const int8_t, int64_t, row_major> queries,
- raft::host_matrix_view<int64_t, int64_t, row_major> neighbors,
- raft::host_matrix_view<float, int64_t, row_major> distances,
- int64_t n_rows_per_batch = DEFAULT_SEARCH_BATCH_SIZE
搜索一个多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<ivf_flat::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset); cuvs::neighbors::mg::search_params<ivf_flat::search_params> search_params; cuvs::neighbors::mg::search(handle, index, search_params, queries, neighbors, distances);
- 参数:
handle – [输入]
index – [输入] 预构建的索引
search_params – 配置索引搜索
queries – [输入] 主机上的行主序矩阵 [n_rows, dim]
neighbors – [输出] 主机上的行主序矩阵 [n_rows, n_neighbors]
distances – [输出] 主机上的行主序矩阵 [n_rows, n_neighbors]
n_rows_per_batch – [输入](可选)搜索批次大小
- void search(
- const raft::device_resources &handle,
- const index<ivf_flat::index<uint8_t, int64_t>, uint8_t, int64_t> &index,
- const mg::search_params<ivf_flat::search_params> &search_params,
- raft::host_matrix_view<const uint8_t, int64_t, row_major> queries,
- raft::host_matrix_view<int64_t, int64_t, row_major> neighbors,
- raft::host_matrix_view<float, int64_t, row_major> distances,
- int64_t n_rows_per_batch = DEFAULT_SEARCH_BATCH_SIZE
搜索一个多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<ivf_flat::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset); cuvs::neighbors::mg::search_params<ivf_flat::search_params> search_params; cuvs::neighbors::mg::search(handle, index, search_params, queries, neighbors, distances);
- 参数:
handle – [输入]
index – [输入] 预构建的索引
search_params – 配置索引搜索
queries – [输入] 主机上的行主序矩阵 [n_rows, dim]
neighbors – [输出] 主机上的行主序矩阵 [n_rows, n_neighbors]
distances – [输出] 主机上的行主序矩阵 [n_rows, n_neighbors]
n_rows_per_batch – [输入](可选)搜索批次大小
- void search(
- const raft::device_resources &handle,
- const index<ivf_pq::index<int64_t>, float, int64_t> &index,
- const mg::search_params<ivf_pq::search_params> &search_params,
- raft::host_matrix_view<const float, int64_t, row_major> queries,
- raft::host_matrix_view<int64_t, int64_t, row_major> neighbors,
- raft::host_matrix_view<float, int64_t, row_major> distances,
- int64_t n_rows_per_batch = DEFAULT_SEARCH_BATCH_SIZE
搜索一个多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<ivf_pq::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset); cuvs::neighbors::mg::search_params<ivf_pq::search_params> search_params; cuvs::neighbors::mg::search(handle, index, search_params, queries, neighbors, distances);
- 参数:
handle – [输入]
index – [输入] 预构建的索引
search_params – 配置索引搜索
queries – [输入] 主机上的行主序矩阵 [n_rows, dim]
neighbors – [输出] 主机上的行主序矩阵 [n_rows, n_neighbors]
distances – [输出] 主机上的行主序矩阵 [n_rows, n_neighbors]
n_rows_per_batch – [输入](可选)搜索批次大小
- void search(
- const raft::device_resources &handle,
- const index<ivf_pq::index<int64_t>, half, int64_t> &index,
- const mg::search_params<ivf_pq::search_params> &search_params,
- raft::host_matrix_view<const half, int64_t, row_major> queries,
- raft::host_matrix_view<int64_t, int64_t, row_major> neighbors,
- raft::host_matrix_view<float, int64_t, row_major> distances,
- int64_t n_rows_per_batch = DEFAULT_SEARCH_BATCH_SIZE
搜索一个多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<ivf_pq::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset); cuvs::neighbors::mg::search_params<ivf_pq::search_params> search_params; cuvs::neighbors::mg::search(handle, index, search_params, queries, neighbors, distances);
- 参数:
handle – [输入]
index – [输入] 预构建的索引
search_params – 配置索引搜索
queries – [输入] 主机上的行主序矩阵 [n_rows, dim]
neighbors – [输出] 主机上的行主序矩阵 [n_rows, n_neighbors]
distances – [输出] 主机上的行主序矩阵 [n_rows, n_neighbors]
n_rows_per_batch – [输入](可选)搜索批次大小
- void search(
- const raft::device_resources &handle,
- const index<ivf_pq::index<int64_t>, int8_t, int64_t> &index,
- const mg::search_params<ivf_pq::search_params> &search_params,
- raft::host_matrix_view<const int8_t, int64_t, row_major> queries,
- raft::host_matrix_view<int64_t, int64_t, row_major> neighbors,
- raft::host_matrix_view<float, int64_t, row_major> distances,
- int64_t n_rows_per_batch = DEFAULT_SEARCH_BATCH_SIZE
搜索一个多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<ivf_pq::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset); cuvs::neighbors::mg::search_params<ivf_pq::search_params> search_params; cuvs::neighbors::mg::search(handle, index, search_params, queries, neighbors, distances);
- 参数:
handle – [输入]
index – [输入] 预构建的索引
search_params – 配置索引搜索
queries – [输入] 主机上的行主序矩阵 [n_rows, dim]
neighbors – [输出] 主机上的行主序矩阵 [n_rows, n_neighbors]
distances – [输出] 主机上的行主序矩阵 [n_rows, n_neighbors]
n_rows_per_batch – [输入](可选)搜索批次大小
- void search(
- const raft::device_resources &handle,
- const index<ivf_pq::index<int64_t>, uint8_t, int64_t> &index,
- const mg::search_params<ivf_pq::search_params> &search_params,
- raft::host_matrix_view<const uint8_t, int64_t, row_major> queries,
- raft::host_matrix_view<int64_t, int64_t, row_major> neighbors,
- raft::host_matrix_view<float, int64_t, row_major> distances,
- int64_t n_rows_per_batch = DEFAULT_SEARCH_BATCH_SIZE
搜索一个多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<ivf_pq::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset); cuvs::neighbors::mg::search_params<ivf_pq::search_params> search_params; cuvs::neighbors::mg::search(handle, index, search_params, queries, neighbors, distances);
- 参数:
handle – [输入]
index – [输入] 预构建的索引
search_params – 配置索引搜索
queries – [输入] 主机上的行主序矩阵 [n_rows, dim]
neighbors – [输出] 主机上的行主序矩阵 [n_rows, n_neighbors]
distances – [输出] 主机上的行主序矩阵 [n_rows, n_neighbors]
n_rows_per_batch – [输入](可选)搜索批次大小
- void search(
- const raft::device_resources &handle,
- const index<cagra::index<float, uint32_t>, float, uint32_t> &index,
- const mg::search_params<cagra::search_params> &search_params,
- raft::host_matrix_view<const float, int64_t, row_major> queries,
- raft::host_matrix_view<uint32_t, int64_t, row_major> neighbors,
- raft::host_matrix_view<float, int64_t, row_major> distances,
- int64_t n_rows_per_batch = DEFAULT_SEARCH_BATCH_SIZE
搜索一个多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<cagra::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset); cuvs::neighbors::mg::search_params<cagra::search_params> search_params; cuvs::neighbors::mg::search(handle, index, search_params, queries, neighbors, distances);
- 参数:
handle – [输入]
index – [输入] 预构建的索引
search_params – 配置索引搜索
queries – [输入] 主机上的行主序矩阵 [n_rows, dim]
neighbors – [输出] 主机上的行主序矩阵 [n_rows, n_neighbors]
distances – [输出] 主机上的行主序矩阵 [n_rows, n_neighbors]
n_rows_per_batch – [输入](可选)搜索批次大小
- void search(
- const raft::device_resources &handle,
- const index<cagra::index<half, uint32_t>, half, uint32_t> &index,
- const mg::search_params<cagra::search_params> &search_params,
- raft::host_matrix_view<const half, int64_t, row_major> queries,
- raft::host_matrix_view<uint32_t, int64_t, row_major> neighbors,
- raft::host_matrix_view<float, int64_t, row_major> distances,
- int64_t n_rows_per_batch = DEFAULT_SEARCH_BATCH_SIZE
搜索一个多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<cagra::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset); cuvs::neighbors::mg::search_params<cagra::search_params> search_params; cuvs::neighbors::mg::search(handle, index, search_params, queries, neighbors, distances);
- 参数:
handle – [输入]
index – [输入] 预构建的索引
search_params – 配置索引搜索
queries – [输入] 主机上的行主序矩阵 [n_rows, dim]
neighbors – [输出] 主机上的行主序矩阵 [n_rows, n_neighbors]
distances – [输出] 主机上的行主序矩阵 [n_rows, n_neighbors]
n_rows_per_batch – [输入](可选)搜索批次大小
- void search(
- const raft::device_resources &handle,
- const index<cagra::index<int8_t, uint32_t>, int8_t, uint32_t> &index,
- const mg::search_params<cagra::search_params> &search_params,
- raft::host_matrix_view<const int8_t, int64_t, row_major> queries,
- raft::host_matrix_view<uint32_t, int64_t, row_major> neighbors,
- raft::host_matrix_view<float, int64_t, row_major> distances,
- int64_t n_rows_per_batch = DEFAULT_SEARCH_BATCH_SIZE
搜索一个多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<cagra::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset); cuvs::neighbors::mg::search_params<cagra::search_params> search_params; cuvs::neighbors::mg::search(handle, index, search_params, queries, neighbors, distances);
- 参数:
handle – [输入]
index – [输入] 预构建的索引
search_params – 配置索引搜索
queries – [输入] 主机上的行主序矩阵 [n_rows, dim]
neighbors – [输出] 主机上的行主序矩阵 [n_rows, n_neighbors]
distances – [输出] 主机上的行主序矩阵 [n_rows, n_neighbors]
n_rows_per_batch – [输入](可选)搜索批次大小
- void search(
- const raft::device_resources &handle,
- const index<cagra::index<uint8_t, uint32_t>, uint8_t, uint32_t> &index,
- const mg::search_params<cagra::search_params> &search_params,
- raft::host_matrix_view<const uint8_t, int64_t, row_major> queries,
- raft::host_matrix_view<uint32_t, int64_t, row_major> neighbors,
- raft::host_matrix_view<float, int64_t, row_major> distances,
- int64_t n_rows_per_batch = DEFAULT_SEARCH_BATCH_SIZE
搜索一个多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<cagra::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset); cuvs::neighbors::mg::search_params<cagra::search_params> search_params; cuvs::neighbors::mg::search(handle, index, search_params, queries, neighbors, distances);
- 参数:
handle – [输入]
index – [输入] 预构建的索引
search_params – 配置索引搜索
queries – [输入] 主机上的行主序矩阵 [n_rows, dim]
neighbors – [输出] 主机上的行主序矩阵 [n_rows, n_neighbors]
distances – [输出] 主机上的行主序矩阵 [n_rows, n_neighbors]
n_rows_per_batch – [输入](可选)搜索批次大小
索引序列化#
- void serialize(
- const raft::device_resources &handle,
- const index<ivf_flat::index<float, int64_t>, float, int64_t> &index,
- const std::string &filename
序列化多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<ivf_flat::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset); const std::string filename = "mg_index.cuvs"; cuvs::neighbors::mg::serialize(handle, index, filename);
- 参数:
handle – [输入]
index – [输入] 预构建的索引
filename – [in] 要序列化的文件的路径
- void serialize(
- const raft::device_resources &handle,
- const index<ivf_flat::index<int8_t, int64_t>, int8_t, int64_t> &index,
- const std::string &filename
序列化多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<ivf_flat::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset); const std::string filename = "mg_index.cuvs"; cuvs::neighbors::mg::serialize(handle, index, filename);
- 参数:
handle – [输入]
index – [输入] 预构建的索引
filename – [in] 要序列化的文件的路径
- void serialize(
- const raft::device_resources &handle,
- const index<ivf_flat::index<uint8_t, int64_t>, uint8_t, int64_t> &index,
- const std::string &filename
序列化多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<ivf_flat::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset); const std::string filename = "mg_index.cuvs"; cuvs::neighbors::mg::serialize(handle, index, filename);
- 参数:
handle – [输入]
index – [输入] 预构建的索引
filename – [in] 要序列化的文件的路径
- void serialize(
- const raft::device_resources &handle,
- const index<ivf_pq::index<int64_t>, float, int64_t> &index,
- const std::string &filename
序列化多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<ivf_pq::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset); const std::string filename = "mg_index.cuvs"; cuvs::neighbors::mg::serialize(handle, index, filename);
- 参数:
handle – [输入]
index – [输入] 预构建的索引
filename – [in] 要序列化的文件的路径
- void serialize(
- const raft::device_resources &handle,
- const index<ivf_pq::index<int64_t>, half, int64_t> &index,
- const std::string &filename
序列化多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<ivf_pq::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset); const std::string filename = "mg_index.cuvs"; cuvs::neighbors::mg::serialize(handle, index, filename);
- 参数:
handle – [输入]
index – [输入] 预构建的索引
filename – [in] 要序列化的文件的路径
- void serialize(
- const raft::device_resources &handle,
- const index<ivf_pq::index<int64_t>, int8_t, int64_t> &index,
- const std::string &filename
序列化多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<ivf_pq::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset); const std::string filename = "mg_index.cuvs"; cuvs::neighbors::mg::serialize(handle, index, filename);
- 参数:
handle – [输入]
index – [输入] 预构建的索引
filename – [in] 要序列化的文件的路径
- void serialize(
- const raft::device_resources &handle,
- const index<ivf_pq::index<int64_t>, uint8_t, int64_t> &index,
- const std::string &filename
序列化多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<ivf_pq::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset); const std::string filename = "mg_index.cuvs"; cuvs::neighbors::mg::serialize(handle, index, filename);
- 参数:
handle – [输入]
index – [输入] 预构建的索引
filename – [in] 要序列化的文件的路径
- void serialize(
- const raft::device_resources &handle,
- const index<cagra::index<float, uint32_t>, float, uint32_t> &index,
- const std::string &filename
序列化多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<cagra::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset); const std::string filename = "mg_index.cuvs"; cuvs::neighbors::mg::serialize(handle, index, filename);
- 参数:
handle – [输入]
index – [输入] 预构建的索引
filename – [in] 要序列化的文件的路径
- void serialize(
- const raft::device_resources &handle,
- const index<cagra::index<half, uint32_t>, half, uint32_t> &index,
- const std::string &filename
序列化多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<cagra::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset); const std::string filename = "mg_index.cuvs"; cuvs::neighbors::mg::serialize(handle, index, filename);
- 参数:
handle – [输入]
index – [输入] 预构建的索引
filename – [in] 要序列化的文件的路径
- void serialize(
- const raft::device_resources &handle,
- const index<cagra::index<int8_t, uint32_t>, int8_t, uint32_t> &index,
- const std::string &filename
序列化多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<cagra::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset); const std::string filename = "mg_index.cuvs"; cuvs::neighbors::mg::serialize(handle, index, filename);
- 参数:
handle – [输入]
index – [输入] 预构建的索引
filename – [in] 要序列化的文件的路径
- void serialize(
- const raft::device_resources &handle,
- const index<cagra::index<uint8_t, uint32_t>, uint8_t, uint32_t> &index,
- const std::string &filename
序列化多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<cagra::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset); const std::string filename = "mg_index.cuvs"; cuvs::neighbors::mg::serialize(handle, index, filename);
- 参数:
handle – [输入]
index – [输入] 预构建的索引
filename – [in] 要序列化的文件的路径
索引反序列化#
-
template<typename T, typename IdxT>
index<ivf_flat::index<T, IdxT>, T, IdxT> deserialize_flat( - const raft::device_resources &handle,
- const std::string &filename
反序列化 IVF-Flat 多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<ivf_flat::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset); const std::string filename = "mg_index.cuvs"; cuvs::neighbors::mg::serialize(handle, index, filename); auto new_index = cuvs::neighbors::mg::deserialize_flat<float, int64_t>(handle, filename);
- 参数:
handle – [输入]
filename – [in] 要反序列化的文件的路径
-
template<typename T, typename IdxT>
index<ivf_pq::index<IdxT>, T, IdxT> deserialize_pq( - const raft::device_resources &handle,
- const std::string &filename
反序列化 IVF-PQ 多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<ivf_pq::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset); const std::string filename = "mg_index.cuvs"; cuvs::neighbors::mg::serialize(handle, index, filename); auto new_index = cuvs::neighbors::mg::deserialize_pq<float, int64_t>(handle, filename);
- 参数:
handle – [输入]
filename – [in] 要反序列化的文件的路径
-
template<typename T, typename IdxT>
index<cagra::index<T, IdxT>, T, IdxT> deserialize_cagra( - const raft::device_resources &handle,
- const std::string &filename
反序列化 CAGRA 多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::mg::index_params<cagra::index_params> index_params; auto index = cuvs::neighbors::mg::build(handle, index_params, index_dataset); const std::string filename = "mg_index.cuvs"; cuvs::neighbors::mg::serialize(handle, index, filename); auto new_index = cuvs::neighbors::mg::deserialize_cagra<float, uint32_t>(handle, filename);
- 参数:
handle – [输入]
filename – [in] 要反序列化的文件的路径
分发预构建的本地索引#
-
template<typename T, typename IdxT>
index<ivf_flat::index<T, IdxT>, T, IdxT> distribute_flat( - const raft::device_resources &handle,
- const std::string &filename
将本地构建和序列化的 IVF-Flat 索引复制到所有 GPU,以形成分布式多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::ivf_flat::index_params index_params; auto index = cuvs::neighbors::ivf_flat::build(handle, index_params, index_dataset); const std::string filename = "local_index.cuvs"; cuvs::neighbors::ivf_flat::serialize(handle, filename, index); auto new_index = cuvs::neighbors::mg::distribute_flat<float, int64_t>(handle, filename);
- 参数:
handle – [输入]
filename – [in] 要反序列化的文件的路径:一个本地索引
-
template<typename T, typename IdxT>
index<ivf_pq::index<IdxT>, T, IdxT> distribute_pq( - const raft::device_resources &handle,
- const std::string &filename
将本地构建和序列化的 IVF-PQ 索引复制到所有 GPU,以形成分布式多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::ivf_pq::index_params index_params; auto index = cuvs::neighbors::ivf_pq::build(handle, index_params, index_dataset); const std::string filename = "local_index.cuvs"; cuvs::neighbors::ivf_pq::serialize(handle, filename, index); auto new_index = cuvs::neighbors::mg::distribute_pq<float, int64_t>(handle, filename);
- 参数:
handle – [输入]
filename – [in] 要反序列化的文件的路径:一个本地索引
-
template<typename T, typename IdxT>
index<cagra::index<T, IdxT>, T, IdxT> distribute_cagra( - const raft::device_resources &handle,
- const std::string &filename
将本地构建和序列化的 CAGRA 索引复制到所有 GPU,以形成分布式多 GPU 索引。
使用示例
raft::handle_t handle; cuvs::neighbors::cagra::index_params index_params; auto index = cuvs::neighbors::cagra::build(handle, index_params, index_dataset); const std::string filename = "local_index.cuvs"; cuvs::neighbors::cagra::serialize(handle, filename, index); auto new_index = cuvs::neighbors::mg::distribute_cagra<float, uint32_t>(handle, filename);
- 参数:
handle – [输入]
filename – [in] 要反序列化的文件的路径:一个本地索引