结构体 faiss::IndexShardsTemplate
-
template<typename IndexT>
struct IndexShardsTemplate : public faiss::ThreadedIndex<IndexT> 将多个子索引的结果串联起来的Index
公共类型
-
using component_t = typename IndexT::component_t
-
using distance_t = typename IndexT::distance_t
公共函数
-
explicit IndexShardsTemplate(bool threaded = false, bool successive_ids = true)
所有子索引必须共享的维度将是添加的第一个子索引的维度
- 参数:
threaded – 我们是否为每个 sub_index 使用一个线程,或者按顺序查询?
successive_ids – 我们是否应该将返回的 ID 移动每个子索引的大小,或者按原样返回它们?
-
explicit IndexShardsTemplate(idx_t d, bool threaded = false, bool successive_ids = true)
- 参数:
threaded – 我们是否为每个 sub_index 使用一个线程,或者按顺序查询?
successive_ids – 我们是否应该将返回的 ID 移动每个子索引的大小,或者按原样返回它们?
-
explicit IndexShardsTemplate(int d, bool threaded = false, bool successive_ids = true)
int 版本是由于 int 作为维度的隐式布尔转换歧义
-
inline void add_shard(IndexT *index)
别名为 addIndex()
-
inline void remove_shard(IndexT *index)
别名为 removeIndex()
-
void add(idx_t n, const component_t *x) override
仅支持实现 add_with_ids 的子索引
-
void add_with_ids(idx_t n, const component_t *x, const idx_t *xids) override
情况(successive_ids,xids)
true,非 NULL 错误:传入 ID 并要求它们被移动是没有意义的
true,NULL 确定:但应该只调用一次(在子索引上调用 add())。
false,非 NULL 确定:将使用均匀分布在分片上的传入 xids 调用 add_with_ids
false,NULL 确定:将在每个子索引上调用 add_with_ids,从 ntotal 开始
-
void search(idx_t n, const component_t *x, idx_t k, distance_t *distances, idx_t *labels, const SearchParameters *params = nullptr) const override
-
void train(idx_t n, const component_t *x) override
-
virtual void syncWithSubIndexes()
将顶级索引(IndexShards)与子索引中的数据同步
-
virtual void addIndex(IndexT *index)
覆盖由我们自己管理的索引。警告:一旦添加了索引,在关闭之前,从管理它的线程之外的任何其他线程触摸它都是不安全的。请改用 runOnIndex 在其上执行工作。
-
void removeIndex(IndexT *index)
删除由我们自己管理的索引。这将刷新该索引上的所有挂起工作,然后关闭其管理线程,并删除该索引。
-
void reset() override
faiss::Index API 所有索引都收到相同的调用
-
inline int count() const
返回子索引的数量。
-
inline IndexT *at(size_t i)
返回第 i 个子索引。
-
inline const IndexT *at(size_t i) const
返回第 i 个子索引(const 版本)
公共成员
-
bool successive_ids
-
bool own_indices = false
我们是否负责删除我们包含的索引。
保护函数
-
virtual void onAfterAddIndex(IndexT *index) override
在添加索引之后立即调用。
-
virtual void onAfterRemoveIndex(IndexT *index) override
在删除索引之后立即调用。
-
using component_t = typename IndexT::component_t