PiPNN 4/6: integrate disk build pipeline - #1291
Conversation
There was a problem hiding this comment.
Pull request overview
This PR integrates PiPNN graph construction into the DiskANN disk-index build pipeline and exposes it through the benchmark CLI inputs, including automated fixture-based tests to validate the new JSON configuration and execution paths.
Changes:
- Add a
BuildAlgorithmselector (Vamana vs PiPNN) with JSON-facing PiPNN parameters, plus memory-estimate-based fallback to Vamana for disk builds. - Implement PiPNN graph building adapters for disk builds and in-memory benchmark builds, including vector-store “flat prefix” access for dense layouts.
- Add a shared cached CLI fixture runner and new PiPNN benchmark fixtures (disk + in-memory) to validate end-to-end CLI wiring.
Reviewed changes
Copilot reviewed 33 out of 37 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| diskann-providers/src/utils/rayon_util.rs | Exposes underlying Rayon pool reference for APIs that need &rayon::ThreadPool. |
| diskann-providers/src/storage/mod.rs | Re-exports new adjacency-graph save helper. |
| diskann-providers/src/storage/bin.rs | Adds save_adjacency_graph for canonical adjacency graph serialization. |
| diskann-providers/src/model/graph/provider/async_/fast_memory_vector_provider.rs | Exposes unsafe dense-prefix slice access to support PiPNN build path. |
| diskann-providers/src/model/graph/provider/async_/common.rs | Implements AlignedMemoryVectorStore::flat_prefix and adds a contiguous-prefix test. |
| diskann-disk/src/lib.rs | Re-exports PiPNN parameters (feature-gated) and exposes build-algorithm selection. |
| diskann-disk/src/build/mod.rs | Re-exports BuildAlgorithm and (feature-gated) PiPNN parameters. |
| diskann-disk/src/build/configuration/mod.rs | Introduces build-algorithm configuration module and re-exports its types. |
| diskann-disk/src/build/configuration/disk_index_build_parameter.rs | Adds build_algorithm, PiPNN constructor, PiPNN config conversion, and memory-estimate-based fallback. |
| diskann-disk/src/build/configuration/build_algorithm.rs | New: serde-driven BuildAlgorithm enum and PiPNN JSON parameter struct. |
| diskann-disk/src/build/builder/build/pipnn.rs | New: PiPNN graph build adapter producing a canonical on-disk adjacency graph. |
| diskann-disk/src/build/builder/build/pipnn/tests.rs | New: disk-build integration tests for PiPNN selection, fallback, and header correctness. |
| diskann-disk/src/build/builder/build.rs | Routes graph construction to PiPNN (when selected) while keeping existing Vamana pipeline as default. |
| diskann-disk/Cargo.toml | Adds optional diskann-pipnn dependency + feature, plus test deps for new tests. |
| diskann-benchmark/src/main.rs | Refactors registry creation and adds PiPNN fixture test hook (feature-gated). |
| diskann-benchmark/src/inputs/graph_index.rs | Adds PiPNN build-algorithm selection for graph-index build inputs (feature-gated). |
| diskann-benchmark/src/inputs/disk.rs | Adds alpha, makes quantization_type optional, and adds disk build-algorithm selection + validation. |
| diskann-benchmark/src/index/build.rs | Adds PiPNN in-memory build path leveraging dense flat-prefix when possible. |
| diskann-benchmark/src/index/benchmarks.rs | Wires PiPNN build path selection into benchmark build flow. |
| diskann-benchmark/src/disk_index/build.rs | Wires disk BuildAlgorithm into disk-index build parameter construction. |
| diskann-benchmark/Cargo.toml | Adds optional PiPNN dependency/feature and enables fixture runner for dev-tests. |
| diskann-benchmark/tests/pipnn/inmemory/stdout.txt | New: expected output for in-memory PiPNN CLI fixture. |
| diskann-benchmark/tests/pipnn/inmemory/stdin.txt | New: commands for in-memory PiPNN CLI fixture. |
| diskann-benchmark/tests/pipnn/inmemory/input.json | New: PiPNN in-memory input JSON fixture. |
| diskann-benchmark/tests/pipnn/disk/stdout.txt | New: expected output for disk PiPNN CLI fixture. |
| diskann-benchmark/tests/pipnn/disk/stdin.txt | New: commands for disk PiPNN CLI fixture. |
| diskann-benchmark/tests/pipnn/disk/input.json | New: PiPNN disk input JSON fixture. |
| diskann-benchmark-runner/src/lib.rs | Exposes new fixture runner module for tests/downstream crates (feature-gated). |
| diskann-benchmark-runner/src/fixture.rs | New: shared cached CLI fixture runner implementation. |
| diskann-benchmark-runner/src/fixture/tests.rs | New: unit tests for fixture runner behavior. |
| diskann-benchmark-runner/src/app.rs | Updates integration-test documentation and switches tests to the shared fixture runner. |
| diskann-benchmark-runner/Cargo.toml | Adds test-fixtures feature + optional tempfile dep for downstream fixture usage. |
| Cargo.lock | Adds/records diskann-pipnn and serde_json dependency changes. |
| .cargo/mutants.toml | Excludes new fixture overwrite behavior from mutation testing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| #[cfg(feature = "pipnn")] | ||
| let frozen_points = match self.build_algorithm { | ||
| diskann_disk::BuildAlgorithm::PiPNN(_) => NonZero::new(1).unwrap(), | ||
| _ => NonZero::new(self.start_point_strategy.count()).unwrap(), | ||
| }; |
| use std::num::NonZeroUsize; | ||
|
|
||
| use diskann::ANNError; | ||
| #[cfg(feature = "pipnn")] | ||
| use diskann::ANNResult; |
8134eb3 to
ce5f054
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 13 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (2)
diskann-disk/src/build/configuration/disk_index_build_parameter.rs:17
estimate_pipnn_peak_memoryusessize_of::<...>()unqualified, but this module doesn’t importstd::mem::size_of. This will fail to compile under the repo’s Rust toolchain.
use std::num::NonZeroUsize;
use diskann::ANNError;
#[cfg(feature = "pipnn")]
use diskann::ANNResult;
use thiserror::Error;
#[cfg(feature = "pipnn")]
use super::PiPNNParameters;
use super::{BuildAlgorithm, QuantizationType};
diskann-disk/src/build/configuration/disk_index_build_parameter.rs:113
DiskIndexBuildParametersis publicly re-exported (viadiskann-disk’s public API) and this change removesCopyfrom its derives. That is a breaking API change for downstream users that relied on implicit copies; if this is intentional, it should be called out explicitly (and potentially gated or versioned accordingly).
/// Parameters specific for disk index construction.
#[derive(Clone, PartialEq, Debug)]
pub struct DiskIndexBuildParameters {
ce5f054 to
3893460
Compare
| /// Save real-point adjacency lists in the canonical graph layout. | ||
| pub fn save_adjacency_graph<P>( | ||
| adjacency: &[AdjacencyList<u32>], | ||
| max_degree: u32, | ||
| provider: &P, | ||
| start_point: u32, | ||
| path: &str, | ||
| ) -> ANNResult<usize> | ||
| where | ||
| P: StorageWriteProvider, | ||
| { | ||
| save_graph( | ||
| &AdjacencyGraph { | ||
| adjacency, | ||
| max_degree, | ||
| }, | ||
| provider, | ||
| start_point, | ||
| path, | ||
| ) | ||
| } |
3893460 to
f836f69
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 13 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (3)
diskann-disk/src/build/configuration/disk_index_build_parameter.rs:204
disk_index_build_parameter.rsenables#![warn(missing_docs)], and the newpub(crate) fn pipnn_confighas no doc comment. If CI promotes warnings to errors, this will fail builds; even if not, it adds new lint noise.
#[cfg(feature = "pipnn")]
pub(crate) fn pipnn_config(&self) -> Option<diskann_pipnn::PiPNNConfig> {
match &self.build_algorithm {
BuildAlgorithm::PiPNN(config) => Some(config.into()),
BuildAlgorithm::Vamana => None,
}
}
diskann-disk/src/build/builder/build/pipnn.rs:49
pipnn::build_graphreads the full dataset into memory (read_bin) and then callsfind_medoid_with_sampling, which performs another full pass over the dataset viaVectorDataIterator(plus a sampled centroid pass). On large datasets this doubles I/O and parsing work even though the vectors are already in memory.
let data =
read_bin::<Data::VectorDataType>(&mut builder.storage_provider.open_reader(&data_path)?)?;
let context = PiPNNBuildContext::new(
config,
&builder.index_configuration.config,
diskann-providers/src/storage/bin.rs:388
save_adjacency_graphis re-exported as a public API, but its signature exposesdiskann::graph::AdjacencyList<u32>, forcing downstream callers to take a dependency ondiskanngraph types just to usediskann-providersserialization. If the goal is a narrow cross-crate adjacency entry point, consider changing this API to accept adjacency rows as plain slices (or any type that derefs/borrows to&[u32]) to avoid leakingdiskanninternals intodiskann-providers’ public surface.
pub fn save_adjacency_graph<P>(
adjacency: &[AdjacencyList<u32>],
max_degree: u32,
provider: &P,
start_point: u32,
f836f69 to
2181da2
Compare
Codecov Report❌ Patch coverage is ❌ Your patch status has failed because the patch coverage (23.21%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## pipnn-stack/03-core #1291 +/- ##
======================================================
Coverage ? 90.72%
======================================================
Files ? 521
Lines ? 101084
Branches ? 0
======================================================
Hits ? 91709
Misses ? 9375
Partials ? 0
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
2181da2 to
19c3b5a
Compare
9ba8d47 to
4e92b01
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 13 changed files in this pull request and generated no new comments.
Suppressed comments (2)
diskann-providers/src/storage/bin.rs:388
save_adjacency_graphis a new public entry point that can currently write an invalid graph file: it does not validate thatstart_pointis withinadjacency.len(), and it trusts the caller-providedmax_degreeeven if some rows are longer.load_graphsizes its buffer from the header max-degree and will panic if any stored row length exceeds that header value, so acceptingmax_degree< observed degree can produce a graph that crashes on load.
pub fn save_adjacency_graph<P>(
adjacency: &[AdjacencyList<u32>],
max_degree: u32,
provider: &P,
start_point: u32,
diskann-disk/src/build/builder/build/pipnn.rs:88
build_graphreads the entire dataset into memory viaread_bin, but then immediately re-reads/scans the dataset again viafind_medoid_with_samplingto pick the start node. For large datasets/providers this doubles I/O and can become a noticeable build-time cost. Consider adding/using a medoid helper that operates over the already-loaded matrix view (or a row iterator over it) so PiPNN can reuse the in-memory data instead of reopening/scanning the file again.
let mut rng = diskann_providers::utils::create_rnd_from_optional_seed(
builder.index_configuration.random_seed,
);
let (_, start_id) = find_medoid_with_sampling::<Data::VectorDataType, _>(
&data_path,
4e92b01 to
d9c15f2
Compare
d9c15f2 to
7a5bbeb
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 13 changed files in this pull request and generated no new comments.
Suppressed comments (2)
diskann-providers/src/storage/bin.rs:388
save_adjacency_graphcan write a graph file thatload_graphcannot read if any row has more thanmax_degreeneighbors:load_graphallocates a buffer of lengthmax_degreeand slices it tonum_neighbors, which will panic/out-of-bounds whennum_neighbors > max_degree. The wrapper should ensure the header max degree is at least the observed maximum (or fail early).
pub fn save_adjacency_graph<P>(
adjacency: &[AdjacencyList<u32>],
max_degree: u32,
provider: &P,
start_point: u32,
diskann-providers/src/utils/rayon_util.rs:81
as_rayonis documented as a borrow, but it consumesself. WhileRayonThreadPoolRefisCopy, taking&selfbetter matches the API intent and avoids forcing a move in call sites that hold the wrapper in a non-Copycontext later.
/// Borrow the underlying pool for APIs that retain a caller-owned pool.
pub fn as_rayon(self) -> &'a rayon::ThreadPool {
self.0
}
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 13 changed files in this pull request and generated no new comments.
Suppressed comments (2)
diskann-providers/src/storage/bin.rs:398
save_adjacency_graphis a new public entry point but it doesn’t validate thatstart_pointis withinadjacency.len()or that any row’s degree is <=max_degree. If callers pass an out-of-range start point or an overfull row, this will write a graph whose header/contents are inconsistent and can later fail (or mis-size allocations) when loading.
save_graph(
&AdjacencyGraph {
adjacency,
max_degree,
},
diskann-disk/src/build/configuration/disk_index_build_parameter.rs:113
DiskIndexBuildParameterspreviously implementedCopy; addingbuild_algorithm: BuildAlgorithm(which can contain heap data likeVec) dropsCopy. This is an API-breaking change for downstream users that may have relied on implicit copies (e.g., passing params by value multiple times). If this is intended, it likely needs an explicit release note / versioning consideration; otherwise consider keeping the algorithm config outside this public params struct (or exposing a separate PiPNN params type) to preserve the priorCopyAPI surface.
/// Parameters specific for disk index construction.
#[derive(Clone, PartialEq, Debug)]
pub struct DiskIndexBuildParameters {
/// Memory budget for disk-index pipeline stages that support bounded work.
/// Explicit one-shot PiPNN selection is never silently replaced.
7a5bbeb to
ebac06f
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 13 changed files in this pull request and generated no new comments.
Suppressed comments (2)
diskann-providers/src/storage/bin.rs:398
save_adjacency_graphwrites a headermax_degreethat is later trusted byload_graphto size its read buffer; if any adjacency row is longer thanmax_degree,load_graphwill panic when slicing the buffer. Since this is now a public entry point, it should defensively validate that the observed max row length does not exceed the configuredmax_degree(and return an error if it does) before delegating tosave_graph.
save_graph(
&AdjacencyGraph {
adjacency,
max_degree,
},
diskann-disk/src/build/configuration/disk_index_build_parameter.rs:113
DiskIndexBuildParametersused to beCopy, but the newbuild_algorithm: BuildAlgorithmfield (and thePiPNNvariant’sVec) forces droppingCopyfor all builds. Sincepipnnis an optional feature and the default build still only hasBuildAlgorithm::Vamana, consider preservingCopyfor the common non-pipnnbuild viacfg_attr(not(feature = "pipnn"), derive(Copy))(and similarly makingBuildAlgorithmCopywhenpipnnis disabled). This reduces downstream breakage for consumers not enabling PiPNN.
/// Parameters specific for disk index construction.
#[derive(Clone, PartialEq, Debug)]
pub struct DiskIndexBuildParameters {
/// Memory budget for disk-index pipeline stages that support bounded work.
/// Explicit one-shot PiPNN selection is never silently replaced.
ebac06f to
2e0532f
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 13 changed files in this pull request and generated 1 comment.
Suppressed comments (2)
diskann-providers/src/storage/bin.rs:398
- save_adjacency_graph() forwards a caller-supplied max_degree into the file header without validating it against the actual adjacency row lengths. If any row is longer than max_degree, load_graph() will panic because it allocates a buffer of size max_degree and then slices it to num_neighbors. Consider validating and returning an ANNError when observed_max_degree > max_degree.
save_graph(
&AdjacencyGraph {
adjacency,
max_degree,
},
diskann-disk/src/build/builder/build/pipnn/tests.rs:154
- This test currently hard-codes the serialized graph header max_degree to the pruned degree (32). If the adapter writes the canonical max_degree (Config::max_degree_u32) like the Vamana pipeline, this assertion will fail even though the header is correct.
assert_eq!(u32::from_le_bytes(header[8..12].try_into().unwrap()), 32);
| )?; | ||
| save_adjacency_graph( | ||
| &adjacency, | ||
| u32_try_from(builder.index_configuration.config.pruned_degree().get())?, |
Connects PiPNN adjacency output to the production disk-index build pipeline.
Code map
build_algorithm.rsadds the taggedPiPNNconfiguration and converts it into the core crate's validated parameters.builder/build.rsdispatches on the explicit algorithm choice. Memory-budget estimation may choose Vamana only for the existing automatic path; an explicit PiPNN request is never rewritten.builder/build/pipnn.rsvalidates the dataset/configuration boundary, constructs the core build context, and receives adjacency for real point IDs.Review path
BuildAlgorithm, builder dispatch, core invocation, and graph serialization.Stack 4/6: #1290 → #1294