索引= faiss.IndexFlatL2(vectormatrix.shape1)
打印(index.is_trained)
Faiss.normalize_L2(向量矩阵)
Index.add(向量矩阵)
打印(index.ntotal)
距离,索引=index.Search(token_vector.reshape(1,token_vector.size)),k)
发布于 2022-11-16 06:27:57
我有几乎相同的问题,但内部产品。距离应该在范围内(-1;1),但我有100或200这样的值。
%%time
k = 255
dim = X.shape[1]
quantiser = faiss.IndexFlatIP(dim)
index = faiss.IndexIVFFlat(quantiser, dim, k)
faiss.normalize_L2(X)
index.train(X)
index.add(X)
sample = ['some text']
query = scipy.sparse.csr_matrix.toarray(vectorizer.transform(sample)).astype('float32')
index.nprobe=100
D, I = index.search(query, 10)
print(D[0])
> array([73.49516 , 73.504524, 73.75489 , 73.767204, 73.78795 ,
> 73.800064, 73.80722 , 73.82175 , 73.94714 , 74.034 ], dtype=float32)我现在正努力解决这个问题
将faiss.METRIC_INNER_PRODUCT作为参数添加到faiss.IndexIVFFlat()中部分解决了我的问题
https://stackoverflow.com/questions/74095910
复制相似问题