Materialize HNSW Layered Index to hnswlib Index#2241
Draft
julianmi wants to merge 12 commits into
Draft
Conversation
- Add base node IDs for sequential access. - Scattered writes happen only in deserialization step using host memory.
- `materialize_to_hnswlib` enables disk-to-disk materialization of a layered HNSW artifact to a standard hnswlib index fiel. - Adds bindings
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
#2148 added a HNSW layered index that compacts the HNSW index by stripping out the dataset. This can be especially beneficial if the index is built on an accelerated machine and moved over a network to a search node. This proposal adds
cuvs::neighbors::hnsw::materialize_to_hnswlib, a file-to-file API that converts aGPU_LAYERED_ON_DISKartifact (graph topology only, stored in ACE/build order) plus its original-ID-ordered dataset into a standard hnswlib index file.Public API (
cpp/include/cuvs/neighbors/hnsw.hpp)I don't think there is a similar API in cuVS nor hnswlib. Thus, I've aligned the naming with the existing
serialize_to_hnswliband usedmaterializeto clarify that the result is a hnswlib index file. I'm open for other naming suggestions.A single entry point covers all dtypes: the element type (
float,half,uint8_t,int8_t) isread from the artifact header and dispatched internally.
Implementation (
cpp/src/neighbors/detail/hnsw.hpp)The goal is to minimize the random access necessary for the ID reordering. The random access in main memory is cheap but severe for disk I/O. Thus, two passes are used:
layout constants from a dummy single-element index, compute the output layout,
posix_fallocatethe output, and write the native hnswlib header.
vectors, emitting
[level-0 link block | vector | label]sequentially. Two strategies:max_host_memory_gb;id_record_spiller) otherwise — sequential append + sequential replayper bucket, peak RAM bounded near the budget.
sequentially, with the same in-memory / bucketed fallback.
The output is the exact upstream layout (header + level-0 array + per-element link lists), loadable
by
hnswlib::loadIndexand bycuvs::neighbors::hnsw::deserializewithhierarchy == CPU.Details
base_links_bytes / num_buckets) + small (~64 MiB) streamingbuffers +
levels(n bytes) + the upper locator. With the in-memory pass, RAM ≈ the base topologyonly and a budget lowers it further.
(in-memory) or read once + temp write/read once (bucketed), and upper read once + written once.
cpp/tests/neighbors/ann_hnsw_ace*.examples/cpp/src/hnsw_ace_layered_example.cuwas updated to use the materialization path.