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
3 changes: 2 additions & 1 deletion diskann-benchmark/src/exhaustive/algos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ where

let search = start.elapsed().into();

std::iter::zip(o.iter_mut(), queue.iter()).for_each(|(o, neighbor)| *o = neighbor.id);
std::iter::zip(o.iter_mut(), queue.iter())
.for_each(|(o, neighbor)| *o = *neighbor.id());
progress.inc(1);
Ok(Times { preprocess, search })
})
Expand Down
14 changes: 7 additions & 7 deletions diskann-bftree/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1540,11 +1540,11 @@ where
for n in candidates {
match provider
.full_vectors
.get_vector_sync(n.id.into_usize())
.get_vector_sync(n.id().into_usize())
.allow_transient("stale candidate during rerank")
{
Ok(Some(vec)) => {
reranked.push((n.id, f.evaluate_similarity(query, &vec)));
reranked.push((*n.id(), f.evaluate_similarity(query, &vec)));
}
Ok(None) => {
// Transient (deleted/missing) — skip this candidate.
Expand Down Expand Up @@ -2092,7 +2092,7 @@ mod tests {
res.result_count, 5,
"there are 15 points and we're asking for 5, we expect 5"
);
assert_eq!(neighbors[0].id, 3);
assert_eq!(*neighbors[0].id(), 3);
}

#[tokio::test]
Expand Down Expand Up @@ -2143,7 +2143,7 @@ mod tests {
res.result_count, 5,
"there are 15 points and we're asking for 5, we expect 5"
);
let neighbor_ids: Vec<u32> = neighbors.iter().map(|n| n.id).collect();
let neighbor_ids: Vec<u32> = neighbors.iter().map(|n| *n.id()).collect();
for expected in 1u32..=5 {
assert!(
neighbor_ids.contains(&expected),
Expand Down Expand Up @@ -2190,7 +2190,7 @@ mod tests {
.unwrap();

assert_eq!(res.result_count, 5);
let neighbor_ids: Vec<u32> = neighbors.iter().map(|n| n.id).collect();
let neighbor_ids: Vec<u32> = neighbors.iter().map(|n| *n.id()).collect();
assert!(!neighbor_ids.contains(&2u32));
assert!(!neighbor_ids.contains(&4u32));
}
Expand Down Expand Up @@ -2264,7 +2264,7 @@ mod tests {
res.result_count, 5,
"there are 15 points and we're asking for 5, we expect 5"
);
assert_eq!(neighbors[0].id, 3);
assert_eq!(*neighbors[0].id(), 3);
}

#[tokio::test]
Expand Down Expand Up @@ -2317,7 +2317,7 @@ mod tests {
.unwrap();

assert_eq!(res.result_count, 5);
let neighbor_ids: Vec<u32> = neighbors.iter().map(|n| n.id).collect();
let neighbor_ids: Vec<u32> = neighbors.iter().map(|n| *n.id()).collect();
assert!(!neighbor_ids.contains(&2u32));
assert!(!neighbor_ids.contains(&4u32));
}
Expand Down
12 changes: 6 additions & 6 deletions diskann-disk/src/search/provider/disk_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,11 @@ where
};
match self.filter {
PostprocessStrategy::AcceptAll => candidates
.map(|n| n.id)
.map(|n| *n.id())
.filter_map(&mut process)
.collect::<Result<Vec<_>, _>>()?,
PostprocessStrategy::Apply(f) => candidates
.map(|n| n.id)
.map(|n| *n.id())
.filter(|id| f(id))
.filter_map(&mut process)
.collect::<Result<Vec<_>, _>>()?,
Expand Down Expand Up @@ -419,9 +419,9 @@ where
let query_f32 = Data::VectorDataType::as_f32(query).map_err(Into::into)?;

let candidate_ids: Vec<u32> = match self.filter {
PostprocessStrategy::AcceptAll => candidates.map(|candidate| candidate.id).collect(),
PostprocessStrategy::AcceptAll => candidates.map(|candidate| *candidate.id()).collect(),
PostprocessStrategy::Apply(f) => candidates
.map(|candidate| candidate.id)
.map(|candidate| *candidate.id())
.filter(|id| f(id))
.collect(),
};
Expand Down Expand Up @@ -1805,7 +1805,7 @@ mod disk_provider_tests {
let ids = search_record
.visited
.iter()
.map(|n| n.id)
.map(|n| *n.id())
.collect::<Vec<_>>();

const EXPECTED_NODES: [u32; 18] = [
Expand Down Expand Up @@ -2503,7 +2503,7 @@ mod disk_provider_tests {
let visited_ids = search_record
.visited
.iter()
.map(|n| n.id)
.map(|n| *n.id())
.collect::<Vec<_>>();

let query_stats = strategy.io_tracker;
Expand Down
10 changes: 5 additions & 5 deletions diskann-garnet/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1227,12 +1227,12 @@ impl<'a, T: VectorRepr> SearchPostProcess<DynamicAccessor<'a, T>, &[T], GarnetId
{
let initial = output.current_len();
for n in candidates {
let id = match accessor.provider.to_external_id(accessor.context, n.id) {
let id = match accessor.provider.to_external_id(accessor.context, *n.id()) {
Ok(id) => id,
Err(_) => continue, // Can't read the mapping; skip.
};

if output.push(id, n.distance).is_full() {
if output.push(id, n.distance()).is_full() {
break;
}
}
Expand Down Expand Up @@ -1284,15 +1284,15 @@ impl<'a, 'b, T: VectorRepr> SearchPostProcessStep<DynamicAccessor<'a, T>, &'b [T
// Filter before computing the full precision distances.
let mut reranked: Vec<(u32, f32)> = candidates
.filter_map(|n| {
if !provider.vector_iid_exists(accessor.context, n.id) {
if !provider.vector_iid_exists(accessor.context, *n.id()) {
None
} else if provider.callbacks.read_single_iid(
&accessor.context.term(Term::Vector),
n.id,
*n.id(),
&mut v,
) {
Some((
n.id,
*n.id(),
f.evaluate_similarity(query, bytemuck::cast_slice::<u8, T>(&v)),
))
} else {
Expand Down
19 changes: 11 additions & 8 deletions diskann-label-filter/src/inline_beta_search/inline_beta_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,17 @@ where
// TODO: Fix for performance.
let mut filtered_candidates = Vec::<Neighbor<IA::Id>>::new();
for candidate in candidates {
accessor.attributes_for(candidate.id, |computer, attributes| -> ANNResult<()> {
let pe = PredicateEvaluator::new(&*attributes);

if computer.filter_expr().encoded_filter_expr().accept(&pe)? {
filtered_candidates.push(Neighbor::new(candidate.id, candidate.distance));
}
Ok(())
})??;
accessor.attributes_for(
*candidate.id(),
|computer, attributes| -> ANNResult<()> {
let pe = PredicateEvaluator::new(&*attributes);

if computer.filter_expr().encoded_filter_expr().accept(&pe)? {
filtered_candidates.push(candidate);
}
Ok(())
},
)??;
}

// Assuming that the job of the post processor is to only forward the right set of
Expand Down
22 changes: 11 additions & 11 deletions diskann-providers/src/index/diskann_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ pub(crate) mod tests {
search::Range,
search_output_buffer,
},
neighbor::Neighbor,
neighbor::{self, Neighbor},
provider::{
DataProvider, DefaultContext, Delete, ExecutionContext, Guard, NeighborAccessor,
NeighborAccessorMut, SetElement,
Expand Down Expand Up @@ -916,17 +916,17 @@ pub(crate) mod tests {

let checker = |position, (id, distance)| -> Result<(), Box<dyn std::fmt::Display>> {
let expected: Neighbor<u32> = gt[gt.len() - 1 - position];
if id != expected.id {
if id != *expected.id() {
// We can allow it if the distance is the same.
if distance == expected.distance {
if distance == expected.distance() {
Ok(())
} else {
Err(Box::new(format!(
"expected neighbor {:?}, but found {}",
expected, id
)))
}
} else if distance != expected.distance {
} else if distance != expected.distance() {
Err(Box::new(format!(
"expected neighbor {:?}, but found {}",
expected, distance
Expand Down Expand Up @@ -1085,11 +1085,11 @@ pub(crate) mod tests {
let gt = {
let mut gt = groundtruth(corpus.as_view(), &query, |a, b| SquaredL2::evaluate(a, b));
for n in gt.iter_mut() {
if filter.is_match(n.id) {
n.distance *= beta;
if filter.is_match(*n.id()) {
*n = Neighbor::new(*n.id(), n.distance() * beta);
}
}
gt.sort_unstable_by(|a, b| a.cmp(b).reverse());
gt.sort_unstable_by(neighbor::ord::reverse(neighbor::ord::fast_distance));
gt
};

Expand Down Expand Up @@ -1528,7 +1528,7 @@ pub(crate) mod tests {
.await
.unwrap();

let ids: Vec<u32> = results.iter().map(|n| n.id).collect();
let ids: Vec<u32> = results.iter().map(|n| *n.id()).collect();
assert_range_results_exactly_match(q, &gt, &ids, radius, None);
}

Expand All @@ -1541,7 +1541,7 @@ pub(crate) mod tests {
.await
.unwrap();

let ids: Vec<u32> = results.iter().map(|n| n.id).collect();
let ids: Vec<u32> = results.iter().map(|n| *n.id()).collect();
assert_range_results_exactly_match(q, &gt, &ids, radius, None);
}

Expand All @@ -1565,7 +1565,7 @@ pub(crate) mod tests {
.await
.unwrap();

let ids: Vec<u32> = results.iter().map(|n| n.id).collect();
let ids: Vec<u32> = results.iter().map(|n| *n.id()).collect();
assert_range_results_exactly_match(q, &gt, &ids, radius, Some(inner_radius));
}

Expand All @@ -1582,7 +1582,7 @@ pub(crate) mod tests {
// check that ids don't have duplicates
let mut ids_set = std::collections::HashSet::new();
for n in &results {
assert!(ids_set.insert(n.id));
assert!(ids_set.insert(*n.id()));
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions diskann-providers/src/index/wrapped_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -836,16 +836,17 @@ mod tests {

for neighbor in v {
assert_ne!(
neighbor.id,
*neighbor.id(),
u32::MAX,
"paged search should not return start point",
);
assert_eq!(
neighbor.id, i,
*neighbor.id(),
i,
"monotonicity should at least hold for the 1d grid"
);
assert_eq!(
neighbor.distance,
neighbor.distance(),
(i as f32) * (i as f32),
"distance was computed incorrectly!",
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,13 +381,13 @@ where
// Filter before computing the full precision distances.
let mut reranked: Vec<(u32, f32)> = candidates
.filter_map(|n| {
if checker.deletion_check(n.id) {
if checker.deletion_check(*n.id()) {
None
} else {
Some((
n.id,
*n.id(),
f.evaluate_similarity(query, unsafe {
full.get_vector_sync(n.id.into_usize())
full.get_vector_sync(n.id().into_usize())
}),
))
}
Expand Down Expand Up @@ -445,9 +445,9 @@ where
for (i, candidate) in candidates.into_iter().enumerate() {
// SAFETY: We accept potential unsynchronized concurrent mutation, matching the
// pattern used by `Rerank` above.
let vector = unsafe { store.get_vector_sync(candidate.id.into_usize()) };
ids.push(candidate.id);
distances.push(candidate.distance);
let vector = unsafe { store.get_vector_sync(candidate.id().into_usize()) };
ids.push(*candidate.id());
distances.push(candidate.distance());
vectors.row_mut(i).copy_from_slice(vector);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ where
{
let checker = accessor.as_deletion_check();
let count = output.extend(candidates.filter_map(|n| {
if checker.deletion_check(n.id) {
if checker.deletion_check(*n.id()) {
None
} else {
Some((n.id, n.distance))
Some(n.as_tuple())
}
}));
std::future::ready(Ok(count))
Expand Down
28 changes: 16 additions & 12 deletions diskann-providers/src/test_utils/search_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT license.
*/

use diskann::neighbor::Neighbor;
use diskann::neighbor::{self, Neighbor};
use diskann_utils::views::MatrixView;

/// Compute the ground truth for a small dataset.
Expand All @@ -23,7 +23,7 @@ where
.map(|(i, row)| Neighbor::new(i as u32, f(row, query)))
.collect();

results.sort_unstable_by(|a, b| a.cmp(b).reverse());
results.sort_unstable_by(neighbor::ord::reverse(neighbor::ord::fast_distance));
results
}

Expand All @@ -43,10 +43,10 @@ pub fn is_match(
for i in (0..groundtruth.len()).rev() {
// Check if the distance matches.
let gt = groundtruth[i];
if (gt.distance - neighbor.distance).abs() > margin {
if (gt.distance() - neighbor.distance()).abs() > margin {
return None;
}
if gt.id == neighbor.id {
if gt.id() == neighbor.id() {
return Some(i);
}
}
Expand All @@ -70,14 +70,18 @@ pub fn assert_top_k_exactly_match(
for i in 0..top_k {
let neighbor = gt[gt.len() - 1 - i];
assert_eq!(
neighbor.distance, distances[i],
neighbor.distance(),
distances[i],
"failed on query {} for result {}",
query_id, i
query_id,
i
);
assert_eq!(
neighbor.id, ids[i],
*neighbor.id(),
ids[i],
"failed on query {} for result {}",
query_id, i
query_id,
i
);
}
}
Expand All @@ -96,13 +100,13 @@ pub fn assert_range_results_exactly_match(
) {
let gt_ids = if let Some(inner_radius) = inner_radius {
gt.iter()
.filter(|nbh| nbh.distance >= inner_radius && nbh.distance <= radius)
.map(|nbh| nbh.id)
.filter(|nbh| nbh.distance() >= inner_radius && nbh.distance() <= radius)
.map(|nbh| *nbh.id())
.collect::<Vec<_>>()
} else {
gt.iter()
.filter(|nbh| nbh.distance <= radius)
.map(|nbh| nbh.id)
.filter(|nbh| nbh.distance() <= radius)
.map(|nbh| *nbh.id())
.collect::<Vec<_>>()
};
if ids.iter().any(|id| !gt_ids.contains(id)) {
Expand Down
Loading
Loading