Skip to content

feat(rust): add serialize/deserialize support for CAGRA index#1840

Open
zbennett10 wants to merge 3 commits intorapidsai:mainfrom
zbennett10:feat/rust-cagra-serialization
Open

feat(rust): add serialize/deserialize support for CAGRA index#1840
zbennett10 wants to merge 3 commits intorapidsai:mainfrom
zbennett10:feat/rust-cagra-serialization

Conversation

@zbennett10
Copy link
Contributor

Closes #1479

Description

Adds serialization and deserialization support to the Rust CAGRA index bindings. The underlying C API functions (cuvsCagraSerialize, cuvsCagraDeserialize, cuvsCagraSerializeToHnswlib) already exist but were not exposed through the Rust crate.

Methods added to cagra::Index:

  • serialize(&self, res, filename, include_dataset) — Save the CAGRA index to file, with option to include or exclude the dataset
  • serialize_to_hnswlib(&self, res, filename) — Save the CAGRA index in hnswlib-compatible format
  • deserialize(res, filename) -> Result<Index> — Load a CAGRA index from file

Design decisions:

  • Uses &self (not self) for serialize methods so the index remains usable after serialization. This differs from the Vamana pattern but is more ergonomic for the common case of serializing a hot index.
  • Uses CString for safe C string interop with the FFI layer.
  • Follows the existing error handling pattern via check_cuvs.

Tests:

  • test_cagra_serialize_deserialize — Round-trip test: build → serialize (with dataset) → deserialize → search → verify nearest neighbors match
  • test_cagra_serialize_without_dataset — Verifies serialization works with include_dataset=false
  • test_cagra_serialize_to_hnswlib — Verifies hnswlib format export produces a non-empty file

Documentation:

  • Added serialization example to cagra module docs in mod.rs

Checklist

  • I am familiar with the Contributing Guidelines
  • New or existing tests cover these changes
  • The documentation is up to date with these changes

Add idiomatic Rust bindings for CAGRA index serialization and
deserialization, wrapping the existing C API functions:

- `Index::serialize()` - Save index to file with optional dataset
- `Index::serialize_to_hnswlib()` - Save in hnswlib-compatible format
- `Index::deserialize()` - Load index from file

Includes comprehensive test suite:
- Round-trip serialize/deserialize with search verification
- Serialization with and without dataset
- hnswlib format serialization

Closes rapidsai#1479
@copy-pr-bot
Copy link

copy-pr-bot bot commented Feb 23, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@aamijar aamijar added Rust non-breaking Introduces a non-breaking change improvement Improves an existing functionality labels Feb 23, 2026
@aamijar
Copy link
Member

aamijar commented Feb 23, 2026

/ok to test b66d204

@aamijar
Copy link
Member

aamijar commented Feb 23, 2026

/ok to test f530475

@aamijar
Copy link
Member

aamijar commented Feb 25, 2026

/ok to test 2c5f58b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Improves an existing functionality non-breaking Introduces a non-breaking change Rust

Projects

Development

Successfully merging this pull request may close these issues.

[FEA] Add support for index serialization/deserialization in rust

2 participants