-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does Faiss distance function support cosine distance? #593
Comments
This seems like a duplicate of #95. The cosine distance is obtained with the inner product after normalizing all vectors to unit norm. |
Thanks Eduardo! Does that mean if I want to use cosine similarity, I need to convert both the query vectors and the centroids vectors to unit vector beforehand? |
That is correct. |
Thanks for your quick reply. And I will try to add cosine distance option to faiss, since sometimes the input vectors are not unit vectors and converting them beforehand on CPU cost more time. |
@Qiaogx please don't spend effort on that. Anything you can do will be more expensive than normalizing the vectors. |
Hi Matthijs, When using cosine similarity, except normalizing the query and centroid vectors, are there any other factors I need to pay attention to? I normalized the vectors and set l2Distance_ to False in faiss/gpu/impl/FlatIndex.cu, but It did not work. Thanks. |
this works.
|
Thank you@liqima. However, it seems IndexIVFPQ does not fully support inner product. |
Inner product con IndexIVFPQ is fully supported on CPU, otherwise it is a bug. |
No activity. Closing. |
Hi,@Qiaogx,can you tell me how do you achieve the cosine distance? normalized vector or other ways? |
Note that there is now a FAQ entry for this question: |
This is the updated link: |
Thanks! updated the link above to avoid confusion. |
Note that normalizing the vectors before K-means, and the cluster centers after K-means, is not quite the same as cosine-sim K-means. |
Currently, I see faiss support L2 distance and inner product distance. My question is whether faiss distance function support cosine distance.
Thanks.
Gary
Summary
Platform
OS:
Faiss version:
Faiss compilation options:
Running on:
Interface:
Reproduction instructions
The text was updated successfully, but these errors were encountered: