Skip to content

Commit b757485

Browse files
author
Jordan Maples
committed
add save_path handling to bftree streaming path
1 parent aea760c commit b757485

2 files changed

Lines changed: 56 additions & 12 deletions

File tree

diskann-benchmark/src/index/bftree/full_precision_streaming.rs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ use diskann_benchmark_runner::{
1616
Benchmark, Checkpoint,
1717
};
1818
use diskann_bftree::{BfTreeProvider, NoStore};
19-
use diskann_providers::model::graph::provider::async_::common::FullPrecision;
19+
use diskann_providers::{
20+
model::graph::provider::async_::common::FullPrecision,
21+
storage::{FileStorageProvider, SaveWith},
22+
};
2023
use diskann_utils::{
2124
sampling::WithApproximateNorm,
2225
views::{Matrix, MatrixView},
@@ -199,18 +202,36 @@ where
199202
) -> anyhow::Result<Self::Output> {
200203
writeln!(output, "{}", input)?;
201204

202-
super::streaming_utils::run_streaming::<T, _>(
205+
let mut index_for_save: Option<BfTreeFPIndex<T>> = None;
206+
207+
let results = super::streaming_utils::run_streaming::<T, _>(
203208
input.runbook_params(),
204-
|max_points| bftree_streaming::<T>(input, max_points),
209+
|max_points| {
210+
let (streamer, index) = bftree_streaming::<T>(input, max_points)?;
211+
index_for_save = Some(index);
212+
Ok(streamer)
213+
},
205214
output,
206-
)
215+
)?;
216+
217+
// save the index if requested
218+
if let Some(save_path) = input.build().save_path() {
219+
let index = index_for_save.expect("index should have been set by make_streamer");
220+
crate::utils::tokio::block_on(
221+
index
222+
.provider()
223+
.save_with(&FileStorageProvider, &save_path.to_string()),
224+
)?;
225+
}
226+
227+
Ok(results)
207228
}
208229
}
209230

210231
fn bftree_streaming<T>(
211232
input: &BfTreeDynamicRun,
212233
max_points: usize,
213-
) -> anyhow::Result<bigann::WithData<T, u32, Managed<T, StreamStats>>>
234+
) -> anyhow::Result<(bigann::WithData<T, u32, Managed<T, StreamStats>>, BfTreeFPIndex<T>)>
214235
where
215236
T: bytemuck::Pod + VectorRepr + WithApproximateNorm + SampleableForStart,
216237
{
@@ -232,6 +253,7 @@ where
232253
.compute(data.as_view())?;
233254
let provider = BfTreeProvider::new(params, start_points.as_view(), NoStore)?;
234255
let index = Arc::new(DiskANNIndex::new(config, provider, None));
256+
let index_handle = index.clone();
235257

236258
let num_threads_and_tasks = NonZeroUsize::new(input.build().num_threads()).unwrap();
237259
let managed_stream = BfTreeStream {
@@ -258,5 +280,5 @@ where
258280
)?))
259281
});
260282

261-
Ok(layered)
283+
Ok((layered, index_handle))
262284
}

diskann-benchmark/src/index/bftree/spherical_streaming.rs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ use diskann_benchmark_runner::{
1919
Benchmark, Checkpoint,
2020
};
2121
use diskann_bftree::{quant::QuantVectorProvider, BfTreeProvider};
22-
use diskann_providers::model::graph::provider::async_::common::Quantized;
22+
use diskann_providers::{
23+
model::graph::provider::async_::common::Quantized,
24+
storage::{FileStorageProvider, SaveWith},
25+
};
2326
use diskann_quantization::alloc::{AllocatorError, GlobalAllocator, Poly};
2427
use diskann_quantization::spherical::{
2528
iface::{self as spherical_iface, Quantizer},
@@ -204,18 +207,36 @@ impl Benchmark for StreamingSpherical {
204207
) -> anyhow::Result<Self::Output> {
205208
writeln!(output, "{}", input)?;
206209

207-
super::streaming_utils::run_streaming::<f32, _>(
210+
let mut index_for_save: Option<BfTreeSQIndex> = None;
211+
212+
let results = super::streaming_utils::run_streaming::<f32, _>(
208213
input.runbook_params(),
209-
|max_points| bftree_sq_streaming_impl(input, max_points),
214+
|max_points| {
215+
let (streamer, index) = bftree_sq_streaming_impl(input, max_points)?;
216+
index_for_save = Some(index);
217+
Ok(streamer)
218+
},
210219
output,
211-
)
220+
)?;
221+
222+
// save the index if requested
223+
if let Some(save_path) = input.build().save_path() {
224+
let index = index_for_save.expect("index should have been set by make_streamer");
225+
crate::utils::tokio::block_on(
226+
index
227+
.provider()
228+
.save_with(&FileStorageProvider, &save_path.to_string()),
229+
)?;
230+
}
231+
232+
Ok(results)
212233
}
213234
}
214235

215236
fn bftree_sq_streaming_impl(
216237
input: &BfTreeSphericalDynamicRun,
217238
max_points: usize,
218-
) -> anyhow::Result<bigann::WithData<f32, u32, Managed<f32, StreamStats>>> {
239+
) -> anyhow::Result<(bigann::WithData<f32, u32, Managed<f32, StreamStats>>, BfTreeSQIndex)> {
219240
let topk = match input.search_phase() {
220241
SearchPhase::Topk(topk) => topk,
221242
_ => anyhow::bail!("Only TopK is currently supported by the streaming index"),
@@ -257,6 +278,7 @@ fn bftree_sq_streaming_impl(
257278
.compute(data.as_view())?;
258279
let provider = BfTreeProvider::new(params, start_points.as_view(), quantizer_poly)?;
259280
let index = Arc::new(DiskANNIndex::new(config, provider, None));
281+
let index_handle = index.clone();
260282

261283
let num_threads_and_tasks = NonZeroUsize::new(input.build().num_threads()).unwrap();
262284
let managed_stream = BfTreeSQStream {
@@ -283,5 +305,5 @@ fn bftree_sq_streaming_impl(
283305
)?))
284306
});
285307

286-
Ok(layered)
308+
Ok((layered, index_handle))
287309
}

0 commit comments

Comments
 (0)