水文: 待完善
一、简介
faiss是用来做召回的, facebook出品, 内置HNSW{占用内存巨大}以及一些基于倒排索引和聚类的算法, 基于向量做的召回.
基于向量做召回的还有annoy.
更多参考: https://zhuanlan.zhihu.com/p/37381294
二、推荐博客
-
https://zhuanlan.zhihu.com/p/357414033
这个文章很不错: 需要注意的一点:IVFx中的x是k-means聚类中心的个数; PQx中的x为将向量切分的段数,因此,x需要能被向量维度整除.
使用PQ的时候,如果要用到GPU. 对向量维度也有要求!!但是我也还没弄明白
三、常见问题
3.1 安装:
faiss的安装不能直接pip install faiss
会出错的.
应该参考这个的:https://github.com/facebookresearch/faiss/issues/821
比如: conda install faiss-gpu cudatoolkit=11.0 -c pytorch
无脑copy遇bug. {据说:这么安装会遇到3.3的问题,我遇到了. }
3.2 【faiss】TypeError: in method ‘IndexFlat_add’, argument 3 of type ‘float const *’
faiss使用的数据类型是float32
,所以如果数据类型是float64
会报错.
使用以下代码转换:
arr = arr.astype("float32")
3.3 Intel MKL FATAL ERROR: Cannot load libmkl_avx2.so or libmkl_def.so.
- 安装:
conda install mkl
conda install mkl-service
- 代码中加入:
import mkl
mkl.get_max_threads()
import faiss
3.4 IndexPreTransform.cpp:163: Error: ‘is_trained’ failed
使用index_factory构建的话, add之前是需要train的.