Repository navigation
Introduce a Loader trait in diskann-record to help deserialization with run-time parameters - #1387
Suhas Jayaram Subramanya (suhasjs) wants to merge 16 commits into
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Runtime associated type for Load,Loadable in diskann-recordLoader trait in diskann-record to help deserialization with run-time parameters
f8f265f to
77e935e
Compare
acbf415 to
63b6a3f
Compare
There was a problem hiding this comment.
🟡 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
Restore leaves the freelist cursor uninitialized · New Compaction miscounts relocated frozen start-point IDs · New Saving after edge deletion can make live nodes unreachable · New Memory-only builds expose no public save/load entry point · New Saving while holding a write accessor can deadlock · New
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
f32providers withu32external 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
Mark Hildebrand (hildebrandmw)
left a comment
There was a problem hiding this comment.
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 fromRepresentationtoProviderthat 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::Configin the benchmark digging through the serialized representation of theProvider. That is not a maintainable pattern. Instead, actually implementsave/loadfordiskann::graph::Config. - I don't understand why the combination
f32/u32is so special cased. Generalizing toT: FullPrecisionshould be pretty easy, and generalizing the ID type seems like a good stress test fordiskann-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 makingRecordconstruction easier from primitive types.
| self.forward.contains_key(external) | ||
| } | ||
|
|
||
| pub(crate) fn len(&self) -> usize { |
There was a problem hiding this comment.
Small docstring would be appreciated.
| use super::Full; | ||
| use crate::num::Range; | ||
|
|
||
| impl Full<f32> { |
There was a problem hiding this comment.
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).
| &self, | ||
| context: save::Context<'_>, | ||
| renaming: &[u32], | ||
| live_count: u32, |
There was a problem hiding this comment.
Would be nice for this to take like a &ExcludeWriters<'_> as proof that writer exclusion is in place.
| 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) { |
There was a problem hiding this comment.
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.
| return Err(save::Error::message("graph edge is outside the provider")); | ||
| } | ||
| if renaming[*target as usize] == u32::MAX { | ||
| return Err(save::Error::message(format!( |
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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!( |
There was a problem hiding this comment.
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)), |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
| "search": search, | ||
| "save_path": "metadata.json", | ||
| }, | ||
| }], |
There was a problem hiding this comment.
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?
… additions to diskann-benchmark's README for inmem2
97751e0 to
31bb3c7
Compare



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 millionand contains 900k active points. After serialization to disk, only the data in the active slots is persisted, so using aInMemIndexLoaderwithmax_slots = 2 millionto 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.
diskann-record::load::Loader(default load path remains the same)f32FullProvider(in-mem 2.0): compacts the ID space, renames the graph during save time, and can load it back up with configurable capacityAny other comments?
Other impls for in-mem 2.0 providers will come after this PR goes through.