Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
CosineExpanded Metric for IVF-PQ (normalize inputs) #346
CosineExpanded Metric for IVF-PQ (normalize inputs) #346
Changes from 7 commits
6aa64e8
5eae823
c9b800c
0a860d4
55c17fd
e3490e3
be343be
f3b50e4
56bbed0
3967c4c
442d65e
3ab1c7f
6b93282
bd41e20
ca240ac
69d1edf
6b3c953
edbda6c
28a48d1
8f93ab3
75209a2
fca5d94
ecf6dc4
4bb816c
3ecda59
076a60c
a943f6a
8c9d7be
ba660ce
bcefbe3
496ff5c
59fbb5e
490e6d2
932ae8a
eac9bba
c6912ec
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cuvs::cluster::kmeans_balanced::predict
Already supports Cosine metric, so there is no need to add normalization + switch to inner productThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I tried that. I also tried normalizing the cluster centers, but that does not give good recall. I get the best recall when I normalize the inputs and use inner product.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cuvs::cluster::kmeans_balanced::fit
Already supports Cosine metric, so there is no need to add normalization + switch to inner product.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As @achirkin noted, the norms of the centers and of the queries should be accounted for when computing the cosine distance. Right now only the norms of the queries is used, and this can result in the wrong clusters getting selected.
In IVF-Flat: https://github.com/rapidsai/cuvs/blob/branch-24.10/cpp/src/neighbors/ivf_flat/ivf_flat_search.cuh#L166
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to do that, but that gives poorer recall. Simply using inner product to select the clusters to probe gives better recall in the tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Among all of the things that I tried, normalizing the dataset and queries and using inner product directly works the best.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get it. What's the difference to the inner product here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should choose which clusters to probe using cosine distance.