Skip to content

Introduce a Loader trait in diskann-record to help deserialization with run-time parameters - #1387

Open
Suhas Jayaram Subramanya (suhasjs) wants to merge 16 commits into
mainfrom
users/suhasjs/saveload-runtime
Open

Suhas Jayaram Subramanya (suhasjs) wants to merge 16 commits into
mainfrom
users/suhasjs/saveload-runtime

Conversation

@suhasjs

@suhasjs Suhas Jayaram Subramanya (suhasjs) commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor
  • Does this PR have a descriptive title that could go in our release notes?
  • Does this PR add any new dependencies?
  • Does this PR modify any existing APIs?
  • Is the change to the API backwards compatible?
  • Should this result in any changes to our documentation, either updating existing docs or adding new ones?

This PR addresses the problem of providing runtime state/config/parameters during index deserialization.

One obvious example of what this enables: an inmem-2.0 index is constructed with max_slots = 1 million and contains 900k active points. After serialization to disk, only the data in the active slots is persisted, so using a InMemIndexLoader with max_slots = 2 million to support a larger index size than originally intended.

Another obvious use-case involves setting scratch spaces and number of threads, etc.

Reference Issues/PRs

#1386

What does this implement/fix? Briefly explain your changes.

  • Adds runtime-configurable loading through diskann-record::load::Loader (default load path remains the same)
  • Implements save/load for f32 FullProvider (in-mem 2.0): compacts the ID space, renames the graph during save time, and can load it back up with configurable capacity

Any other comments?

Other impls for in-mem 2.0 providers will come after this PR goes through.

@suhasjs Suhas Jayaram Subramanya (suhasjs) added enhancement New feature or request rust Pull requests that update rust code RFC Request For Comments labels Sep 8, 2026
@codecov-commenter

Codecov Comments Bot (codecov-commenter) commented Sep 8, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.98682% with 64 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.37%. Comparing base (adb5cd6) to head (31bb3c7).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
diskann-inmem/src/provider/persist.rs 97.74% 23 Missing ⚠️
diskann/src/graph/config/persist.rs 92.25% 11 Missing ⚠️
diskann-benchmark/src/index/inmem2/full.rs 94.94% 10 Missing ⚠️
diskann-inmem/src/repr/full.rs 94.53% 7 Missing ⚠️
diskann-inmem/src/provider/mod.rs 0.00% 3 Missing ⚠️
diskann-record/src/backend/memory.rs 97.19% 3 Missing ⚠️
diskann-record/src/load/error.rs 0.00% 3 Missing ⚠️
diskann-record/src/save/error.rs 0.00% 3 Missing ⚠️
diskann-record/src/save/mod.rs 92.85% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1387      +/-   ##
==========================================
+ Coverage   92.27%   92.37%   +0.10%     
==========================================
  Files         633      635       +2     
  Lines      133563   135691    +2128     
==========================================
+ Hits       123239   125344    +2105     
- Misses      10324    10347      +23     
Flag Coverage Δ
miri 92.37% <96.98%> (+0.10%) ⬆️
unittests 92.32% <96.98%> (+0.10%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
diskann-benchmark/src/main.rs 94.90% <100.00%> (+0.83%) ⬆️
diskann-inmem/src/buffer.rs 96.01% <100.00%> (+0.03%) ⬆️
diskann-inmem/src/ids.rs 100.00% <100.00%> (ø)
diskann-inmem/src/neighbors.rs 100.00% <100.00%> (ø)
diskann-inmem/src/repr/quantized/mod.rs 99.02% <100.00%> (+0.11%) ⬆️
diskann-inmem/src/store/mod.rs 93.52% <100.00%> (+1.48%) ⬆️
diskann-inmem/src/store/packed.rs 98.70% <100.00%> (+0.01%) ⬆️
diskann-record/src/lib.rs 89.07% <100.00%> (-0.04%) ⬇️
diskann-record/src/load/context.rs 92.60% <100.00%> (+16.76%) ⬆️
diskann-record/src/load/mod.rs 97.97% <100.00%> (+1.42%) ⬆️
... and 12 more

... and 12 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@suhasjs Suhas Jayaram Subramanya (suhasjs) changed the title Introduce Runtime associated type for Load,Loadable in diskann-record Introduce a Loader trait in diskann-record to help deserialization with run-time parameters Sep 9, 2026
Comment thread diskann-garnet/src/ffi_tests.rs Fixed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved persistence defects can break post-restore insertions, fail compaction for valid relocated frozen ranges, and leave retained live nodes unreachable after reload.

5 open issues
What changed in this PR

Adds runtime-configurable deserialization to diskann-record, addressing #1386, and applies it to persistence for full-precision in-memory providers.

Changes:

  • Introduces Loader, nested loading helpers, and a disk-loading entry point; makes disk support opt-in.
  • Adds persistence for f32 providers with u32 external IDs, including capacity overrides, ID compaction, validation, and tests.
  • Extends benchmarks with save/load/search workflows and examples.
File Description
rfcs/​01386-runtime-parameters-for-load.md Documents the loader design and proposed persistence layout.
diskann-record/​src/​load/​mod.rs Adds Loader, its adapter, and disk-loading helper.
diskann-record/​src/​load/​context.rs Adds nested loader helpers and tests.
diskann-record/​src/​lib.rs Documents loaders and tests legacy-format loading through the adapter.
diskann-record/​src/​backend/​memory.rs Tests loaders with borrowed metadata and caller-owned resources.
diskann-record/​Cargo.toml Removes disk support from default features.
diskann-inmem/​src/​store/​mod.rs Clarifies writer-exclusion documentation and removes its unused suppression.
diskann-inmem/​src/​repr/​full/​save.rs Serializes vectors, graph rows, and representation metadata.
diskann-inmem/​src/​repr/​full/​load.rs Validates and restores representations with runtime capacity settings.
diskann-inmem/​src/​repr/​full.rs Connects persistence modules and exposes writer exclusion internally.
diskann-inmem/​src/​provider/​persist/​mod.rs Organizes persistence modules and exports the loader.
diskann-inmem/​src/​provider/​persist/​full.rs Implements provider persistence, runtime settings, and tests.
diskann-inmem/​src/​provider/​persist/​common.rs Adds ID compaction and external-ID serialization helpers.
diskann-inmem/​src/​provider/​mod.rs Exports the loader and documents persistence requirements.
diskann-inmem/​src/​lib.rs Re-exports FullProviderLoader.
diskann-inmem/​src/​ids.rs Adds an internal mapping-count accessor.
diskann-inmem/​Cargo.toml Adds the record dependency and disk-enabled test support.
diskann-benchmark/​src/​main.rs Adds save/load/search integration coverage.
diskann-benchmark/​src/​index/​inmem2/​full.rs Adds saving and load-only search benchmark workflows.
diskann-benchmark/​example/​inmem2.json Adds explicit save-path fields to existing examples.
diskann-benchmark/​example/​inmem2-search.json Provides a saved-provider search example.
diskann-benchmark/​Cargo.toml Enables disk-backed persistence for in-memory benchmarks.
Cargo.lock Records the new internal dependency relationships.

Review effort: Balanced

Comment thread diskann-inmem/src/repr/full/load.rs Resolved
Comment thread diskann-inmem/src/repr/full/save.rs Resolved
Comment thread diskann-inmem/src/repr/full/save.rs Resolved
Comment thread diskann-record/Cargo.toml Resolved
Comment thread diskann-inmem/src/provider/mod.rs Resolved

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Suhas. This needs some work. The comments I left can be grouped into several themes:

  • Try to reduce implicit coupling and complex function pre-conditions as much as possible. For the save/load implementations in diskann-inmem, this can be helped by using the same information flow from Representation to Provider that already exists.
  • Don't duplicate existing logic if possible (e.g., mechanics of sizing that relies on factors like cache padding etc.) and if necessary, funnel the logic into a single shared place to reduce the maintenance burden.
  • Try to avoid digging through untyped representations to implement functionality. The biggest example here is the creation of diskann::graph::Config in the benchmark digging through the serialized representation of the Provider. That is not a maintainable pattern. Instead, actually implement save/load for diskann::graph::Config.
  • I don't understand why the combination f32/u32 is so special cased. Generalizing to T: FullPrecision should be pretty easy, and generalizing the ID type seems like a good stress test for diskann-record's API.
  • In general, use this integration as a stress test for diskann-record. If you find yourself fighting its API, now is a great time to take that as feedback to improve its API. Examples I found are formalizing the repeated ad-hoc checks of reader sizes on the load path and making Record construction easier from primitive types.

Comment thread diskann-inmem/src/ids.rs
self.forward.contains_key(external)
}

pub(crate) fn len(&self) -> usize {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small docstring would be appreciated.

Comment thread diskann-inmem/src/repr/full/save.rs Outdated
use super::Full;
use crate::num::Range;

impl Full<f32> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right off the bat - implementing this just for f32 seems overly restrictive and unnecessary. The underlying data is already stored as raw bytes. The endian swizzling is the only element dependent bit, and that could either be folded into the FullPrecision trait, or simply left off (since diskann already doesn't compile on big-endian systems).

Comment thread diskann-inmem/src/repr/full/save.rs Outdated
&self,
context: save::Context<'_>,
renaming: &[u32],
live_count: u32,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice for this to take like a &ExcludeWriters<'_> as proof that writer exclusion is in place.

Comment thread diskann-inmem/src/repr/full/save.rs Outdated
let id_limit = u32::try_from(renaming.len()).map_err(save::Error::new)?;
let writable =
(0..self.start_point_ids.start()).chain(self.start_point_ids.end()..id_limit);
for old in self.start_point_ids.iter().chain(writable) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ... assumes that renaming was created with an awareness that this particular iteration order would be used. Which is a long-range implicit dependency that is also not stated as a pre-condition in this function's doc-string.

The problem of implicit data dependence is actually worse. Nothing describes that renaming needs to keep the start-points together to be represented by a Range upon deserialization. This implementation structurally writes the start points in order, but there's nothing that guarantees that the remapped IDs do so.

Perhaps think about it more like this: the way the Provider and Representation currently nest, the Provider knows nothing about start points. Serialization and deserialization should follow that. For example, serialization of Provider shouldn't dictate to the Representation how and where start points are placed - the Representation should handle this and pass up to the Provider what it decided to do.

For here, I would say to have the Representation do the scan and come up with the reordering. It can then return it's saved Record and the compaction reordering to the caller, which can use the reordering to save IDs. This mostly keeps information flowing in one direction rather than tangling the Provider and the Representation.

Additionally, please do not universally move start points to the beginning. There is an API in the configs to relocated the start points. As long as they stay together, I don't think there's really a problem with keeping them randomly in the middle. We can still compact them down, but I don't think we need to go out of our way to move them to the beginning.

Comment thread diskann-inmem/src/repr/full/save.rs Outdated
return Err(save::Error::message("graph edge is outside the provider"));
}
if renaming[*target as usize] == u32::MAX {
return Err(save::Error::message(format!(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling consolidate_vector a bunch of times should not be a pre-requisite. Especially if we take the view that the index could be under high concurrent churn and we might not be able to guarantee that all edges are valid. Consolidating the serialized representation inline seems fine.

fn load(
self,
context: diskann_record::load::Context<'a>,
) -> diskann_record::load::Result<Self::Value> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is reaching into the serialized representation of the Provider to reconstruct a diskann::graph::Config? Why is this a good idea as opposed to teaching diskann::graph::Config to be serializable?

start.elapsed().as_secs_f64()
);
let index = diskann::graph::DiskANNIndex::new(config, provider, None);
eprintln!(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diskann-benchmark uses &mut dyn Output as its output stream - not standard prints. Please bundle an Output (maybe Option<&mut dyn Output>) in the loader if timing prints are needed.


registry.register_regression(
"inmem2-f32",
RunBuildSearchAndSave::<f32>::new(Some(save_provider)),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These gymnastics could be avoided if saving didn't have to be special cased so heavily.

dbr::utils::datatype::DataType::Float16,
dbr::utils::datatype::DataType::UInt8,
] {
json["data"]["data_type"] = serde_json::to_value(data_type).unwrap();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any time you find yourself manually digging through JSON, take a step back and think if there is a different way. This implicitly creates a maintenance hazard and is often hiding a better way of doing things.

Comment thread diskann-benchmark/src/main.rs Outdated
"search": search,
"save_path": "metadata.json",
},
}],

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider the maintenance cost of a test like this. This basically has to shadow the existing configuration perfectly and maintains a lot of implicit state that would make debugging failure very hard.

There are alternatives: using the DTOs directly to build the structured input. Building a small general test-harness to executing multiple benchmark operations back-to-back (which would be generally more useful than ad-hoc tests like this). Maybe checking in a small pre-built index which would then work as a test of backwards compatible loading?

This branch has not been deployed

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

Labels

enhancement New feature or request RFC Request For Comments rust Pull requests that update rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Introduce runtime-related args for diskann-record's Load traits

5 participants