文件 residual_quantizer_encode_steps.h
-
namespace faiss
实现具有多种变体的 k-means 聚类。
版权所有 (c) Facebook, Inc. 及其附属公司。
此源代码根据此源代码树根目录中的 LICENSE 文件中找到的 MIT 许可证获得许可。
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
定义了一些将转换应用于一组向量的对象。 通常,这些是预处理步骤。
函数
-
void beam_search_encode_step(size_t d, size_t K, const float *cent, size_t n, size_t beam_size, const float *residuals, size_t m, const int32_t *codes, size_t new_beam_size, int32_t *new_codes, float *new_residuals, float *new_distances, Index *assign_index = nullptr, ApproxTopK_mode_t approx_topk = ApproxTopK_mode_t::EXACT_TOPK)
通过从质心表中采样来编码残差。
这是残差量化器的单个编码步骤。它允许对编码函数进行低级访问,主要为单元测试而公开。
- 参数:
n – 要处理的向量数
residuals – 要编码的向量,大小 (n, beam_size, d)
cent – 质心,大小 (K, d)
beam_size – 输入束大小
m – 先前编码步骤的代码大小
codes – 束的先前步骤的代码数组 (n, beam_size, m)
new_beam_size – 输出束大小(应 <= K * beam_size)
new_codes – 输出代码,大小 (n, new_beam_size, m + 1)
new_residuals – 输出残差,大小 (n, new_beam_size, d)
new_distances – 输出距离,大小 (n, new_beam_size)
assign_index – 如果非 NULL,将用于执行分配
-
void beam_search_encode_step_tab(size_t K, size_t n, size_t beam_size, const float *codebook_cross_norms, size_t ldc, const uint64_t *codebook_offsets, const float *query_cp, size_t ldqc, const float *cent_norms_i, size_t m, const int32_t *codes, const float *distances, size_t new_beam_size, int32_t *new_codes, float *new_distances, ApproxTopK_mode_t approx_topk = ApproxTopK_mode_t::EXACT_TOPK)
使用向量与码本的点积来编码一组向量
- 参数:
K – 码本中的向量数
n – 要编码的向量数
beam_size – 输入束大小
codebook_cross_norms – 此码本与先前编码的 m 个码本的内积
codebook_offsets – 每个先前码本的 codebook_cross_norms 中的偏移量
query_cp – 查询向量与 ??? 的点积
cent_norms_i – 质心的范数
-
namespace rq_encode_steps
函数
-
void refine_beam_mp(const ResidualQuantizer &rq, size_t n, size_t beam_size, const float *x, int out_beam_size, int32_t *out_codes, float *out_residuals, float *out_distances, RefineBeamMemoryPool &pool)
-
void refine_beam_LUT_mp(const ResidualQuantizer &rq, size_t n, const float *query_norms, const float *query_cp, int out_beam_size, int32_t *out_codes, float *out_distances, RefineBeamLUTMemoryPool &pool)
-
void compute_codes_add_centroids_mp_lut0(const ResidualQuantizer &rq, const float *x, uint8_t *codes_out, size_t n, const float *centroids, ComputeCodesAddCentroidsLUT0MemoryPool &pool)
-
void compute_codes_add_centroids_mp_lut1(const ResidualQuantizer &rq, const float *x, uint8_t *codes_out, size_t n, const float *centroids, ComputeCodesAddCentroidsLUT1MemoryPool &pool)
-
struct RefineBeamMemoryPool
公共成员
-
新的代码
-
新的残差
-
残差
-
代码
-
距离
-
新的代码
-
struct RefineBeamLUTMemoryPool
-
struct ComputeCodesAddCentroidsLUT0MemoryPool
-
struct ComputeCodesAddCentroidsLUT1MemoryPool
-
void refine_beam_mp(const ResidualQuantizer &rq, size_t n, size_t beam_size, const float *x, int out_beam_size, int32_t *out_codes, float *out_residuals, float *out_distances, RefineBeamMemoryPool &pool)
-
void beam_search_encode_step(size_t d, size_t K, const float *cent, size_t n, size_t beam_size, const float *residuals, size_t m, const int32_t *codes, size_t new_beam_size, int32_t *new_codes, float *new_residuals, float *new_distances, Index *assign_index = nullptr, ApproxTopK_mode_t approx_topk = ApproxTopK_mode_t::EXACT_TOPK)