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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ criterion = "0.5.1"
crossbeam-queue = { version = "0.3.12", default-features = false }
crossbeam-utils = { version = "0.8.23", default-features = false }
dashmap = "6.1.0"
erased-serde = "0.4.11"
futures-util = { version = "0.3.31", default-features = false }
half = "2.6.0"
hashbrown = "0.16.0"
Expand Down
2 changes: 1 addition & 1 deletion diskann-benchmark-runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ edition = "2024"
[dependencies]
anyhow = { workspace = true }
clap = { workspace = true, features = ["derive"] }
erased-serde = "0.4.11"
erased-serde = { workspace = true }
half = { workspace = true }
indicatif = "0.18.3"
serde = { workspace = true, features = ["derive"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"append_neighbors": 39095,
"distance": 549876,
"get_neighbors": 298634,
"get_vector": 2008258,
"get_vector": 2032786,
"query_distance": 1724191,
"set_neighbors": 11168,
"set_vector": 10000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"append_neighbors": 128225,
"distance": 5596404,
"get_neighbors": 384814,
"get_vector": 2467136,
"get_vector": 3131891,
"query_distance": 1545792,
"set_neighbors": 41655,
"set_vector": 10000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"append_neighbors": 37939,
"distance": 533446,
"get_neighbors": 297940,
"get_vector": 1985381,
"get_vector": 2008439,
"query_distance": 1702322,
"set_neighbors": 11098,
"set_vector": 10000
Expand Down Expand Up @@ -171,7 +171,7 @@
"append_neighbors": 37939,
"distance": 533446,
"get_neighbors": 297940,
"get_vector": 1985381,
"get_vector": 2008439,
"query_distance": 1702322,
"set_neighbors": 11098,
"set_vector": 10000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"append_neighbors": 100311,
"distance": 3063537,
"get_neighbors": 357204,
"get_vector": 2824455,
"get_vector": 3132525,
"query_distance": 2259492,
"set_neighbors": 24670,
"set_vector": 10000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"append_neighbors": 128219,
"distance": 5554287,
"get_neighbors": 380443,
"get_vector": 3110524,
"get_vector": 3775405,
"query_distance": 2193419,
"set_neighbors": 41661,
"set_vector": 10000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"append_neighbors": 125092,
"distance": 4903759,
"get_neighbors": 401105,
"get_vector": 3459145,
"get_vector": 3990928,
"query_distance": 2651349,
"set_neighbors": 35323,
"set_vector": 10000
Expand Down Expand Up @@ -173,7 +173,7 @@
"append_neighbors": 125092,
"distance": 4903759,
"get_neighbors": 401105,
"get_vector": 3459145,
"get_vector": 3990928,
"query_distance": 2651349,
"set_neighbors": 35323,
"set_vector": 10000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"append_neighbors": 107423,
"distance": 3639726,
"get_neighbors": 368584,
"get_vector": 3001191,
"get_vector": 3380724,
"query_distance": 2360497,
"set_neighbors": 28073,
"set_vector": 10000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"append_neighbors": 100733,
"distance": 3083799,
"get_neighbors": 358175,
"get_vector": 2811083,
"get_vector": 3124613,
"query_distance": 2240111,
"set_neighbors": 24930,
"set_vector": 10000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"append_neighbors": 128260,
"distance": 5569637,
"get_neighbors": 380639,
"get_vector": 3119103,
"get_vector": 3783123,
"query_distance": 2202704,
"set_neighbors": 41620,
"set_vector": 10000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"append_neighbors": 100455,
"distance": 3077148,
"get_neighbors": 357944,
"get_vector": 2803941,
"get_vector": 3115938,
"query_distance": 2234455,
"set_neighbors": 24857,
"set_vector": 10000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"append_neighbors": 104911,
"distance": 3391469,
"get_neighbors": 371616,
"get_vector": 3179260,
"get_vector": 3517759,
"query_distance": 2574056,
"set_neighbors": 26119,
"set_vector": 10000
Expand Down Expand Up @@ -171,7 +171,7 @@
"append_neighbors": 104911,
"distance": 3391469,
"get_neighbors": 371616,
"get_vector": 3179260,
"get_vector": 3517759,
"query_distance": 2574056,
"set_neighbors": 26119,
"set_vector": 10000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"append_neighbors": 128385,
"distance": 5555853,
"get_neighbors": 380952,
"get_vector": 3252844,
"get_vector": 3914239,
"query_distance": 2338882,
"set_neighbors": 41495,
"set_vector": 10000
Expand Down Expand Up @@ -171,7 +171,7 @@
"append_neighbors": 128385,
"distance": 5555853,
"get_neighbors": 380952,
"get_vector": 3252844,
"get_vector": 3914239,
"query_distance": 2338882,
"set_neighbors": 41495,
"set_vector": 10000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"append_neighbors": 104879,
"distance": 3387869,
"get_neighbors": 370460,
"get_vector": 3161112,
"get_vector": 3500913,
"query_distance": 2555730,
"set_neighbors": 26181,
"set_vector": 10000
Expand Down Expand Up @@ -171,7 +171,7 @@
"append_neighbors": 104879,
"distance": 3387869,
"get_neighbors": 370460,
"get_vector": 3161112,
"get_vector": 3500913,
"query_distance": 2555730,
"set_neighbors": 26181,
"set_vector": 10000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"append_neighbors": 103313,
"distance": 3222189,
"get_neighbors": 362992,
"get_vector": 2907863,
"get_vector": 3236282,
"query_distance": 2319765,
"set_neighbors": 25639,
"set_vector": 10000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"append_neighbors": 128278,
"distance": 5549845,
"get_neighbors": 380582,
"get_vector": 3182824,
"get_vector": 3846466,
"query_distance": 2266878,
"set_neighbors": 41602,
"set_vector": 10000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"append_neighbors": 102671,
"distance": 3195226,
"get_neighbors": 362395,
"get_vector": 2896757,
"get_vector": 3222110,
"query_distance": 2311680,
"set_neighbors": 25493,
"set_vector": 10000
Expand Down
8 changes: 4 additions & 4 deletions diskann-inmem/integration/jsons/integration-baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"append_neighbors": 96949,
"distance": 2867876,
"get_neighbors": 352139,
"get_vector": 2781513,
"get_vector": 3067092,
"query_distance": 2240744,
"set_neighbors": 23599,
"set_vector": 10000
Expand Down Expand Up @@ -169,7 +169,7 @@
"append_neighbors": 96949,
"distance": 2867876,
"get_neighbors": 352139,
"get_vector": 2781513,
"get_vector": 3067092,
"query_distance": 2240744,
"set_neighbors": 23599,
"set_vector": 10000
Expand Down Expand Up @@ -290,7 +290,7 @@
"append_neighbors": 96949,
"distance": 2867876,
"get_neighbors": 352139,
"get_vector": 2781513,
"get_vector": 3067092,
"query_distance": 2240744,
"set_neighbors": 23599,
"set_vector": 10000
Expand Down Expand Up @@ -414,7 +414,7 @@
"append_neighbors": 97055,
"distance": 2867292,
"get_neighbors": 352087,
"get_vector": 2778779,
"get_vector": 3064106,
"query_distance": 2238420,
"set_neighbors": 23587,
"set_vector": 10000
Expand Down
5 changes: 5 additions & 0 deletions diskann-inmem/src/counters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ mod inner {
pub(crate) fn query_distance(&mut self, _i: u64) {}
pub(crate) fn distance_ref(&self, _i: u64) {}
pub(crate) fn get_vector(&mut self, _i: u64) {}
pub(crate) fn get_vector_ref(&self, _i: u64) {}
pub(crate) fn set_vector(&mut self, _i: u64) {}
pub(crate) fn get_neighbors(&mut self, _i: u64) {}
pub(crate) fn set_neighbors(&mut self, _i: u64) {}
Expand Down Expand Up @@ -135,6 +136,10 @@ mod inner {
*self.get_vector.get_mut() += i;
}

pub(crate) fn get_vector_ref(&self, i: u64) {
self.get_vector.fetch_add(i, Relaxed);
}

pub(crate) fn set_vector(&mut self, i: u64) {
self.set_vector += i;
}
Expand Down
32 changes: 13 additions & 19 deletions diskann-inmem/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,6 @@ impl glue::SearchAccessor for SearchAccessor<'_> {
#[derive(Debug)]
pub struct PruneAccessor<'a> {
prune: Box<dyn repr::Prune + 'a>,
keys: hashbrown::HashMap<u32, Option<repr::PruneKey>>,
neighbors: &'a Neighbors,
counters: LocalCounters<'a>,
}
Expand All @@ -428,7 +427,6 @@ impl<'a> PruneAccessor<'a> {
) -> Self {
Self {
prune,
keys: hashbrown::HashMap::new(),
neighbors,
counters,
}
Expand Down Expand Up @@ -456,18 +454,18 @@ impl<'a> Distance<'a> {
/// An opaque element-ref for [`PruneAccessor`].
#[derive(Debug, Clone, Copy)]
#[repr(transparent)]
pub struct ElementRef(repr::PruneKey);
pub struct ElementRef<'a>(&'a [u8]);

impl<'a> diskann_utils::Reborrow<'a> for ElementRef {
type Target = ElementRef;
impl<'a> diskann_utils::Reborrow<'a> for ElementRef<'_> {
type Target = ElementRef<'a>;
fn reborrow(&'a self) -> Self {
*self
Self(self.0)
}
}

impl diskann_vector::DistanceFunction<ElementRef, ElementRef, f32> for Distance<'_> {
impl diskann_vector::DistanceFunction<ElementRef<'_>, ElementRef<'_>, f32> for Distance<'_> {
#[inline]
fn evaluate_similarity(&self, x: ElementRef, y: ElementRef) -> f32 {
fn evaluate_similarity(&self, x: ElementRef<'_>, y: ElementRef<'_>) -> f32 {
self.counters.distance_ref(1);
self.prune.evaluate(x.0, y.0)
}
Expand All @@ -483,7 +481,7 @@ impl glue::PruneAccessor for PruneAccessor<'_> {
where
Self: 'a;

type ElementRef<'a> = ElementRef;
type ElementRef<'a> = ElementRef<'a>;

type View<'a>
= &'a Self
Expand All @@ -501,16 +499,11 @@ impl glue::PruneAccessor for PruneAccessor<'_> {

async fn fill<'a, Itr>(
&'a mut self,
itr: Itr,
_itr: Itr,
) -> ANNResult<(Self::View<'a>, Self::Distance<'a>)>
where
Itr: ExactSizeIterator<Item = Self::Id> + Clone + Send + Sync,
{
self.keys.clear();
self.keys.extend(itr.map(|i| (i, None)));
let count: usize = self.prune.prepare(self.keys.iter_mut())?;
self.counters.get_vector(count as u64);

Ok((self, Distance::new(&*self.prune, self.counters.fork())))
}
}
Expand Down Expand Up @@ -573,14 +566,15 @@ impl provider::NeighborAccessorMut for PruneAccessor<'_> {
}

impl workingset::View<u32> for &PruneAccessor<'_> {
type ElementRef<'a> = ElementRef;
type ElementRef<'a> = ElementRef<'a>;
type Element<'a>
= ElementRef
= ElementRef<'a>
where
Self: 'a;

fn get(&self, id: u32) -> Option<ElementRef> {
self.keys.get(&id)?.map(ElementRef)
fn get(&self, id: u32) -> Option<ElementRef<'_>> {
self.counters.get_vector_ref(1);
self.prune.get(id).map(ElementRef)
}
}

Expand Down
Loading
Loading