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
22 changes: 17 additions & 5 deletions diskann-disk/src/search/provider/disk_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use diskann::{
},
neighbor::Neighbor,
provider::{
Accessor, BuildQueryComputer, DataProvider, DefaultContext, DelegateNeighbor, HasId,
NeighborAccessor, NoopGuard,
Accessor, BuildQueryComputer, DataProvider, DefaultContext, DelegateNeighbor,
DistancesUnordered, HasElementRef, HasId, NeighborAccessor, NoopGuard,
},
utils::{IntoUsize, VectorRepr},
ANNError, ANNResult,
Expand Down Expand Up @@ -427,7 +427,13 @@ where
.to_vec(),
})
}
}

impl<Data, VP> DistancesUnordered<&[Data::VectorDataType]> for DiskAccessor<'_, Data, VP>
where
Data: GraphDataType<VectorIdType = u32>,
VP: VertexProvider<Data>,
{
async fn distances_unordered<Itr, F>(
&mut self,
vec_id_itr: Itr,
Expand Down Expand Up @@ -688,6 +694,15 @@ where
type Id = u32;
}

impl<Data, VP> HasElementRef for DiskAccessor<'_, Data, VP>
where
Data: GraphDataType<VectorIdType = u32>,
VP: VertexProvider<Data>,
{
/// `ElementRef` can have arbitrary lifetimes.
type ElementRef<'a> = &'a [u8];
}

impl<Data, VP> Accessor for DiskAccessor<'_, Data, VP>
where
Data: GraphDataType<VectorIdType = u32>,
Expand All @@ -700,9 +715,6 @@ where
where
Self: 'a;

/// `ElementRef` can have arbitrary lifetimes.
type ElementRef<'a> = &'a [u8];

/// Choose to panic on an out-of-bounds access rather than propagate an error.
type GetError = ANNError;

Expand Down
10 changes: 8 additions & 2 deletions diskann-garnet/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ use diskann::{
neighbor::Neighbor,
provider::{
Accessor, BuildDistanceComputer, BuildQueryComputer, DataProvider, DelegateNeighbor,
Delete, ElementStatus, HasId, NeighborAccessor, NeighborAccessorMut, NoopGuard, SetElement,
Delete, DistancesUnordered, ElementStatus, HasElementRef, HasId, NeighborAccessor,
NeighborAccessorMut, NoopGuard, SetElement,
},
utils::VectorRepr,
};
Expand Down Expand Up @@ -519,12 +520,15 @@ impl<T: VectorRepr> ExpandBeam<&[T]> for FullAccessor<'_, T> {
}
}

impl<T: VectorRepr> HasElementRef for FullAccessor<'_, T> {
type ElementRef<'a> = &'a [T];
}

impl<T: VectorRepr> Accessor for FullAccessor<'_, T> {
type Element<'a>
= Vec<T>
where
Self: 'a;
type ElementRef<'a> = &'a [T];
type GetError = GarnetProviderError;

fn get_element(
Expand Down Expand Up @@ -581,6 +585,8 @@ impl<T: VectorRepr> BuildQueryComputer<&[T]> for FullAccessor<'_, T> {
}
}

impl<T: VectorRepr> DistancesUnordered<&[T]> for FullAccessor<'_, T> {}

/// An escape hatch for the blanket implementation of [`workingset::Fill`].
///
/// Without an `&[T]: Into<Escape<T>>`, the blanket implementation for `workingset::Map`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use std::sync::{Arc, RwLock};
use diskann::{
error::{ErrorExt, IntoANNResult},
graph::glue::{ExpandBeam, SearchExt},
provider::{Accessor, AsNeighbor, BuildQueryComputer, DelegateNeighbor, HasId},
provider::{
Accessor, AsNeighbor, BuildQueryComputer, DelegateNeighbor, DistancesUnordered,
HasElementRef, HasId,
},
ANNError, ANNErrorKind,
};
use diskann_utils::Reborrow;
Expand Down Expand Up @@ -68,6 +71,13 @@ where
type Id = <IA as HasId>::Id;
}

impl<IA> HasElementRef for EncodedDocumentAccessor<IA>
where
IA: Accessor,
{
type ElementRef<'a> = EncodedDocument<IA::ElementRef<'a>, &'a RoaringTreemap>;
}

impl<IA> Accessor for EncodedDocumentAccessor<IA>
where
IA: Accessor,
Expand All @@ -76,7 +86,6 @@ where
= EncodedDocument<IA::Element<'a>, RoaringTreemap>
where
Self: 'a;
type ElementRef<'a> = EncodedDocument<IA::ElementRef<'a>, &'a RoaringTreemap>;
type GetError = ANNError;

async fn get_element(&mut self, id: Self::Id) -> Result<Self::Element<'_>, Self::GetError> {
Expand Down Expand Up @@ -164,7 +173,7 @@ where

impl<'q, IA, Q> BuildQueryComputer<&'q FilteredQuery<Q>> for EncodedDocumentAccessor<IA>
where
IA: BuildQueryComputer<&'q Q>,
IA: BuildQueryComputer<&'q Q> + Accessor,
{
type QueryComputerError = ANNError;
type QueryComputer = InlineBetaComputer<IA::QueryComputer>;
Expand Down Expand Up @@ -195,6 +204,14 @@ where
{
}

impl<IA, Q> DistancesUnordered<Q> for EncodedDocumentAccessor<IA>
where
IA: Accessor,
EncodedDocumentAccessor<IA>: BuildQueryComputer<Q>,
Q: Clone,
{
}

impl<'a, IA> DelegateNeighbor<'a> for EncodedDocumentAccessor<IA>
where
IA: DelegateNeighbor<'a>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pub struct FilterResults<IPP> {
impl<'q, Q, IA, IPP> SearchPostProcess<EncodedDocumentAccessor<IA>, &'q FilteredQuery<Q>>
for FilterResults<IPP>
where
IA: BuildQueryComputer<&'q Q>,
IA: BuildQueryComputer<&'q Q> + Accessor,
Q: Send + Sync,
IPP: SearchPostProcess<IA, &'q Q> + Send + Sync,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use diskann::{
neighbor::Neighbor,
provider::{
Accessor, BuildDistanceComputer, BuildQueryComputer, DataProvider, DefaultContext,
DelegateNeighbor, Delete, ElementStatus, HasId, NeighborAccessor, NeighborAccessorMut,
NoopGuard, SetElement,
DelegateNeighbor, Delete, DistancesUnordered, ElementStatus, HasElementRef, HasId,
NeighborAccessor, NeighborAccessorMut, NoopGuard, SetElement,
},
utils::{IntoUsize, VectorRepr},
};
Expand Down Expand Up @@ -974,6 +974,15 @@ where
}
}

impl<T, Q, D> HasElementRef for FullAccessor<'_, T, Q, D>
where
T: VectorRepr,
Q: AsyncFriendly,
D: AsyncFriendly,
{
type ElementRef<'a> = &'a [T];
}

impl<T, Q, D> Accessor for FullAccessor<'_, T, Q, D>
where
T: VectorRepr,
Expand All @@ -986,9 +995,6 @@ where
where
Self: 'a;

/// The reference version of `Element` is the same as `Element`.
type ElementRef<'a> = &'a [T];

// Choose to panic on an out-of-bounds access rather than propagate an error.
//
type GetError = Panics;
Expand Down Expand Up @@ -1058,6 +1064,14 @@ where
{
}

impl<T, Q, D> DistancesUnordered<&[T]> for FullAccessor<'_, T, Q, D>
where
T: VectorRepr,
Q: AsyncFriendly,
D: AsyncFriendly,
{
}

impl<'a, T, Q, D> AsDeletionCheck for FullAccessor<'a, T, Q, D>
where
T: VectorRepr,
Expand Down Expand Up @@ -1134,6 +1148,14 @@ where
}
}

impl<T, D> HasElementRef for QuantAccessor<'_, T, D>
where
T: VectorRepr,
D: AsyncFriendly,
{
type ElementRef<'a> = &'a [u8];
}

impl<T, D> Accessor for QuantAccessor<'_, T, D>
where
T: VectorRepr,
Expand All @@ -1145,9 +1167,6 @@ where
where
Self: 'a;

/// The reference version of `Element` is simply `Element`.
type ElementRef<'a> = &'a [u8];

// ANNError on access failures in bf-tree
//
type GetError = ANNError;
Expand Down Expand Up @@ -1220,6 +1239,13 @@ where
{
}

impl<T, D> DistancesUnordered<&[T]> for QuantAccessor<'_, T, D>
where
T: VectorRepr,
D: AsyncFriendly,
{
}

impl<'a, T, D> AsDeletionCheck for QuantAccessor<'a, T, D>
where
T: VectorRepr,
Expand Down Expand Up @@ -1282,6 +1308,14 @@ where
}
}

impl<T, D> HasElementRef for HybridAccessor<'_, T, D>
where
T: VectorRepr,
D: AsyncFriendly,
{
type ElementRef<'a> = distances::pq::Hybrid<&'a [T], &'a [u8]>;
}

impl<T, D> Accessor for HybridAccessor<'_, T, D>
where
T: VectorRepr,
Expand All @@ -1296,9 +1330,6 @@ where
where
Self: 'a;

/// The generalized reference form of `Element`.
type ElementRef<'a> = distances::pq::Hybrid<&'a [T], &'a [u8]>;

// Choose to panic on an out-of-bounds access rather than propagate an error.
type GetError = Panics;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ use diskann::{
neighbor::Neighbor,
provider::{
Accessor, AsNeighbor, BuildDistanceComputer, BuildQueryComputer, CacheableAccessor,
DataProvider, DelegateNeighbor, Delete, ElementStatus, HasId, NeighborAccessor,
NeighborAccessorMut, SetElement,
DataProvider, DelegateNeighbor, Delete, DistancesUnordered, ElementStatus, HasElementRef,
HasId, NeighborAccessor, NeighborAccessorMut, SetElement,
},
};
use diskann_utils::{
Expand Down Expand Up @@ -739,6 +739,14 @@ where
}
}

impl<A, C> HasElementRef for CachingAccessor<A, C>
where
A: CacheableAccessor,
C: ElementCache<A::Id, A::Map>,
{
type ElementRef<'a> = A::ElementRef<'a>;
}

impl<A, C> Accessor for CachingAccessor<A, C>
where
A: CacheableAccessor,
Expand All @@ -748,7 +756,6 @@ where
= A::Element<'a>
where
Self: 'a;
type ElementRef<'a> = A::ElementRef<'a>;

type GetError = CachingError<A::GetError, C::Error>;

Expand Down Expand Up @@ -825,6 +832,13 @@ where
{
}

impl<A, C, T> DistancesUnordered<T> for CachingAccessor<A, C>
where
A: BuildQueryComputer<T> + CacheableAccessor + AsNeighbor,
C: ElementCache<A::Id, A::Map> + NeighborCache<A::Id>,
{
}

/// Post Process
#[derive(Debug, Default, Clone, Copy)]
pub struct Unwrap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use diskann::{
neighbor::Neighbor,
provider::{
Accessor, BuildDistanceComputer, BuildQueryComputer, DefaultContext, DelegateNeighbor,
ExecutionContext, HasId,
DistancesUnordered, ExecutionContext, HasElementRef, HasId,
},
utils::{IntoUsize, VectorRepr},
};
Expand Down Expand Up @@ -185,6 +185,16 @@ where
}
}

impl<T, Q, D, Ctx> HasElementRef for FullAccessor<'_, T, Q, D, Ctx>
where
T: VectorRepr,
Q: AsyncFriendly,
D: AsyncFriendly,
Ctx: ExecutionContext,
{
type ElementRef<'a> = &'a [T];
}

impl<T, Q, D, Ctx> Accessor for FullAccessor<'_, T, Q, D, Ctx>
where
T: VectorRepr,
Expand All @@ -199,9 +209,6 @@ where
where
Self: 'a;

/// `ElementRef` has an arbitrarily short lifetime.
type ElementRef<'a> = &'a [T];

/// Choose to panic on an out-of-bounds access rather than propagate an error.
type GetError = Panics;

Expand Down Expand Up @@ -316,6 +323,15 @@ where
{
}

impl<T, Q, D, Ctx> DistancesUnordered<&[T]> for FullAccessor<'_, T, Q, D, Ctx>
where
T: VectorRepr,
Q: AsyncFriendly,
D: AsyncFriendly,
Ctx: ExecutionContext,
{
}

//-------------------//
// In-mem Extensions //
//-------------------//
Expand Down Expand Up @@ -353,7 +369,7 @@ pub struct Rerank;
impl<'a, A, T> glue::SearchPostProcess<A, &'a [T]> for Rerank
where
T: VectorRepr,
A: BuildQueryComputer<&'a [T], Id = u32> + GetFullPrecision<Repr = T> + AsDeletionCheck,
A: BuildQueryComputer<&'a [T]> + HasId<Id = u32> + GetFullPrecision<Repr = T> + AsDeletionCheck,
{
type Error = Panics;

Expand Down
Loading
Loading