Closed salmanmashayekh closed 1 year ago
search method of a faiss index returns L2 distances, rather than similarities. But the following line in pack_single_result assumes similarities:
search
faiss
pack_single_result
results = [(self.index["sentences"][i], s) for i, s in zip(idx, dist) if s >= threshold]
I think it should change to the following:
results = [(self.index["sentences"][i], d) for i, d in zip(idx, dist) if d <= threshold]
Note the <= vs >= in the list comprehension.
<=
>=
Alternatively, we can change the metric_type to use cosine similarity instead of L2 distance:
metric_type
index.metric_type = faiss.METRIC_INNER_PRODUCT
Hi thanks for reporting this! It only occurs when using fast faiss and now this problem has been fixed!
search
method of afaiss
index returns L2 distances, rather than similarities. But the following line inpack_single_result
assumes similarities:I think it should change to the following:
Note the
<=
vs>=
in the list comprehension.Alternatively, we can change the
metric_type
to use cosine similarity instead of L2 distance: