命名空间 faiss::ivflib
-
namespace ivflib
函数
-
void check_compatible_for_merge(const Index *index1, const Index *index2)
检查两个索引是否具有相同的参数并以相同的方式进行训练,否则抛出异常。
-
const IndexIVF *extract_index_ivf(const Index *index)
从索引获取 IndexIVF。 索引可以是 IndexIVF 或包含 IndexIVF 的一些包装类
如果不是这种情况,则抛出异常。
-
void merge_into(Index *index0, Index *index1, bool shift_ids)
将 index1 合并到 index0 中。适用于 IndexIVF 和嵌入在 IndexPreTransform 中的 IndexIVF。 输出时,index1 为空。
- 参数:
shift_ids – 将 id 从 index1 转换为 index0->prev_ntotal
-
void search_and_return_centroids(Index *index, size_t n, const float *xin, long k, float *distances, idx_t *labels, idx_t *query_centroid_ids, idx_t *result_centroid_ids)
-
ArrayInvertedLists *get_invlist_range(const Index *index, long i0, long i1)
获取倒排列表的子集 [i0, i1)
-
void set_invlist_range(Index *index, long i0, long i1, ArrayInvertedLists *src)
设置倒排列表的子集。
-
void search_with_parameters(const Index *index, idx_t n, const float *x, idx_t k, float *distances, idx_t *labels, const IVFSearchParameters *params, size_t *nb_dis = nullptr, double *ms_per_stage = nullptr)
使用给定的参数搜索 IndexIVF,可能嵌入在 IndexPreTransform 中。 这是一种以线程安全的方式设置 nprobe 并获取统计数据的方法。
可选地返回(如果非空):
nb_dis: 计算的距离数量
ms_per_stage: [0]: 预处理时间 [1]: 粗量化, [2]: 列表扫描
-
void range_search_with_parameters(const Index *index, idx_t n, const float *x, float radius, RangeSearchResult *result, const IVFSearchParameters *params, size_t *nb_dis = nullptr, double *ms_per_stage = nullptr)
与 search_with_parameters 相同,但用于范围搜索
-
IndexIVFResidualQuantizer *ivf_residual_from_quantizer(const ResidualQuantizer&, int nlevel)
从 ResidualQuantizer 构建 IndexIVFResidualQuantizer,使用 nlevel 作为粗量化器的第一个组件,其余组件作为倒排列表中的代码
-
void ivf_residual_add_from_flat_codes(IndexIVFResidualQuantizer *ivfrq, size_t ncode, const uint8_t *codes, int64_t code_size = -1)
从代码添加。 注意:不使用 norm 组件,因此可以提供 code_size。
- 参数:
ivfrq – 要用代码填充的索引
codes – 要添加的代码,大小 (ncode, code_size)
code_size – 覆盖 ivfrq 的 code_size,如果 norm 编码不同,则很有用
-
struct SlidingIndexWindow
- #include <IVFlib.h>
一组以 FIFO 方式连接在一起的 IndexIVF。 在每个“步骤”中,删除最旧的索引切片并添加新的索引。
Public Functions
-
SlidingIndexWindow(Index *index)
索引最初应该是空的并经过训练
-
void step(const Index *sub_index, bool remove_oldest)
将一个索引添加到当前索引并删除最旧的索引。
- 参数:
sub_index – 要换入的切片(可以为 NULL)
remove_oldest – 如果为 true,则删除最旧的切片
Public Members
-
Index *index
包含滑动窗口的公共索引
-
ArrayInvertedLists *ils
索引的 InvertedLists。
-
int n_slice
当前索引中的切片数
-
size_t nlist
与 index->nlist 相同
-
SlidingIndexWindow(Index *index)
-
void check_compatible_for_merge(const Index *index1, const Index *index2)