Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions diskann-benchmark-core/src/build/graph/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use std::{ops::Range, sync::Arc};

use diskann::{
ANNError, ANNErrorKind, ANNResult,
ANNError, ANNResult,
graph::{self, glue},
provider,
};
Expand Down Expand Up @@ -95,14 +95,11 @@ where
}
}

ANNError::message(
ANNErrorKind::Opaque,
OutOfBounds {
max: self.data.nrows(),
start: range.start,
end: range.end,
},
)
ANNError::message(OutOfBounds {
max: self.data.nrows(),
start: range.start,
end: range.end,
})
})?
.to_owned();

Expand Down
36 changes: 17 additions & 19 deletions diskann-benchmark-core/src/build/ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

use std::marker::PhantomData;

use diskann::{ANNError, ANNErrorKind, ANNResult};
use diskann_utils::future::AsyncFriendly;
use diskann::{ANNError, ANNResult};
use diskann_utils::{future::AsyncFriendly, lazy_format};

/// Convert an implicit data index to an external ID.
///
Expand Down Expand Up @@ -77,7 +77,7 @@ where
T: TryFrom<usize, Error: std::error::Error + AsyncFriendly> + AsyncFriendly,
{
fn to_id(&self, i: usize) -> ANNResult<T> {
T::try_from(i).map_err(ANNError::opaque)
T::try_from(i).map_err(ANNError::new)
}
}

Expand Down Expand Up @@ -115,14 +115,13 @@ where
{
fn to_id(&self, i: usize) -> ANNResult<T> {
self.0.get(i).cloned().ok_or_else(|| {
ANNError::message(
ANNErrorKind::Opaque,
format!(
"tried to index a slice of length {} at index {}",
self.0.len(),
i
),
)
let len = self.0.len();
ANNError::message(lazy_format!(
move,
"tried to index a slice of length {} at index {}",
len,
i
))
})
}
}
Expand Down Expand Up @@ -167,14 +166,13 @@ macro_rules! impl_range {
impl ToId<$T> for Range<$T> {
fn to_id(&self, i: usize) -> ANNResult<$T> {
self.0.clone().nth(i).ok_or_else(|| {
ANNError::message(
ANNErrorKind::Opaque,
format!(
"tried to index a range of length {} at index {}",
self.0.len(),
i
),
)
let len = self.0.len();
ANNError::message(lazy_format!(
move,
"tried to index a range of length {} at index {}",
len,
i
))
})
}
}
Expand Down
10 changes: 3 additions & 7 deletions diskann-benchmark-core/src/search/graph/strategy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

use std::{fmt::Debug, sync::Arc};

use diskann::ANNError;
use thiserror::Error;

/// A dynamic strategy (e.g. `diskann::graph::glue::SearchStrategy`) manager for built-in
Expand Down Expand Up @@ -168,12 +167,7 @@ impl Error {
}
}

impl From<Error> for ANNError {
#[track_caller]
fn from(error: Error) -> ANNError {
ANNError::opaque(error)
}
}
diskann::convert_error!(Error);

/// Error for an incorrect number of strategies.
///
Expand Down Expand Up @@ -228,6 +222,8 @@ impl std::error::Error for LengthIncompatible {}
mod tests {
use super::*;

use diskann::ANNError;

// Simple test strategy type
#[derive(Debug, Clone, PartialEq, Eq)]
struct TestStrategy(u32);
Expand Down
5 changes: 1 addition & 4 deletions diskann-benchmark/src/index/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use std::{num::NonZeroUsize, sync::Arc};

use diskann::{
error::DiskANNError::StartPointComputeError,
graph::{DiskANNIndex, StartPointStrategy},
provider::{self, DataProvider, DefaultContext},
ANNError, ANNResult,
Expand Down Expand Up @@ -43,9 +42,7 @@ where
DP: SetStartPoints<[T]>,
T: diskann::graph::SampleableForStart + AsyncFriendly,
{
let start_points = start_strategy
.compute(data)
.map_err(|e| ANNError::new(diskann::ANNErrorKind::DiskANN(StartPointComputeError), e))?;
let start_points = start_strategy.compute(data).map_err(ANNError::new)?;
provider.set_start_points(start_points.row_iter())
}

Expand Down
4 changes: 2 additions & 2 deletions diskann-benchmark/src/index/streaming/full_precision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use diskann::{
graph::{DiskANNIndex, InplaceDeleteMethod},
provider::{self, Delete},
utils::{VectorRepr, ONE},
ANNError, ANNErrorKind, ANNResult,
ANNError, ANNResult,
};
use diskann_benchmark_core::recall::{GroundTruthMode, Rows};
use diskann_providers::model::graph::provider::async_::{
Expand Down Expand Up @@ -210,7 +210,7 @@ where
for internal_id in range {
let internal_id: u32 = internal_id
.try_into()
.map_err(|_| ANNError::message(ANNErrorKind::Opaque, "invalid id provided"))?;
.map_err(|_| ANNError::message("invalid id provided"))?;
if provider
.status_by_external_id(ctx, &internal_id)
.await?
Expand Down
8 changes: 2 additions & 6 deletions diskann-benchmark/src/inputs/save_and_load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@ pub fn get_graph_num_frozen_points(
file.read_exact(&mut usize_buffer)?;
let file_frozen_pts = usize::from_le_bytes(usize_buffer);

NonZeroUsize::new(file_frozen_pts).ok_or_else(|| {
ANNError::log_index_config_error(
"num_frozen_pts".to_string(),
"num_frozen_pts is zero in saved file".to_string(),
)
})
NonZeroUsize::new(file_frozen_pts)
.ok_or_else(|| ANNError::message("num_frozen_pts is zero in saved file"))
}

pub fn get_graph_max_observed_degree(
Expand Down
8 changes: 4 additions & 4 deletions diskann-bftree/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl From<ConfigError> for ANNError {
#[track_caller]
#[inline(never)]
fn from(error: ConfigError) -> ANNError {
ANNError::new(diskann::ANNErrorKind::IndexError, error)
ANNError::new(error)
}
}

Expand Down Expand Up @@ -90,7 +90,7 @@ impl TransientError<ANNError> for VectorUnavailable {
where
D: std::fmt::Display,
{
ANNError::log_index_error(format!("{self}, escalated: {why}"))
ANNError::message(format!("{self}, escalated: {why}"))
}
}

Expand All @@ -107,7 +107,7 @@ pub(crate) fn validate_record_size(
let required = key_size + value_size;
let configured_max = config.get_cb_max_record_size();
if required > configured_max {
return Err(ANNError::log_index_error(format!(
return Err(ANNError::message(format!(
"{provider_name}: cb_max_record_size ({configured_max}) is too small; \
a record requires {required} bytes ({key_size}-byte key + {value_size}-byte value); \
increase cb_max_record_size to at least {required}"
Expand Down Expand Up @@ -214,6 +214,6 @@ impl std::error::Error for InsertError {}
impl From<InsertError> for ANNError {
#[track_caller]
fn from(error: InsertError) -> Self {
ANNError::new(diskann::ANNErrorKind::IndexError, error)
ANNError::new(error)
}
}
14 changes: 6 additions & 8 deletions diskann-bftree/src/neighbors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl<I: VectorId + IntoUsize> NeighborProvider<I> {
if read_size > 0 {
// A retrieved neighbor list should be exactly dim length
if read_size as usize != self.dim * std::mem::size_of::<I>() {
return Err(ANNError::log_index_error(
return Err(ANNError::message(
"Retrieved neighbor list is not expected length = max degree + 1",
));
}
Expand All @@ -135,7 +135,7 @@ impl<I: VectorId + IntoUsize> NeighborProvider<I> {

// The specified list length must be smaller than the retrieved data length
if count > self.max_degree() {
return Err(ANNError::log_index_error(
return Err(ANNError::message(
"Size of retrieved neighbor list is shorter than the stored neighbor count",
));
}
Expand All @@ -144,12 +144,12 @@ impl<I: VectorId + IntoUsize> NeighborProvider<I> {
}
}
bf_tree::LeafReadResult::Deleted => {
return Err(ANNError::log_index_error(
return Err(ANNError::message(
"The bf-tree entry for the vector is marked as deleted",
));
}
bf_tree::LeafReadResult::InvalidKey => {
return Err(ANNError::log_index_error(
return Err(ANNError::message(
"The bf-tree entry for the vector key is marked as invalid",
));
}
Expand Down Expand Up @@ -196,9 +196,7 @@ impl<I: VectorId + IntoUsize> NeighborProvider<I> {
self.num_get_calls.increment();

if buf.len() < self.dim {
return Err(ANNError::log_index_error(
"The provided buffer is not long enough",
));
return Err(ANNError::message("The provided buffer is not long enough"));
}

// Serialize the value into the reusable buffer.
Expand Down Expand Up @@ -227,7 +225,7 @@ impl<I: VectorId + IntoUsize> NeighborProvider<I> {
/// - Buffer length (in `I` cells) is smaller than `max_degree() + 1`
pub fn set_neighbors(&self, vector_id: I, neighbors: &[I], buf: &mut [I]) -> ANNResult<()> {
if neighbors.len() > self.dim - 1 {
return Err(ANNError::log_index_error(
return Err(ANNError::message(
"The provided neighbor list is longer than the max degree",
));
};
Expand Down
31 changes: 16 additions & 15 deletions diskann-bftree/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use diskann::{
};
use diskann_utils::{
future::{AsyncFriendly, SendFuture},
lazy_format,
views::MatrixView,
};
use diskann_vector::{distance::Metric, DistanceFunction, PreprocessedDistanceFunction};
Expand Down Expand Up @@ -343,7 +344,7 @@ where
{
// Early validation before allocating resources
if start_points.nrows() != params.num_start_points.get() {
return Err(ANNError::log_async_index_error(format!(
return Err(ANNError::message(format!(
"start_points matrix has {} rows, but params.num_start_points is {}",
start_points.nrows(),
params.num_start_points.get(),
Expand Down Expand Up @@ -732,7 +733,7 @@ where
fn set_start_points(&self, _hidden: Hidden, start_points: MatrixView<'_, T>) -> ANNResult<()> {
let start_point_ids = self.full_vectors.starting_points()?;
if start_points.nrows() != start_point_ids.len() {
return Err(ANNError::log_async_index_error(format!(
return Err(ANNError::message(format!(
"expected start_points to contain `{}` rows, instead it has {}",
start_point_ids.len(),
start_points.nrows(),
Expand Down Expand Up @@ -763,7 +764,7 @@ where
fn set_start_points(&self, _hidden: Hidden, start_points: MatrixView<'_, T>) -> ANNResult<()> {
let start_point_ids = self.full_vectors.starting_points()?;
if start_points.nrows() != start_point_ids.len() {
return Err(ANNError::log_async_index_error(format!(
return Err(ANNError::message(format!(
"expected start_points to contain `{}` rows, instead it has {}",
start_point_ids.len(),
start_points.nrows(),
Expand Down Expand Up @@ -1691,7 +1692,7 @@ fn save_bftree(
use_snapshot: bool,
) -> ANNResult<()> {
if !use_snapshot {
return Err(ANNError::log_index_error(
return Err(ANNError::message(
"cannot snapshot a BfTree that was not configured with use_snapshot(true)",
));
}
Expand Down Expand Up @@ -1726,7 +1727,7 @@ where
let saved_params = SavedParams {
max_points: self.max_points(),
frozen_points: NonZeroUsize::new(self.num_start_points())
.ok_or_else(|| ANNError::log_index_error("num_start_points is zero"))?,
.ok_or_else(|| ANNError::message("num_start_points is zero"))?,
dim: self.dim(),
metric: self.metric().as_str().to_string(),
max_degree: self.max_degree(),
Expand Down Expand Up @@ -1756,7 +1757,7 @@ where
{
let params_filename = BfTreePaths::params_json(&saved_params.prefix);
let params_json = serde_json::to_string(&saved_params).map_err(|e| {
ANNError::log_index_error(format!("Failed to serialize params: {}", e))
ANNError::message(lazy_format!(move, "Failed to serialize params: {}", e))
})?;
let mut params_writer = storage.create_for_write(&params_filename)?;
params_writer.write_all(params_json.as_bytes())?;
Expand Down Expand Up @@ -1793,12 +1794,12 @@ where
let mut params_json = String::new();
params_reader.read_to_string(&mut params_json)?;
serde_json::from_str(&params_json).map_err(|e| {
ANNError::log_index_error(format!("Failed to deserialize params: {}", e))
ANNError::message(lazy_format!(move, "Failed to deserialize params: {}", e))
})?
};

let metric = Metric::from_str(&saved_params.metric)
.map_err(|e| ANNError::log_index_error(format!("Failed to parse metric: {}", e)))?;
.map_err(|e| ANNError::message(lazy_format!(move, "Failed to parse metric: {}", e)))?;

let vector_index = load_bftree(
BfTreePaths::vectors_bftree(&saved_params.prefix),
Expand Down Expand Up @@ -1846,7 +1847,7 @@ where
let saved_params = SavedParams {
max_points: self.max_points(),
frozen_points: NonZeroUsize::new(self.num_start_points())
.ok_or_else(|| ANNError::log_index_error("num_start_points is zero"))?,
.ok_or_else(|| ANNError::message("num_start_points is zero"))?,
dim: self.dim(),
metric: self.metric().as_str().to_string(),
max_degree: self.max_degree(),
Expand Down Expand Up @@ -1887,7 +1888,7 @@ where
{
let params_filename = BfTreePaths::params_json(&saved_params.prefix);
let params_json = serde_json::to_string(&saved_params).map_err(|e| {
ANNError::log_index_error(format!("Failed to serialize params: {}", e))
ANNError::message(lazy_format!(move, "Failed to serialize params: {}", e))
})?;
let mut params_writer = storage.create_for_write(&params_filename)?;
params_writer.write_all(params_json.as_bytes())?;
Expand All @@ -1914,7 +1915,7 @@ where
.quant_vectors
.quantizer
.serialize(GlobalAllocator)
.map_err(|e| ANNError::log_index_error(format!("{e}")))?;
.map_err(|e| ANNError::message(lazy_format!(move, "{e}")))?;
let mut writer = storage.create_for_write(&filename)?;
writer.write_all(&serialized)?;

Expand All @@ -1938,16 +1939,16 @@ where
let mut params_json = String::new();
params_reader.read_to_string(&mut params_json)?;
serde_json::from_str(&params_json).map_err(|e| {
ANNError::log_index_error(format!("Failed to deserialize params: {}", e))
ANNError::message(lazy_format!(move, "Failed to deserialize params: {}", e))
})?
};

let _quant_params = saved_params.quant_params.ok_or_else(|| {
ANNError::log_index_error("Missing quant_params in saved params for quantized provider")
ANNError::message("Missing quant_params in saved params for quantized provider")
})?;

let metric = Metric::from_str(&saved_params.metric)
.map_err(|e| ANNError::log_index_error(format!("Failed to parse metric: {}", e)))?;
.map_err(|e| ANNError::message(lazy_format!(move, "Failed to parse metric: {}", e)))?;

let vector_index = load_bftree(
BfTreePaths::vectors_bftree(&saved_params.prefix),
Expand All @@ -1974,7 +1975,7 @@ where
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes)?;
let quantizer: Poly<dyn Quantizer> = try_deserialize(&bytes, GlobalAllocator)
.map_err(|e| ANNError::log_index_error(format!("{e}")))?;
.map_err(|e| ANNError::message(lazy_format!(move, "{e}")))?;

let quant_vector_index = load_bftree(
BfTreePaths::quant_bftree(&saved_params.prefix),
Expand Down
Loading
Loading