Skip to content
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

Support graph-based approximate nearest neighbors search (cagra on nn_descent/ivf_pq) #714

Merged
merged 15 commits into from
Sep 3, 2024

Conversation

lijinf2
Copy link
Collaborator

@lijinf2 lijinf2 commented Aug 21, 2024

No description provided.

@lijinf2
Copy link
Collaborator Author

lijinf2 commented Aug 21, 2024

build

@lijinf2 lijinf2 changed the title Support graph-based approximate nearest neighbors search (cagra and nn_descent) Support graph-based approximate nearest neighbors search (cagra on nn_descent/ivf_pq) Aug 21, 2024
@lijinf2
Copy link
Collaborator Author

lijinf2 commented Aug 21, 2024

build

* intermediate_graph_degree: (int, default = 128) an intermediate variable used during graph index construction
* graph_degree: (int, default = 64) the degree of each node in the final graph index

parameters for search, full list in cuvs python API documentation.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great to have a clickable link (in our api docs github pages site) to this. Let's make a note to add one in the future. Need to figure how to do it in Sphinx.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, added the link and tested new docs locally.

parameters for index construction
* build_algo: (str, default = 'ivf_pq') algorithm to build graph index, can be either 'ivf_pq' or 'nn_descent'. nn_descent is expected to be generally faster than ivf_pq.
* intermediate_graph_degree: (int, default = 128) an intermediate variable used during graph index construction
* graph_degree: (int, default = 64) the degree of each node in the final graph index
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this related to the top level topk parameter? If so, should not be exposed (nor documented) separately and should be set in our code based on the top level parameter.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems irrelevant that can be set independently, as I can understand.

graph_degree is the number of neighbors of every node in the final graph index. It is used in the index construction phase to control the size of graph index.

topk is used in the search phase to control the number of returned neighbors.

When a query visits a node of the graph index, all of its neighbors will be evaluated to update the current topk results. A larger graph_degree should be helpful for a given k, and the two parameters can be set independently.

* graph_degree: (int, default = 64) the degree of each node in the final graph index

parameters for search, full list in cuvs python API documentation.
* itopk_size: (int, default = 64) number of intermediate search results retained during the search. Larger value improves the search accuracy but increases the search time.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the intermediate topk related params need to be no smaller than the top level one? Our code should enforce/set this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, added validation on the itopk_size parameter. cuml increases the value to the nearest multiple of 32 and requires the value to be larger than or equal to k.

@lijinf2
Copy link
Collaborator Author

lijinf2 commented Aug 27, 2024

build

Copy link
Collaborator

@eordentlich eordentlich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Minor comment.

internal_topk_size = math.ceil(itopk_size / 32) * 32
if internal_topk_size < topk:
raise ValueError(
f"cuVS increases itopk_size to be closest multiple of 32 and expects the value, i.e. {internal_topk_size}, to be larger than or equal to k, i.e. {topk})."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is more correct to say cagra increase?

n_neighbors = 50
error_msg = ""
if internal_topk_size < n_neighbors:
error_msg = f"cuVS increases itopk_size to be closest multiple of 32 and expects the value, i.e. {internal_topk_size}, to be larger than or equal to k, i.e. {n_neighbors}."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@lijinf2
Copy link
Collaborator Author

lijinf2 commented Aug 30, 2024

build

Copy link
Collaborator

@eordentlich eordentlich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@lijinf2 lijinf2 merged commit 801024e into NVIDIA:branch-24.08 Sep 3, 2024
2 checks passed
@lijinf2 lijinf2 deleted the cagra branch September 3, 2024 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants