-
Notifications
You must be signed in to change notification settings - Fork 184
Improved CAGRA build parameter heuristics #1448
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
Merged
Merged
Changes from 15 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
d93331c
Add the new heuristics as static factory functions of cagra::index_pa…
achirkin e758a0c
Mark new implementations inline to avoid duplicate symbols
achirkin e873d3a
Add the new functions to the C API
achirkin b8f9781
Merge branch 'main' into fea-cagra-hnsw-heuristics
achirkin f15c01a
Merge branch 'main' into fea-cagra-hnsw-heuristics
achirkin cb06d5a
Fix types in C wrapper code
achirkin 582db6f
CagraIndexParams from C/Cpp heuristics
ldematte d0ddb1e
Put the new non-template functions in a separate compilation unit
achirkin 8f0605b
Merge branch 'main' into fea-cagra-hnsw-heuristics
achirkin be3f901
Fix headers
achirkin 5fa89d5
Merge branch 'main' into fea-cagra-hnsw-heuristics
achirkin ed73a65
Merge branch 'main' into fea-cagra-hnsw-heuristics
achirkin 927d206
Merge remote-tracking branch 'rapidsai/main' into fea-cagra-hnsw-heur…
achirkin 15786b7
Fix bad code merge
achirkin da8aa38
Make one function out of two
achirkin 3671205
Put C++ helpers in C API implementation in the the unnamed namespace
achirkin 8b4299e
Undo accidental comment reflow
achirkin 9b33fb7
Add documentation to the java wrapper
achirkin 6904106
Prefix the enum value in the C api in lieu of C++ namespaces
achirkin 21dcc9f
Merge branch 'main' into fea-cagra-hnsw-heuristics
achirkin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #include <cuvs/distance/distance.hpp> | ||
| #include <cuvs/neighbors/cagra.hpp> | ||
|
|
||
| #include <cuvs/neighbors/common.hpp> | ||
|
|
||
| namespace cuvs::neighbors::cagra { | ||
|
|
||
| inline auto graph_params_heuristic(raft::matrix_extent<int64_t> dataset, | ||
| int intermediate_graph_degree, | ||
| int ef_construction, | ||
| cuvs::distance::DistanceType metric) | ||
| -> decltype(index_params::graph_build_params) | ||
| { | ||
| if (dataset.extent(0) < int64_t(1e6)) { | ||
| // Use NN descent for smaller datasets | ||
| auto nn_descent_params = | ||
| graph_build_params::nn_descent_params(intermediate_graph_degree, metric); | ||
| nn_descent_params.max_iterations = 5 + ef_construction / 16; | ||
| return nn_descent_params; | ||
| } else { | ||
| // Otherwise, use IVF-PQ | ||
| auto ivf_pq_params = cuvs::neighbors::graph_build_params::ivf_pq_params(dataset, metric); | ||
| ivf_pq_params.search_params.n_probes = | ||
| std::round(2 + std::sqrt(ivf_pq_params.build_params.n_lists) / 20 + ef_construction / 16); | ||
| return ivf_pq_params; | ||
| } | ||
| } | ||
|
|
||
| cagra::index_params index_params::from_hnsw_params(raft::matrix_extent<int64_t> dataset, | ||
| int M, | ||
| int ef_construction, | ||
| hnsw_heuristic_type heuristic, | ||
| cuvs::distance::DistanceType metric) | ||
| { | ||
| cagra::index_params params; | ||
| switch (heuristic) { | ||
| case hnsw_heuristic_type::SAME_GRAPH_FOOTPRINT: | ||
| params.graph_degree = M * 2; | ||
| params.intermediate_graph_degree = M * 3; | ||
| break; | ||
| case hnsw_heuristic_type::SIMILAR_SEARCH_PERFORMANCE: | ||
| default: | ||
| params.graph_degree = 2 + M * 2 / 3; | ||
| params.intermediate_graph_degree = M + M * ef_construction / 256; | ||
| break; | ||
| } | ||
| params.graph_build_params = | ||
| graph_params_heuristic(dataset, params.intermediate_graph_degree, ef_construction, metric); | ||
| return params; | ||
| } | ||
|
|
||
| } // namespace cuvs::neighbors::cagra |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.