文件 IndexNNDescent.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
定义一些将变换应用于一组向量的对象。通常,这些是预处理步骤。
-
struct IndexNNDescent : public faiss::Index
- #include <IndexNNDescent.h>
NNDescent索引是一个正常的随机访问索引,其顶部构建了一个 NNDescent 链接结构
由 faiss::IndexNNDescentFlat 子类化
公共类型
-
using storage_idx_t = NNDescent::storage_idx_t
公共函数
-
explicit IndexNNDescent(int d = 0, int K = 32, MetricType metric = METRIC_L2)
-
~IndexNNDescent() override
-
virtual void add(idx_t n, const float *x) override
将维度为d的n个向量添加到索引中。
向量被隐式分配标签ntotal .. ntotal + n - 1。此函数将输入向量分割成小于blocksize_add的块,并调用add_core。
- 参数:
n – 向量的数量
x – 输入矩阵,大小为 n * d
-
virtual void search(idx_t n, const float *x, idx_t k, float *distances, idx_t *labels, const SearchParameters *params = nullptr) const override
搜索入口点
-
virtual void reconstruct(idx_t key, float *recons) const override
重建一个存储的向量(如果是近似编码,则为近似值)
对于某些索引,此函数可能未定义
- 参数:
key – 要重建的向量的ID
recons – 重建的向量(大小为d)
-
virtual void reset() override
从数据库中删除所有元素。
-
using storage_idx_t = NNDescent::storage_idx_t
-
struct IndexNNDescentFlat : public faiss::IndexNNDescent
- #include <IndexNNDescent.h>
带有 NNDescent 结构体的 Flat 索引,可以更有效地访问元素。
公共类型
-
using storage_idx_t = NNDescent::storage_idx_t
公共函数
-
IndexNNDescentFlat()
-
IndexNNDescentFlat(int d, int K, MetricType metric = METRIC_L2)
-
virtual void add(idx_t n, const float *x) override
将维度为d的n个向量添加到索引中。
向量被隐式分配标签ntotal .. ntotal + n - 1。此函数将输入向量分割成小于blocksize_add的块,并调用add_core。
- 参数:
n – 向量的数量
x – 输入矩阵,大小为 n * d
-
virtual void search(idx_t n, const float *x, idx_t k, float *distances, idx_t *labels, const SearchParameters *params = nullptr) const override
搜索入口点
-
virtual void reconstruct(idx_t key, float *recons) const override
重建一个存储的向量(如果是近似编码,则为近似值)
对于某些索引,此函数可能未定义
- 参数:
key – 要重建的向量的ID
recons – 重建的向量(大小为d)
-
virtual void reset() override
从数据库中删除所有元素。
-
using storage_idx_t = NNDescent::storage_idx_t
-
struct IndexNNDescent : public faiss::Index