-
Notifications
You must be signed in to change notification settings - Fork 202
Add HNSW Layered Index Support #2148
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
base: main
Are you sure you want to change the base?
Changes from 7 commits
52997da
a11d9ee
a95b0e0
47e2d85
21ce339
4514bc8
0e9accd
7a761cf
ea1a96c
153a82d
265206b
0e2d458
4513f6f
6d9b2c6
2bf44ea
002c373
1bed620
99b1320
a61b7cb
bb66010
d6e3ffa
8f067ed
ecb238e
1771f82
f1fdccc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2023-2025, NVIDIA CORPORATION. | ||
| * SPDX-FileCopyrightText: Copyright (c) 2023-2026, NVIDIA CORPORATION. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| #pragma once | ||
|
|
@@ -9,10 +9,26 @@ | |
| #include <raft/core/logger.hpp> | ||
|
|
||
| #include <chrono> | ||
| #include <filesystem> | ||
| #include <memory> | ||
|
|
||
| namespace cuvs::bench { | ||
|
|
||
| inline void copy_file_overwrite(const std::filesystem::path& src, const std::filesystem::path& dst) | ||
| { | ||
| std::error_code ec; | ||
| if (src == dst || | ||
| (std::filesystem::exists(dst, ec) && std::filesystem::equivalent(src, dst, ec))) { | ||
| return; | ||
| } | ||
| if (!dst.parent_path().empty()) { std::filesystem::create_directories(dst.parent_path()); } | ||
|
|
||
| std::filesystem::copy_file(src, dst, std::filesystem::copy_options::overwrite_existing, ec); | ||
| const auto src_str = src.string(); | ||
| const auto dst_str = dst.string(); | ||
| RAFT_EXPECTS(!ec, "Failed to copy '%s' to '%s'.", src_str.c_str(), dst_str.c_str()); | ||
| } | ||
|
|
||
| template <typename T, typename IdxT> | ||
| class cuvs_cagra_hnswlib : public algo<T>, public algo_gpu { | ||
| public: | ||
|
|
@@ -130,6 +146,18 @@ void cuvs_cagra_hnswlib<T, IdxT>::set_search_param(const search_param_base& para | |
| template <typename T, typename IdxT> | ||
| void cuvs_cagra_hnswlib<T, IdxT>::save(const std::string& file) const | ||
| { | ||
| if (build_param_.hnsw_index_params.hierarchy == | ||
| cuvs::neighbors::hnsw::HnswHierarchy::GPU_LAYERED_ON_DISK) { | ||
| const auto src_artifact = std::filesystem::path(hnsw_index_->file_path()); | ||
| RAFT_EXPECTS(!src_artifact.empty(), "Layered HNSW artifact path is not available."); | ||
| RAFT_EXPECTS(std::filesystem::exists(src_artifact), | ||
| "Layered HNSW artifact '%s' does not exist.", | ||
| src_artifact.c_str()); | ||
|
|
||
| copy_file_overwrite(src_artifact, std::filesystem::path(file)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we copy here instead of moving (like in the cagra_ace block below?)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, thanks. I've changed this and reuse the helper in the |
||
| return; | ||
| } | ||
|
|
||
| if (cagra_ace_build_) { | ||
| std::string index_filename = hnsw_index_->file_path(); | ||
| RAFT_EXPECTS(!index_filename.empty(), "HNSW index file path is not available."); | ||
|
|
||
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.
Are these all just synonyms for
GPU_LAYERED_ON_DISK?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.
Yes, I've removed them to better align with the other formats.