-
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
Open
julianmi
wants to merge
25
commits into
NVIDIA:main
Choose a base branch
from
julianmi:hnsw-layered-index
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 15 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
52997da
Add HNSW layered hierarchy
julianmi a11d9ee
Improve deserialization logging
julianmi a95b0e0
Use ace prefix in benchmarking consistently
julianmi 47e2d85
Validate metadata before allocating
julianmi 21ce339
Store layered base topology by original node ID
julianmi 4514bc8
Unify the ACE logging format
julianmi 0e9accd
Merge branch 'main' into hnsw-layered-index
julianmi 7a761cf
Address review feedback
julianmi ea1a96c
Replace JSON header with binary header
julianmi 153a82d
Merge branch 'main' into hnsw-layered-index
julianmi 265206b
Merge branch 'main' into hnsw-layered-index
julianmi 0e2d458
Merge branch 'main' into hnsw-layered-index
julianmi 4513f6f
Merge branch 'main' into hnsw-layered-index
julianmi 6d9b2c6
Address coderabbit comments
julianmi 2bf44ea
Fix half type numpy conversions
julianmi 002c373
Make numpy helpers private
julianmi 1bed620
C deserialization should accept f2 numpy half type
julianmi 99b1320
Merge branch 'main' of https://github.com/NVIDIA/cuvs into hnsw-layer…
julianmi a61b7cb
Merge branch 'main' into hnsw-layered-index
julianmi bb66010
Merge branch 'main' into hnsw-layered-index
julianmi d6e3ffa
Merge branch 'main' into hnsw-layered-index
julianmi 8f067ed
Merge branch 'main' into hnsw-layered-index
julianmi ecb238e
Merge branch 'main' into hnsw-layered-index
julianmi 1771f82
Merge branch 'main' into hnsw-layered-index
julianmi f1fdccc
Update license comments
julianmi 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| #pragma once | ||
|
|
||
| #include <cuvs/core/cuda_fp16.hpp> | ||
| #include <cuvs/core/export.hpp> | ||
|
|
||
| #include <raft/core/detail/mdspan_numpy_serializer.hpp> | ||
| #include <raft/core/error.hpp> | ||
|
|
||
| #include <cstddef> | ||
| #include <cstdint> | ||
| #include <limits> | ||
| #include <sstream> | ||
| #include <string> | ||
| #include <type_traits> | ||
| #include <vector> | ||
|
|
||
| namespace CUVS_EXPORT cuvs { | ||
| namespace util { | ||
|
|
||
| template <typename T> | ||
| inline auto numpy_dtype_string() -> std::string | ||
| { | ||
| if constexpr (std::is_same_v<T, half>) { | ||
| return "<f2"; | ||
| } else { | ||
| return raft::detail::numpy_serializer::get_numpy_dtype<T>().to_string(); | ||
| } | ||
| } | ||
|
|
||
| inline auto make_numpy_header_from_dtype(const std::string& dtype, const std::vector<size_t>& shape) | ||
| -> std::string | ||
| { | ||
| std::stringstream dict; | ||
| dict << "{'descr': '" << dtype << "', 'fortran_order': False, 'shape': ("; | ||
| for (size_t i = 0; i < shape.size(); ++i) { | ||
| if (i != 0) { dict << ", "; } | ||
| dict << shape[i]; | ||
| } | ||
| if (shape.size() == 1) { dict << ","; } | ||
| dict << "), }"; | ||
|
|
||
| std::string header = dict.str(); | ||
| constexpr size_t preamble_size = | ||
| 6 + 2 + sizeof(uint16_t); // magic string, version, v1 header length | ||
| const size_t remainder = (preamble_size + header.size() + 1) % 16; | ||
| if (remainder != 0) { header.append(16 - remainder, ' '); } | ||
| header.push_back('\n'); | ||
|
|
||
| RAFT_EXPECTS(header.size() <= std::numeric_limits<uint16_t>::max(), | ||
| "NumPy v1 header is too large: %zu bytes", | ||
| header.size()); | ||
|
|
||
| const auto header_len = static_cast<uint16_t>(header.size()); | ||
| std::string result; | ||
| result.reserve(preamble_size + header.size()); | ||
| result.append("\x93NUMPY", 6); | ||
| result.push_back(1); | ||
| result.push_back(0); | ||
| result.push_back(static_cast<char>(header_len & 0xff)); | ||
| result.push_back(static_cast<char>((header_len >> 8) & 0xff)); | ||
| result.append(header); | ||
| return result; | ||
| } | ||
|
|
||
| template <typename T> | ||
| inline auto make_numpy_header_string(const std::vector<size_t>& shape) -> std::string | ||
| { | ||
| if constexpr (std::is_same_v<T, half>) { | ||
| return make_numpy_header_from_dtype(numpy_dtype_string<T>(), shape); | ||
| } else { | ||
| const auto dtype = raft::detail::numpy_serializer::get_numpy_dtype<T>(); | ||
| const bool fortran_order = false; | ||
| const raft::detail::numpy_serializer::header_t header = {dtype, fortran_order, shape}; | ||
|
|
||
| std::stringstream ss; | ||
| raft::detail::numpy_serializer::write_header(ss, header); | ||
| return ss.str(); | ||
| } | ||
| } | ||
|
|
||
| } // namespace util | ||
| } // namespace CUVS_EXPORT cuvs | ||
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.
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.