Skip to main content

VectorBase

Struct VectorBase 

Source
pub struct VectorBase<const NBITS: usize, Repr, Ptr, T, Perm = Dense>
where Ptr: AsPtr<Type = u8>, Repr: Representation<NBITS>, Perm: PermutationStrategy<NBITS>,
{ /* private fields */ }
Expand description

A wrapper for BitSliceBase that provides the addition of arbitrary metadata.

§Examples

The VectorBase has several named variants that are commonly used:

  • Vector: An owning, independently allocated VectorBase.
  • VectorMut: A mutable, reference-like type to a VectorBase.
  • VectorRef: A const, reference-like type to a VectorBase.
use diskann_quantization::{
    meta::{Vector, VectorMut, VectorRef},
    bits::Unsigned,
};

use diskann_utils::{Reborrow, ReborrowMut};

#[derive(Debug, Default, Clone, Copy, PartialEq)]
struct Metadata {
    value: f32,
}

// Create a new heap-allocated Vector for 4-bit compressions capable of
// holding 3 elements.
//
// In this case, the associated m
let mut v = Vector::<4, Unsigned, Metadata>::new_boxed(3);

// We can inspect the underlying bitslice.
let bitslice = v.vector();
assert_eq!(bitslice.get(0).unwrap(), 0);
assert_eq!(bitslice.get(1).unwrap(), 0);
assert_eq!(v.meta(), Metadata::default(), "expected default metadata value");

// If we want, we can mutably borrow the bitslice and mutate its components.
let mut bitslice = v.vector_mut();
bitslice.set(0, 1).unwrap();
bitslice.set(1, 2).unwrap();
bitslice.set(2, 3).unwrap();

assert!(bitslice.set(3, 4).is_err(), "out-of-bounds access");

// Get the underlying pointer for comparison.
let ptr = bitslice.as_ptr();

// Vectors can be converted to a generalized reference.
let mut v_ref = v.reborrow_mut();

// The generalized reference preserves the underlying pointer.
assert_eq!(v_ref.vector().as_ptr(), ptr);
let mut bitslice = v_ref.vector_mut();
bitslice.set(0, 10).unwrap();

// Setting the underlying compensation will be visible in the original allocation.
v_ref.set_meta(Metadata { value: 10.5 });

// Check that the changes are visible.
assert_eq!(v.meta().value, 10.5);
assert_eq!(v.vector().get(0).unwrap(), 10);

// Finally, the immutable ref also maintains pointer compatibility.
let v_ref = v.reborrow();
assert_eq!(v_ref.vector().as_ptr(), ptr);

§Constructing a VectorMut From Components

The following example shows how to assemble a VectorMut from raw memory.

use diskann_quantization::{bits::{Unsigned, MutBitSlice}, meta::VectorMut};

// Start with 2 bytes of memory. We will impose a 4-bit scalar quantization on top of
// these 2 bytes.
let mut data = vec![0u8; 2];
let mut metadata: f32 = 0.0;
{
    // First, we need to construct a bit-slice over the data.
    // This will check that it is sized properly for 4, 4-bit values.
    let mut slice = MutBitSlice::<4, Unsigned>::new(data.as_mut_slice(), 4).unwrap();

    // Next, we construct the `VectorMut`.
    let mut v = VectorMut::new(slice, &mut metadata);

    // Through `v`, we can set all the components in `slice` and the compensation.
    v.set_meta(123.4);
    let mut from_v = v.vector_mut();
    from_v.set(0, 1).unwrap();
    from_v.set(1, 2).unwrap();
    from_v.set(2, 3).unwrap();
    from_v.set(3, 4).unwrap();
}

// Now we can check that the changes made internally are visible.
assert_eq!(&data, &[0x21, 0x43]);
assert_eq!(metadata, 123.4);

§Canonical Layout

When the metadata type T is bytemuck::Pod, VectorRef and VectorMut support layout canonicalization, where a raw slice can be used as the backing store for such vectors, enabling inline storage.

There are two supported schems for the canonical layout, depending on whether the metadata is located at the beginning of the slice or at the end of the slice.

If the metadata is at the front, then the layout consists of a slice &[u8] where the first std::mem::size_of::<T>() bytes are the metadata and the remainder compose the BitSlice codes.

If the metadata is at the back, , then the layout consists of a slice &[u8] where the last std::mem::size_of::<T>() bytes are the metadata and the prefix is the BitSlice codes.

The canonical layout needs the following properties:

  • T: bytemuck::Pod: For safely storing and retrieving.
  • The length for a vector with N dimensions must be equal to the value returne from Vector::canonical_bytes.

The following functions can be used to construct VectorBases from raw slices:

An example is shown below.

use diskann_quantization::{bits, meta::{Vector, VectorRef, VectorMut}};

type CVRef<'a, const NBITS: usize> = VectorRef<'a, NBITS, bits::Unsigned, f32>;
type MutCV<'a, const NBITS: usize> = VectorMut<'a, NBITS, bits::Unsigned, f32>;

let dim = 3;

// Since we don't control the alignment of the returned pointer, we need to oversize it.
let bytes = CVRef::<4>::canonical_bytes(dim);
let mut data: Box<[u8]> = (0..bytes).map(|_| u8::default()).collect();

// Construct a mutable compensated vector over the slice.
let mut mut_cv = MutCV::<4>::from_canonical_front_mut(&mut data, dim).unwrap();
mut_cv.set_meta(1.0);
let mut v = mut_cv.vector_mut();
v.set(0, 1).unwrap();
v.set(1, 2).unwrap();
v.set(2, 3).unwrap();

// Reconstruct a constant CompensatedVector.
let cv = CVRef::<4>::from_canonical_front(&data, dim).unwrap();
assert_eq!(cv.meta(), 1.0);
let v = cv.vector();
assert_eq!(v.get(0).unwrap(), 1);
assert_eq!(v.get(1).unwrap(), 2);
assert_eq!(v.get(2).unwrap(), 3);

Implementations§

Source§

impl<const NBITS: usize, Repr, Ptr, T, Perm> VectorBase<NBITS, Repr, Ptr, T, Perm>
where Ptr: AsPtr<Type = u8>, Repr: Representation<NBITS>, Perm: PermutationStrategy<NBITS>,

Source

pub fn slice_bytes(count: usize) -> usize

Return the number of bytes required for the underlying BitSlice.

Source

pub fn canonical_bytes(count: usize) -> usize
where T: CopyRef, T::Target: Pod,

Return the number of bytes required for the canonical representation of a Vector.

See: VectorRef::from_canonical_back, VectorMut::from_canonical_back_mut.

Source

pub fn new<M>(bits: BitSliceBase<NBITS, Repr, Ptr, Perm>, meta: M) -> Self
where M: Into<T>,

Construct a new VectorBase over the bit-slice.

Source

pub fn len(&self) -> usize

Return the number of dimensions of in the vector.

Source

pub fn is_empty(&self) -> bool

Return whether or not the vector is empty.

Source

pub fn meta(&self) -> T::Target
where T: CopyRef,

Return the metadata value for this vector.

Source

pub fn vector(&self) -> BitSlice<'_, NBITS, Repr, Perm>

Borrow the integer compressed vector.

Source

pub fn vector_mut(&mut self) -> MutBitSlice<'_, NBITS, Repr, Perm>
where Ptr: AsMutPtr,

Mutably borrow the integer compressed vector.

Source

pub fn set_meta(&mut self, value: T::Target)
where Ptr: AsMutPtr, T: CopyMut,

Get a mutable reference to the metadata component.

In addition to a mutable reference, this also requires Ptr: AsMutPtr to prevent accidental misuse where the VectorBase is mutable but the underlying BitSlice is not.

Source§

impl<const NBITS: usize, Repr, Perm, T> VectorBase<NBITS, Repr, Poly<[u8], GlobalAllocator>, Owned<T>, Perm>
where Repr: Representation<NBITS>, Perm: PermutationStrategy<NBITS>, T: Default,

Source

pub fn new_boxed(len: usize) -> Self

Create a new owned VectorBase with its metadata default initialized.

Source§

impl<const NBITS: usize, Repr, Perm, T, A> VectorBase<NBITS, Repr, Poly<[u8], A>, Owned<T>, Perm>
where Repr: Representation<NBITS>, Perm: PermutationStrategy<NBITS>, T: Default, A: AllocatorCore,

Source

pub fn new_in(len: usize, allocator: A) -> Result<Self, AllocatorError>

Create a new owned VectorBase with its metadata default initialized.

Source§

impl<'a, const NBITS: usize, Repr, T, Perm> VectorBase<NBITS, Repr, SlicePtr<'a, u8>, Ref<'a, T>, Perm>
where Repr: Representation<NBITS>, Perm: PermutationStrategy<NBITS>, T: Pod,

Source

pub fn from_canonical_front( data: &'a [u8], dim: usize, ) -> Result<Self, NotCanonical>

Construct an instance of Self viewing data as the canonical layout for a vector. The canonical layout is as follows:

  • std::mem::size_of::<T>() for the metadata coefficient.
  • Self::slice_bytes(dim) for the underlying bit-slice.

Returns an error if data.len() != Self::canonical_bytes`.

Source

pub fn from_canonical_back( data: &'a [u8], dim: usize, ) -> Result<Self, NotCanonical>

Construct an instance of Self viewing data as the canonical layout for a vector. The back canonical layout is as follows:

  • Self::slice_bytes(dim) for the underlying bit-slice.
  • std::mem::size_of::<T>() for the metadata coefficient.

Returns an error if data.len() != Self::canonical_bytes`.

Source

pub unsafe fn from_canonical_unchecked(data: &'a [u8], dim: usize) -> Self

Construct a VectorRef from the raw data.

§Safety
  • data.len() must be equal to Self::canonical_bytes(dim).

This invariant is checked in debug builds and will panic if not satisfied.

Source

pub unsafe fn from_canonical_back_unchecked(data: &'a [u8], dim: usize) -> Self

Construct a VectorRef from the raw data.

§Safety
  • data.len() must be equal to Self::canonical_bytes(dim).

This invariant is checked in debug builds and will panic if not satisfied.

Source§

impl<'a, const NBITS: usize, Repr, T, Perm> VectorBase<NBITS, Repr, MutSlicePtr<'a, u8>, Mut<'a, T>, Perm>
where Repr: Representation<NBITS>, Perm: PermutationStrategy<NBITS>, T: Pod,

Source

pub fn from_canonical_front_mut( data: &'a mut [u8], dim: usize, ) -> Result<Self, NotCanonical>

Construct an instance of Self viewing data as the canonical layout for a vector. The canonical layout is as follows:

  • std::mem::size_of::<T>() for the metadata coefficient.
  • Self::slice_bytes(dim) for the underlying bit-slice.

Returns an error if data.len() != Self::canonical_bytes`.

Source

pub unsafe fn from_canonical_front_mut_unchecked( data: &'a mut [u8], dim: usize, ) -> Self

Construct a VectorMut from the raw data.

§Safety
  • data.len() must be equal to Self::canonical_bytes(dim).

This invariant is checked in debug builds and will panic if not satisfied.

Source

pub fn from_canonical_back_mut( data: &'a mut [u8], dim: usize, ) -> Result<Self, NotCanonical>

Construct an instance of Self viewing data as the canonical layout for a vector. The back canonical layout is as follows:

  • Self::slice_bytes(dim) for the underlying bit-slice.
  • std::mem::size_of::<T>() for the metadata coefficient.

Returns an error if data.len() != Self::canonical_bytes`.

Source§

impl<const NBITS: usize> VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, MinMaxCompensation>>
where Unsigned: Representation<NBITS>,

Source

pub fn decompress_into(&self, dst: &mut [f32]) -> Result<(), DecompressError>

Decompresses a MinMax quantized vector back into its original floating-point representation.

This method reconstructs the original vector values using the stored quantization parameters and the MinMax dequantization formula: x = x' * a + b and stores the result in dst

§Arguments
  • dst - A mutable slice of f32 values where the decompressed data will be written. Must have the same length as the compressed vector.
§Returns
  • Ok(()) - On successful decompression
  • Err(DecompressError::LengthMismatch(src_len, dst_len)) - If the destination slice length doesn’t match the compressed vector length

Trait Implementations§

Source§

impl<const NBITS: usize, Repr, Ptr, T: Clone, Perm> Clone for VectorBase<NBITS, Repr, Ptr, T, Perm>
where Ptr: AsPtr<Type = u8> + Clone, Repr: Representation<NBITS> + Clone, Perm: PermutationStrategy<NBITS> + Clone,

Source§

fn clone(&self) -> VectorBase<NBITS, Repr, Ptr, T, Perm>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const NBITS: usize, T, Perm> CompressInto<&[T], VectorBase<NBITS, Unsigned, MutSlicePtr<'_, u8>, Mut<'_, Compensation>, Perm>> for ScalarQuantizer
where T: Copy + Into<f32>, Unsigned: Representation<NBITS>, Perm: PermutationStrategy<NBITS>,

Source§

fn compress_into( &self, from: &[T], into: MutCompensatedVectorRef<'_, NBITS, Perm>, ) -> Result<(), Self::Error>

Compress the input vector from into the bitslice into.

This method computes and stores the compensation coefficient required for fast inner product computations.

§Error

Returns an error if the input contains NaN.

§Panics

Panics if:

  • from.len() != self.dim(): Vector to be compressed must have the same dimensionality as the quantizer.
  • into.len() != self.dim(): Compressed vector must have the same dimensionality as the quantizer.
Source§

type Error = InputContainsNaN

Errors that may occur during compression.
Source§

type Output = ()

An output type resulting from compression.
Source§

impl<const NBITS: usize, T> CompressInto<&[T], VectorBase<NBITS, Unsigned, MutSlicePtr<'_, u8>, Mut<'_, MinMaxCompensation>>> for MinMaxQuantizer
where T: Copy + Into<f32>, Unsigned: Representation<NBITS>,

Source§

fn compress_into( &self, from: &[T], to: DataMutRef<'_, NBITS>, ) -> Result<L2Loss, Self::Error>

Compress the input vector from into a mut ref of Data to.

This method computes and stores the compensation coefficients required for computing distances correctly.

§Error

Returns an error if the input contains NaN.

§Panics

Panics if:

  • from.len() != self.dim(): Vector to be compressed must have the same dimensionality as the quantizer.
  • to.vector().len() != self.output_dim(): Compressed vector must have the same dimensionality as the quantizer.
Source§

type Error = InputContainsNaN

Errors that may occur during compression.
Source§

type Output = L2Loss

An output type resulting from compression.
Source§

impl<'a, 'b> CompressInto<VectorBase<4, Unsigned, SlicePtr<'a, u8>, Ref<'a, MinMaxCompensation>>, VectorBase<2, Unsigned, MutSlicePtr<'b, u8>, Mut<'b, MinMaxCompensation>>> for Recompressor

Source§

type Error = RecompressError

Errors that may occur during compression.
Source§

type Output = ()

An output type resulting from compression.
Source§

fn compress_into( &self, from: DataRef<'a, 4>, to: DataMutRef<'b, 2>, ) -> Result<(), Self::Error>

Compress the data in From into To. Read more
Source§

impl<'a, 'b> CompressInto<VectorBase<8, Unsigned, SlicePtr<'a, u8>, Ref<'a, MinMaxCompensation>>, VectorBase<2, Unsigned, MutSlicePtr<'b, u8>, Mut<'b, MinMaxCompensation>>> for Recompressor

Source§

type Error = RecompressError

Errors that may occur during compression.
Source§

type Output = ()

An output type resulting from compression.
Source§

fn compress_into( &self, from: DataRef<'a, 8>, to: DataMutRef<'b, 2>, ) -> Result<(), Self::Error>

Compress the data in From into To. Read more
Source§

impl<'a, 'b> CompressInto<VectorBase<8, Unsigned, SlicePtr<'a, u8>, Ref<'a, MinMaxCompensation>>, VectorBase<4, Unsigned, MutSlicePtr<'b, u8>, Mut<'b, MinMaxCompensation>>> for Recompressor

Source§

type Error = RecompressError

Errors that may occur during compression.
Source§

type Output = ()

An output type resulting from compression.
Source§

fn compress_into( &self, from: DataRef<'a, 8>, to: DataMutRef<'b, 4>, ) -> Result<(), Self::Error>

Compress the data in From into To. Read more
Source§

impl<const NBITS: usize, A> CompressIntoWith<&[f32], VectorBase<NBITS, Unsigned, MutSlicePtr<'_, u8>, Mut<'_, DataMeta>>, ScopedAllocator<'_>> for SphericalQuantizer<A>
where A: Allocator, Unsigned: Representation<NBITS>, for<'a> DataMut<'a, NBITS>: FinishCompressing,

Source§

fn compress_into_with( &self, from: &[f32], into: DataMut<'_, NBITS>, allocator: ScopedAllocator<'_>, ) -> Result<(), Self::Error>

Compress the input vector from into the bitslice into.

§Error

Returns an error if

  • The input contains NaN.
  • from.len() != self.dim(): Vector to be compressed must have the same dimensionality as the quantizer.
  • into.len() != self.output_dim(): Compressed vector must have the same dimensionality as the output of the distance-preserving transform. Importantely, this may be different than self.dim() and should be retrieved from self.output_dim().
Source§

type Error = CompressionError

Errors that may occur during compression.
Source§

impl<const NBITS: usize, Perm, A> CompressIntoWith<&[f32], VectorBase<NBITS, Unsigned, MutSlicePtr<'_, u8>, Mut<'_, QueryMeta>, Perm>, ScopedAllocator<'_>> for SphericalQuantizer<A>
where Unsigned: Representation<NBITS>, Perm: PermutationStrategy<NBITS>, A: Allocator,

Source§

fn compress_into_with( &self, from: &[f32], into: QueryMut<'_, NBITS, Perm>, allocator: ScopedAllocator<'_>, ) -> Result<(), Self::Error>

Compress the input vector from into the bitslice into.

§Error

Returns an error if

  • The input contains NaN.
  • from.len() != self.dim(): Vector to be compressed must have the same dimensionality as the quantizer.
  • into.len() != self.output_dim(): Compressed vector must have the same dimensionality as the output of the distance-preserving transform. Importantely, this may be different than self.dim() and should be retrieved from self.output_dim().
Source§

type Error = CompressionError

Errors that may occur during compression.
Source§

impl<const NBITS: usize, Repr, Ptr, T: Debug, Perm> Debug for VectorBase<NBITS, Repr, Ptr, T, Perm>
where Ptr: AsPtr<Type = u8> + Debug, Repr: Representation<NBITS> + Debug, Perm: PermutationStrategy<NBITS> + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const NBITS: usize> DistanceFunction<VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, Compensation>>, VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, Compensation>>, Result<MathematicalValue<f32>, UnequalLengths>> for CompensatedCosineNormalized

CosineNormalized

This implementation calculates the <x, y> = 1 - L2 / 2 value, which will be further used to compute the CosineNormalised distance function

§Notes

s = 1 - cosine(X, Y) = 1- <X, Y> / (||X|| * ||Y||)

We can make simply assumption that ||X|| = 1 and ||Y|| = 1. Then s = 1 - <X, Y>

The squared L2 distance can be computed as follows: p = ||x||^2 + ||y||^2 - 2<x, y> When vectors are normalized, this becomes p = 2 - 2<x, y> = 2 * (1 - <x, y>)

In other words, the similarity score for the squared L2 distance in an ideal world is 2 times that for cosine similarity. Therefore, squared L2 may serves as a stand-in for cosine normalized as ordering is preserved.

Source§

fn evaluate_similarity( &self, x: CompensatedVectorRef<'_, NBITS>, y: CompensatedVectorRef<'_, NBITS>, ) -> MathematicalResult<f32>

Perform a distance computation between the left-hand and right-hand arguments.
Source§

impl<const NBITS: usize> DistanceFunction<VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, Compensation>>, VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, Compensation>>, Result<MathematicalValue<f32>, UnequalLengths>> for CompensatedIP

Compute the inner product between the two compensated vectors.

The value returned by this function is scaled properly, meaning that distances returned by this method are compatible with full-precision computations.

§Validity

The results of this function are only meaningful if both x, y, and Self belong to the same quantizer.

§Panics

Panics if x.len() != y.len().

Source§

fn evaluate_similarity( &self, x: CompensatedVectorRef<'_, NBITS>, y: CompensatedVectorRef<'_, NBITS>, ) -> MathematicalResult<f32>

Perform a distance computation between the left-hand and right-hand arguments.
Source§

impl<const NBITS: usize> DistanceFunction<VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, Compensation>>, VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, Compensation>>, Result<MathematicalValue<f32>, UnequalLengths>> for CompensatedSquaredL2

Compute the squared euclidean distance between the two compensated vectors.

The value returned by this function is scaled properly, meaning that distances returned by this method are compatible with full-precision distances.

§Validity

The results of this function are only meaningful if both x, y, and Self belong to the same quantizer.

§Panics

Panics if x.len() != y.len().

Source§

fn evaluate_similarity( &self, x: CompensatedVectorRef<'_, NBITS>, y: CompensatedVectorRef<'_, NBITS>, ) -> MathematicalResult<f32>

Perform a distance computation between the left-hand and right-hand arguments.
Source§

impl<const NBITS: usize> DistanceFunction<VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, Compensation>>, VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, Compensation>>, Result<f32, UnequalLengths>> for CompensatedCosineNormalized
where Unsigned: Representation<NBITS>, Self: for<'a, 'b> DistanceFunction<CompensatedVectorRef<'a, NBITS>, CompensatedVectorRef<'b, NBITS>, MathematicalResult<f32>>,

Source§

fn evaluate_similarity( &self, x: CompensatedVectorRef<'_, NBITS>, y: CompensatedVectorRef<'_, NBITS>, ) -> Result<f32>

Perform a distance computation between the left-hand and right-hand arguments.
Source§

impl<const NBITS: usize> DistanceFunction<VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, Compensation>>, VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, Compensation>>, Result<f32, UnequalLengths>> for CompensatedIP
where Unsigned: Representation<NBITS>, Self: for<'a, 'b> DistanceFunction<CompensatedVectorRef<'a, NBITS>, CompensatedVectorRef<'b, NBITS>, MathematicalResult<f32>>,

Compute the inner product between the two compensated vectors.

The value returned by this function is scaled properly, meaning that distances returned by this method are compatible with full-precision computations.

§Validity

The results of this function are only meaningful if both x, y, and Self belong to the same quantizer.

§Panics

Panics if x.len() != y.len().

Source§

fn evaluate_similarity( &self, x: CompensatedVectorRef<'_, NBITS>, y: CompensatedVectorRef<'_, NBITS>, ) -> Result<f32>

Perform a distance computation between the left-hand and right-hand arguments.
Source§

impl<const NBITS: usize> DistanceFunction<VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, Compensation>>, VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, Compensation>>, Result<f32, UnequalLengths>> for CompensatedSquaredL2
where Unsigned: Representation<NBITS>, Self: for<'a, 'b> DistanceFunction<CompensatedVectorRef<'a, NBITS>, CompensatedVectorRef<'b, NBITS>, MathematicalResult<f32>>,

Compute the squared euclidean distance between the two compensated vectors.

The value returned by this function is scaled properly, meaning that distances returned by this method are compatible with full-precision distances.

§Validity

The results of this function are only meaningful if both x, y, and Self belong to the same quantizer.

§Panics

Panics if x.len() != y.len().

Source§

fn evaluate_similarity( &self, x: CompensatedVectorRef<'_, NBITS>, y: CompensatedVectorRef<'_, NBITS>, ) -> Result<f32>

Perform a distance computation between the left-hand and right-hand arguments.
Source§

impl<const NBITS: usize> PureDistanceFunction<&FullQuery, VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, MinMaxCompensation>>, Result<MathematicalValue<f32>, UnequalLengths>> for MinMaxIP

Source§

impl<const NBITS: usize> PureDistanceFunction<&FullQuery, VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, MinMaxCompensation>>, Result<MathematicalValue<f32>, UnequalLengths>> for MinMaxL2Squared

Source§

impl<const NBITS: usize> PureDistanceFunction<&FullQuery, VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, MinMaxCompensation>>, Result<f32, UnequalLengths>> for MinMaxCosine

Source§

fn evaluate(x: &FullQuery, y: DataRef<'_, NBITS>) -> Result<f32>

Source§

impl<const NBITS: usize> PureDistanceFunction<&FullQuery, VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, MinMaxCompensation>>, Result<f32, UnequalLengths>> for MinMaxCosineNormalized

Source§

fn evaluate(x: &FullQuery, y: DataRef<'_, NBITS>) -> Result<f32>

Source§

impl<const NBITS: usize> PureDistanceFunction<&FullQuery, VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, MinMaxCompensation>>, Result<f32, UnequalLengths>> for MinMaxIP

Source§

fn evaluate(x: &FullQuery, y: DataRef<'_, NBITS>) -> Result<f32>

Source§

impl<const NBITS: usize> PureDistanceFunction<&FullQuery, VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, MinMaxCompensation>>, Result<f32, UnequalLengths>> for MinMaxL2Squared

Source§

fn evaluate(x: &FullQuery, y: DataRef<'_, NBITS>) -> Result<f32>

Source§

impl<const NBITS: usize> PureDistanceFunction<VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, MinMaxCompensation>>, VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, MinMaxCompensation>>, Result<MathematicalValue<f32>, UnequalLengths>> for MinMaxIP

Source§

fn evaluate( x: DataRef<'_, NBITS>, y: DataRef<'_, NBITS>, ) -> MathematicalResult<f32>

Source§

impl<const NBITS: usize> PureDistanceFunction<VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, MinMaxCompensation>>, VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, MinMaxCompensation>>, Result<MathematicalValue<f32>, UnequalLengths>> for MinMaxL2Squared

Source§

fn evaluate( x: DataRef<'_, NBITS>, y: DataRef<'_, NBITS>, ) -> MathematicalResult<f32>

Source§

impl<const NBITS: usize> PureDistanceFunction<VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, MinMaxCompensation>>, VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, MinMaxCompensation>>, Result<f32, UnequalLengths>> for MinMaxCosine
where Unsigned: Representation<NBITS>, MinMaxIP: for<'a, 'b> PureDistanceFunction<DataRef<'a, NBITS>, DataRef<'b, NBITS>, MathematicalResult<f32>>,

Source§

fn evaluate(x: DataRef<'_, NBITS>, y: DataRef<'_, NBITS>) -> Result<f32>

Source§

impl<const NBITS: usize> PureDistanceFunction<VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, MinMaxCompensation>>, VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, MinMaxCompensation>>, Result<f32, UnequalLengths>> for MinMaxCosineNormalized
where Unsigned: Representation<NBITS>, MinMaxIP: for<'a, 'b> PureDistanceFunction<DataRef<'a, NBITS>, DataRef<'b, NBITS>, MathematicalResult<f32>>,

Source§

fn evaluate(x: DataRef<'_, NBITS>, y: DataRef<'_, NBITS>) -> Result<f32>

Source§

impl<const NBITS: usize> PureDistanceFunction<VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, MinMaxCompensation>>, VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, MinMaxCompensation>>, Result<f32, UnequalLengths>> for MinMaxIP

Source§

fn evaluate(x: DataRef<'_, NBITS>, y: DataRef<'_, NBITS>) -> Result<f32>

Source§

impl<const NBITS: usize> PureDistanceFunction<VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, MinMaxCompensation>>, VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, MinMaxCompensation>>, Result<f32, UnequalLengths>> for MinMaxL2Squared

Source§

fn evaluate(x: DataRef<'_, NBITS>, y: DataRef<'_, NBITS>) -> Result<f32>

Source§

impl<'this, const NBITS: usize, Repr, Ptr, T, Perm> Reborrow<'this> for VectorBase<NBITS, Repr, Ptr, T, Perm>
where Ptr: AsPtr<Type = u8>, Repr: Representation<NBITS>, Perm: PermutationStrategy<NBITS>, T: CopyRef + Reborrow<'this, Target = Ref<'this, <T as CopyRef>::Target>>,

Source§

type Target = VectorBase<NBITS, Repr, SlicePtr<'this, u8>, Ref<'this, <T as CopyRef>::Target>, Perm>

Source§

fn reborrow(&'this self) -> Self::Target

Borrow self into a generalized reference type and reborrow
Source§

impl<'this, const NBITS: usize, Repr, Ptr, T, Perm> ReborrowMut<'this> for VectorBase<NBITS, Repr, Ptr, T, Perm>
where Ptr: AsMutPtr<Type = u8>, Repr: Representation<NBITS>, Perm: PermutationStrategy<NBITS>, T: CopyMut + ReborrowMut<'this, Target = Mut<'this, <T as CopyRef>::Target>>,

Source§

type Target = VectorBase<NBITS, Repr, MutSlicePtr<'this, u8>, Mut<'this, <T as CopyRef>::Target>, Perm>

Source§

fn reborrow_mut(&'this mut self) -> Self::Target

Mutably borrow self into a generalized reference type and reborrow.
Source§

impl<A, const NBITS: usize> Target2<A, Result<MathematicalValue<f32>, UnequalLengths>, Slice<&[f32], Ref<'_, FullQueryMeta>>, VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, DataMeta>>> for CompensatedIP
where A: Architecture, Unsigned: Representation<NBITS>, InnerProduct: for<'a> Target2<A, MathematicalResult<f32>, &'a [f32], BitSlice<'a, NBITS, Unsigned>>,

Compute the inner product between a full-precision query and a spherically quantized data vector.

Returns an error if the arguments have different lengths.

Source§

fn run( self, arch: A, x: FullQueryRef<'_>, y: DataRef<'_, NBITS>, ) -> MathematicalResult<f32>

Run the operation with the provided Architecture.
Source§

impl<A, const NBITS: usize> Target2<A, Result<MathematicalValue<f32>, UnequalLengths>, Slice<&[f32], Ref<'_, FullQueryMeta>>, VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, DataMeta>>> for CompensatedSquaredL2
where A: Architecture, Unsigned: Representation<NBITS>, InnerProduct: for<'a> Target2<A, MathematicalResult<f32>, &'a [f32], BitSlice<'a, NBITS, Unsigned>>,

Compute the inner product between a full-precision query and a spherically quantized data vector.

Returns an error if the arguments have different lengths.

Source§

fn run( self, arch: A, x: FullQueryRef<'_>, y: DataRef<'_, NBITS>, ) -> MathematicalResult<f32>

Run the operation with the provided Architecture.
Source§

impl<A, const NBITS: usize> Target2<A, Result<MathematicalValue<f32>, UnequalLengths>, VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, DataMeta>>, VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, DataMeta>>> for CompensatedIP

Compute the inner product between the two compensated vectors.

Returns an error if the arguments have different lengths.

The value returned by this function is scaled properly, meaning that distances returned by this method are compatible with full-precision computations.

§Validity

The results of this function are only meaningful if both x, y, and Self belong to the same quantizer.

Source§

fn run( self, arch: A, x: DataRef<'_, NBITS>, y: DataRef<'_, NBITS>, ) -> MathematicalResult<f32>

Run the operation with the provided Architecture.
Source§

impl<A, const NBITS: usize> Target2<A, Result<MathematicalValue<f32>, UnequalLengths>, VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, DataMeta>>, VectorBase<NBITS, Unsigned, SlicePtr<'_, u8>, Ref<'_, DataMeta>>> for CompensatedSquaredL2

Compute the squared euclidean distance between the two compensated vectors.

The value returned by this function is scaled properly, meaning that distances returned by this method are compatible with full-precision distances.

§Validity

The results of this function are only meaningful if both x, y, and Self belong to the same quantizer.

Source§

fn run( self, arch: A, x: DataRef<'_, NBITS>, y: DataRef<'_, NBITS>, ) -> MathematicalResult<f32>

Run the operation with the provided Architecture.
Source§

impl<A, const Q: usize, const D: usize, Perm> Target2<A, Result<MathematicalValue<f32>, UnequalLengths>, VectorBase<Q, Unsigned, SlicePtr<'_, u8>, Ref<'_, QueryMeta>, Perm>, VectorBase<D, Unsigned, SlicePtr<'_, u8>, Ref<'_, DataMeta>>> for CompensatedIP

Source§

fn run( self, arch: A, x: QueryRef<'_, Q, Perm>, y: DataRef<'_, D>, ) -> MathematicalResult<f32>

Run the operation with the provided Architecture.
Source§

impl<A, const Q: usize, const D: usize, Perm> Target2<A, Result<MathematicalValue<f32>, UnequalLengths>, VectorBase<Q, Unsigned, SlicePtr<'_, u8>, Ref<'_, QueryMeta>, Perm>, VectorBase<D, Unsigned, SlicePtr<'_, u8>, Ref<'_, DataMeta>>> for CompensatedSquaredL2

Source§

fn run( self, arch: A, x: QueryRef<'_, Q, Perm>, y: DataRef<'_, D>, ) -> MathematicalResult<f32>

Run the operation with the provided Architecture.
Source§

impl<const NBITS: usize, Repr, Ptr, T: Copy, Perm> Copy for VectorBase<NBITS, Repr, Ptr, T, Perm>
where Ptr: AsPtr<Type = u8> + Copy, Repr: Representation<NBITS> + Copy, Perm: PermutationStrategy<NBITS> + Copy,

Auto Trait Implementations§

§

impl<const NBITS: usize, Repr, Ptr, T, Perm> Freeze for VectorBase<NBITS, Repr, Ptr, T, Perm>
where T: Freeze, Ptr: Freeze,

§

impl<const NBITS: usize, Repr, Ptr, T, Perm> RefUnwindSafe for VectorBase<NBITS, Repr, Ptr, T, Perm>

§

impl<const NBITS: usize, Repr, Ptr, T, Perm> Send for VectorBase<NBITS, Repr, Ptr, T, Perm>
where T: Send, Ptr: Send, Repr: Send, Perm: Send,

§

impl<const NBITS: usize, Repr, Ptr, T, Perm> Sync for VectorBase<NBITS, Repr, Ptr, T, Perm>
where T: Sync, Ptr: Sync, Repr: Sync, Perm: Sync,

§

impl<const NBITS: usize, Repr, Ptr, T, Perm> Unpin for VectorBase<NBITS, Repr, Ptr, T, Perm>
where T: Unpin, Ptr: Unpin, Repr: Unpin, Perm: Unpin,

§

impl<const NBITS: usize, Repr, Ptr, T, Perm> UnwindSafe for VectorBase<NBITS, Repr, Ptr, T, Perm>
where T: UnwindSafe, Ptr: UnwindSafe, Repr: UnwindSafe, Perm: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Generator<T> for T
where T: Clone,

Source§

fn generate(&mut self) -> T

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> AsyncFriendly for T
where T: Send + Sync + 'static,