结构体 faiss::IndexLocalSearchQuantizerFastScan
-
struct IndexLocalSearchQuantizerFastScan : public faiss::IndexAdditiveQuantizerFastScan
基于局部搜索量化器的索引。 存储的向量通过局部搜索量化码来近似。 也可以用作编解码器。
公共类型
-
using Search_type_t = AdditiveQuantizer::Search_type_t
-
using component_t = float
-
using distance_t = float
公共函数
-
IndexLocalSearchQuantizerFastScan(int d, size_t M, size_t nbits, MetricType metric = METRIC_L2, Search_type_t search_type = AdditiveQuantizer::ST_norm_lsq2x4, int bbs = 32)
构造函数。
- 参数:
d – 输入向量的维度
M – 子量化器的数量
nbits – 每个子向量索引的位数
d – 输入向量的维度
M – 子量化器的数量
nbits – 每个子向量索引的位数
metric – 度量类型
search_type – AQ 搜索类型
-
IndexLocalSearchQuantizerFastScan()
-
void init(AdditiveQuantizer *aq, MetricType metric = METRIC_L2, int bbs = 32)
-
virtual void train(idx_t n, const float *x) override
对有代表性的向量集执行训练
- 参数:
n – 训练向量的数量
x – 训练向量,大小为 n * d
-
void estimate_norm_scale(idx_t n, const float *x)
-
virtual void compute_codes(uint8_t *codes, idx_t n, const float *x) const override
-
virtual void compute_float_LUT(float *lut, idx_t n, const float *x) const override
-
virtual void search(idx_t n, const float *x, idx_t k, float *distances, idx_t *labels, const SearchParameters *params = nullptr) const override
查询索引中n个维度为d的向量。
最多返回k个向量。 如果查询的结果不足,则结果数组将填充-1。
- 参数:
n – 向量数
x – 要搜索的输入向量,大小为 n * d
k – 提取的向量数
distances – 输出成对距离,大小为 n*k
labels – 输出NN的标签,大小为 n*k
-
virtual void sa_decode(idx_t n, const uint8_t *bytes, float *x) const override
解码一组向量。
注意:IndexAdditiveQuantizerFastScan 对象中的代码不是连续的。但是此方法需要连续的表示。
- 参数:
n – 向量数
bytes – 输入编码向量,大小为 n * code_size
x – 输出向量,大小为 n * d
-
void init_fastscan(int d, size_t M, size_t nbits, MetricType metric, int bbs)
-
virtual void reset() 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
-
void compute_quantized_LUT(idx_t n, const float *x, uint8_t *lut, float *normalizers) const
-
template<bool is_max>
void search_dispatch_implem(idx_t n, const float *x, idx_t k, float *distances, idx_t *labels, const NormTableScaler *scaler) const
-
template<class Cfloat>
void search_implem_234(idx_t n, const float *x, idx_t k, float *distances, idx_t *labels, const NormTableScaler *scaler) const
-
template<class C>
void search_implem_12(idx_t n, const float *x, idx_t k, float *distances, idx_t *labels, int impl, const NormTableScaler *scaler) const
-
template<class C>
void search_implem_14(idx_t n, const float *x, idx_t k, float *distances, idx_t *labels, int impl, const NormTableScaler *scaler) const
-
virtual void reconstruct(idx_t key, float *recons) const override
重构一个存储的向量(如果是有损编码,则是近似值)
对于某些索引,此函数可能未定义
- 参数:
key – 要重构的向量的 id
recons – 重构的向量(大小为 d)
-
virtual size_t remove_ids(const IDSelector &sel) override
从索引中删除 ID。并非所有索引都支持。 返回已删除的元素数量。
-
CodePacker *get_CodePacker() const
-
virtual void merge_from(Index &otherIndex, idx_t add_id = 0) override
将条目从另一个数据集移动到 self。 在输出时,other 为空。 add_id 添加到所有移动的 id(对于连续 id,这将是 this->ntotal)
-
virtual void check_compatible_for_merge(const Index &otherIndex) const override
检查两个索引是否兼容(即,它们以相同的方式训练并且具有相同的参数)。 否则抛出异常。
-
virtual void add_with_ids(idx_t n, const float *x, const idx_t *xids)
与 add 相同,但存储 xids 而不是连续的 id。
默认实现失败并出现断言,因为它并非所有索引都支持。
- 参数:
n – 向量数
x – 输入向量,大小为 n * d
xids – 如果不为空,则为要存储的向量的 id(大小为 n)
-
virtual void range_search(idx_t n, const float *x, float radius, RangeSearchResult *result, const SearchParameters *params = nullptr) const
查询索引中n个维度为d的向量。
返回所有距离 < radius 的向量。 请注意,许多索引未实现 range_search(只有 k-NN 搜索是强制性的)。
- 参数:
n – 向量数
x – 要搜索的输入向量,大小为 n * d
radius – 搜索半径
result – 结果表
-
virtual void assign(idx_t n, const float *x, idx_t *labels, idx_t k = 1) const
返回与查询 x 最接近的 k 个向量的索引。
此函数与搜索相同,但仅返回邻居的标签。
- 参数:
n – 向量数
x – 要搜索的输入向量,大小为 n * d
labels – 输出NN的标签,大小为 n*k
k – 最近邻的数量
-
virtual void reconstruct_batch(idx_t n, const idx_t *keys, float *recons) const
重构多个存储的向量(如果是有损编码,则是近似值)
对于某些索引,此函数可能未定义
- 参数:
n – 要重构的向量的数量
keys – 要重构的向量的 id(大小为 n)
recons – 重构的向量(大小为 n * d)
-
virtual void reconstruct_n(idx_t i0, idx_t ni, float *recons) const
重构向量 i0 到 i0 + ni - 1
对于某些索引,此函数可能未定义
- 参数:
i0 – 序列中第一个向量的索引
ni – 序列中向量的数量
recons – 重构的向量(大小为 ni * d)
-
virtual void search_and_reconstruct(idx_t n, const float *x, idx_t k, float *distances, idx_t *labels, float *recons, const SearchParameters *params = nullptr) const
与搜索类似,但也为搜索结果重建存储的向量(或在有损编码的情况下进行近似)。
如果查询结果不足,则结果数组将填充 -1。
- 参数:
n – 向量数
x – 要搜索的输入向量,大小为 n * d
k – 提取的向量数
distances – 输出成对距离,大小为 n*k
labels – 输出NN的标签,大小为 n*k
recons – 重建的向量大小 (n, k, d)
-
virtual void compute_residual(const float *x, float *residual, idx_t key) const
计算索引编码后的残差向量。
残差向量是向量与可以从其在索引中的表示形式解码的重建之间的差。残差可用于多阶段索引方法,例如IndexIVF的方法。
- 参数:
x – 输入向量,大小为 d
residual – 输出残差向量,大小为 d
key – 编码后的索引,由搜索和分配返回
-
virtual void compute_residual_n(idx_t n, const float *xs, float *residuals, const idx_t *keys) const
计算索引编码后的残差向量(批量形式)。 等效于为每个向量调用 compute_residual。
残差向量是向量与可以从其在索引中的表示形式解码的重建之间的差。残差可用于多阶段索引方法,例如IndexIVF的方法。
- 参数:
n – 向量数
xs – 输入向量,大小 (n x d)
residuals – 输出残差向量,大小 (n x d)
keys – 编码后的索引,由搜索和分配返回
-
virtual DistanceComputer *get_distance_computer() const
为此类索引获取一个DistanceComputer (在 AuxIndexStructures 中定义) 对象。
对于支持随机访问其向量的索引,实现了 DistanceComputer。
-
virtual size_t sa_code_size() const
生成的代码的大小(以字节为单位)
-
virtual void sa_encode(idx_t n, const float *x, uint8_t *bytes) const
编码一组向量
- 参数:
n – 向量数
x – 输入向量,大小为 n * d
bytes – 输出编码后的向量,大小 n * sa_code_size()
-
virtual void add_sa_codes(idx_t n, const uint8_t *codes, const idx_t *xids)
添加使用独立编解码器计算的向量
- 参数:
codes – 要添加的代码,大小为 n * sa_code_size()
xids – 对应的 ID,大小为 n
公共成员
-
是否重新缩放范数 = true
-
范数缩放比例 = 1
-
最大训练点数 = 0
-
实现方式 = 0
-
跳过 = 0
-
块大小(用于数据库向量)
-
块大小(用于查询向量) = 0
-
子向量的数量
-
每个子向量的代码位数
-
每个子向量的聚类数量
-
每个向量的代码大小(以字节为单位)
-
索引的向量数量的另一个副本
-
子向量数量的另一个副本
-
数据库向量的代码
-
原始数据库向量的代码 = nullptr
-
向量维度
向量维度
-
索引向量的总数量
索引向量的总数量
-
详细程度
详细程度
-
此索引用于搜索的度量类型
此索引用于搜索的度量类型
-
度量类型的参数
度量类型的参数
-
using Search_type_t = AdditiveQuantizer::Search_type_t