pub struct PQScratch {
pub aligned_pqtable_dist_scratch: Poly<[f32], AlignedAllocator>,
pub aligned_dist_scratch: Poly<[f32], AlignedAllocator>,
pub aligned_pq_coord_scratch: Poly<[u8], AlignedAllocator>,
pub query_scratch: Vec<f32>,
}Expand description
PQ scratch
Fields§
§aligned_pqtable_dist_scratch: Poly<[f32], AlignedAllocator>Aligned pq table distance scratch, the length must be at least [256 * NCHUNKS]. 256 is the number of PQ centroids. This is used to store the distance between each chunk in the query vector to each centroid, which is why the length is num of centroids * num of chunks
aligned_dist_scratch: Poly<[f32], AlignedAllocator>Aligned dist scratch, must be at least diskann MAX_DEGREE This is used to temporarily save the pq distance between query vector to the candidate vectors.
aligned_pq_coord_scratch: Poly<[u8], AlignedAllocator>Aligned pq coord scratch, must be at least [N_CHUNKS * MAX_DEGREE] This is used to store the pq coordinates of the candidate vectors.
query_scratch: Vec<f32>Query scratch buffer stored as f32, sized by the PQ table’s logical dimension.
set populates it from a caller-provided &[f32]; PQTable::preprocess_query can
then rotate or otherwise preprocess it.
Implementations§
Source§impl PQScratch
impl PQScratch
Sourcepub fn new(
graph_degree: usize,
dim: usize,
num_pq_chunks: usize,
num_centers: usize,
) -> ANNResult<Self>
pub fn new( graph_degree: usize, dim: usize, num_pq_chunks: usize, num_centers: usize, ) -> ANNResult<Self>
Create a new pq scratch.
dim is the PQ table’s logical dimension (PQData::get_dim()); the
internal query_scratch buffer is sized to exactly this many f32 slots.
Sourcepub fn set(&mut self, query: &[f32]) -> ANNResult<()>
pub fn set(&mut self, query: &[f32]) -> ANNResult<()>
Copy the first dim elements of query into query_scratch.
query must already be in full-precision f32 representation; quantized
inputs (e.g. MinMaxElement) should be decoded via VectorRepr::as_f32
at the caller boundary before invoking this method.
Accepts oversized query (only the first dim elements are used) for
backwards compatibility with callers that hold alignment-padded buffers.
Returns DimensionMismatchError if query.len() < query_scratch.len().
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PQScratch
impl RefUnwindSafe for PQScratch
impl Send for PQScratch
impl Sync for PQScratch
impl Unpin for PQScratch
impl UnsafeUnpin for PQScratch
impl UnwindSafe for PQScratch
Blanket Implementations§
impl<T> AsyncFriendly for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more