文件 IndexShards.h
-
namespace faiss
实现了包含多种变体的 k-means 聚类算法。
版权所有 (c) Facebook, Inc. 及其附属公司。
此源代码根据 MIT 许可证授权,该许可证可在该源代码树的根目录中的 LICENSE 文件中找到。
IDSelector 旨在定义要处理的向量子集(用于移除或作为搜索的子集)
PQ4 SIMD 压缩和累积函数
基本内核使用 bbs = nb * 2 * 16 个向量累积 nq 查询向量,并为此生成一个输出矩阵。 对于 nq * nb <= 4 很有用,否则寄存器溢出变得太大。
这些函数的实现分布在 3 个 cpp 文件中,以减少并行编译时间。 模板被显式实例化。
此文件包含计算距离的内核的回调。
在整个库中,向量以 float * 指针的形式提供。 当多个向量在一个批次中一起处理(添加/搜索)时,大多数算法都可以得到优化。 在这种情况下,它们作为矩阵传入。 当大小为 d 的 n 个向量作为 float * x 提供时,向量 i 的分量 j 为
x[ i * d + j ]
其中 0 <= i < n 且 0 <= j < d。 换句话说,矩阵始终是紧凑的。 当指定矩阵的大小时,我们将其称为 n*d 矩阵,这意味着行优先存储。
I/O 函数可以读取/写入到文件名、文件句柄或抽象媒介的对象。
读取函数返回应该用 delete 释放的对象。 这些对象中的所有引用都归该对象所有。
倒排列表的定义 + 一些实现该接口的常用类。
由于 IVF(倒排文件)索引在大规模用例中非常有用,因此我们将与它们相关的一些函数分组到这个小库中。 大多数函数都适用于 IndexIVF 和嵌入在 IndexPreTransform 中的 IndexIVF。
此文件实现了 L2 和内积之外的额外度量标准
实现了一些神经网络层,主要用于支持 QINCo
定义了一些对向量集合应用变换的对象。 通常这些是预处理步骤。
类型定义
-
using IndexShards = IndexShardsTemplate<Index>
-
using IndexBinaryShards = IndexShardsTemplate<IndexBinary>
-
template<typename IndexT>
struct IndexShardsTemplate : public faiss::ThreadedIndex<IndexT> - #include <IndexShards.h>
Index,它连接了来自多个子索引的结果
公共类型
公共函数
-
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 作为维度具有隐式的 bool 转换歧义
-
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 确定:将调用 add_with_ids,传入的 xids 在分片上均匀分布
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) 与子索引中的数据同步
公共成员
-
bool successive_ids
-
explicit IndexShardsTemplate(bool threaded = false, bool successive_ids = true)
-
using IndexShards = IndexShardsTemplate<Index>