faiss icon indicating copy to clipboard operation
faiss copied to clipboard

Why is the cosine similarity > 1?

Open MrHwc opened this issue 7 years ago • 3 comments

faiss.normalize_L2(feature)
faiss.normalize_L2(query_vector)

index = faiss.IndexFlatIP(feature.shape[1])
index = faiss.IndexIDMap2(index)
index.add_with_ids(feature, label)
simi, ID = index.search(query_vector, k)

Why the result will be greater than 1? eg:

1.0000001192092896, 0.4944802522659302, 0.46121683716773987
0.9999998807907104, 0.785945475101471, 0.7602823972702026

MrHwc avatar Aug 16 '19 09:08 MrHwc

Hi @MrHwc, I can reproduce the same issue. Is this a numerical overflow problem?

elopezz avatar Oct 25 '21 10:10 elopezz

I'm having the same problem. @MrHwc @elopezz How do you guys address this problem?

nbui-sc avatar Aug 12 '24 19:08 nbui-sc

Yes, it's numerical overflow problem for me.

nbui-sc avatar Aug 12 '24 19:08 nbui-sc