初学faiss,找了一些博客学习
使用faiss==1.5.3实验,发现faiss.index_factory(dim, param, measure) 方法的确存在指定inner product 失效的问题。
用faiss.IndexHNSWFlat(dim, x,faiss.METRIC_INNER_PRODUCT)这样会报错,
NotImplementedError: Wrong number or type of arguments for overloaded function ‘new_IndexHNSWFlat’.
Possible C/C++ prototypes are:
faiss::IndexHNSWFlat::IndexHNSWFlat()
faiss::IndexHNSWFlat::IndexHNSWFlat(int,int)
c++提示了!!!用faiss.IndexHNSWFlat(dim, x)
使用faiss.IndexHNSWFlat(dim, x)虽然可以,但是默认的measure 方式还是l2范数(准确说是平方和,未开根号的欧式距离,实验验证)
faiss HNSW索引构建方式应该是本身不支持内积。解决方式参考https://github.com/facebookresearch/faiss/wiki/MetricType-and-distances(多亏评论区)
(论文理论还没看,但demo代码可用)
reference
https://zhuanlan.zhihu.com/p/357414033
https://github.com/facebookresearch/faiss/wiki/MetricType-and-distances