File InvertedListsIOHook.h

namespace faiss

具有多种变体的k-means聚类算法的实现。

版权所有 (c) Facebook, Inc. 及其附属公司。

此源代码根据 LICENSE 文件中的 MIT 许可证获得许可,该文件位于此源树的根目录中。

IDSelector 旨在定义要处理的向量子集(用于删除或作为搜索的子集)

PQ4 SIMD 打包和累积函数

基本内核使用 bbs = nb * 2 * 16 个向量累积 nq 查询向量,并生成该输出矩阵。 对于 nq * nb <= 4 很有趣,否则寄存器溢出变得太大。

这些函数的实现分布在 3 个 cpp 文件中,以减少并行编译时间。 模板被显式实例化。

此文件包含用于计算距离的内核的回调。

在整个库中,向量以 float * 指针的形式提供。 当在一批中一起处理(添加/搜索)多个向量时,大多数算法都可以优化。 在这种情况下,它们作为矩阵传入。 当 n 个大小为 d 的向量作为 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 InvertedListsIOHook
#include <InvertedListsIOHook.h>

用于处理其他类型的 InvertedList 对象的回调。

回调应在调用 read_index 或 read_InvertedLists 之前通过 add_callback 注册。 OnDiskInvertedLists 的回调默认注册。 invlist 类型由以下项标识:

  • 读取时的键 (a fourcc)

  • 写入时的类名(由 typeid.name 给出)

faiss::BlockInvertedListsIOHook, faiss::OnDiskInvertedListsIOHook 继承

公共函数

InvertedListsIOHook(const std::string &key, const std::string &classname)
virtual void write(const InvertedLists *ils, IOWriter *f) const = 0

将索引写入 IOWriter (包括 fourcc)

virtual InvertedLists *read(IOReader *f, int io_flags) const = 0

当 fourcc 与此类的 fourcc 匹配时调用

virtual InvertedLists *read_ArrayInvertedLists(IOReader *f, int io_flags, size_t nlist, size_t code_size, const std::vector<size_t> &sizes) const

ArrayInvertedLists 读取到此倒排列表类型中。 为了使其工作,必须启用回调,并且 io_flag 必须设置为 IO_FLAG_SKIP_IVF_DATA | (fourcc 的 16 个高位)

(默认实现失败)

inline virtual ~InvertedListsIOHook()

公共成员

const std::string key

fourcc 的字符串版本

const std::string classname

typeid.name

公共静态函数

static void add_callback(InvertedListsIOHook*)
static void print_callbacks()
static InvertedListsIOHook *lookup(int h)
static InvertedListsIOHook *lookup_classname(const std::string &classname)