#[repr(C)]pub struct MinMaxCompensation {
pub dim: u32,
pub b: f32,
pub n: f32,
pub a: f32,
pub norm_squared: f32,
}Expand description
A per-vector precomputed coefficients to help compute inner products and squared L2 distances for the MinMax quantized vectors.
The inner product between X = ax * X' + bx and Y = ay * Y' + by for d-dimensional
vectors X and Y is:
<X, Y> = <ax * X' + bx, ay * Y' + by>
= ax * ay * <X', Y'> + ax * <X', by> + ay * <Y', bx> + d * bx * by.Let us define a grouping of these terms to make it easier to understand:
Nx = ax * sum_i X'[i], Ny = ay * sum_i Y'[i],We can then simplify the dot product calculation as follows:
<X, Y> = ax * ay * <X', Y'> + Nx * by + Ny * bx + d * bx * by
--------
|
Integer Dot ProductTo compute the squared L2 distance,
|X - Y|^2 = |ax * X' + bx|^2 + |ay * Y' + by|^2 - 2 * <X, Y>we can re-use the computation for inner-product from above.
Fields§
§dim: u32§b: f32§n: f32§a: f32§norm_squared: f32Implementations§
Source§impl MinMaxCompensation
impl MinMaxCompensation
Sourcepub fn read_dimension(bytes: &[u8]) -> Result<usize, MetaParseError>
pub fn read_dimension(bytes: &[u8]) -> Result<usize, MetaParseError>
Reads the dimension from the first 4 bytes of a MinMax quantized vector’s metadata.
This function is used to extract the vector dimension from serialized MinMax quantized vector data without fully deserializing the entire vector structure.
§Arguments
bytes- A byte slice containing the serialized MinMax vector data
§Returns
Ok(dimension)- The dimension of the vector as ausizeErr(MetaParseError::NotCanonical(size))- If the byte slice is shorter than 20 bytes (META_BYTES)
§Usage
Use this when you need to determine the vector dimension from serialized data before
creating a DataRef or allocating appropriately sized buffers for decompression.
Trait Implementations§
Source§impl Clone for MinMaxCompensation
impl Clone for MinMaxCompensation
Source§fn clone(&self) -> MinMaxCompensation
fn clone(&self) -> MinMaxCompensation
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MinMaxCompensation
impl Debug for MinMaxCompensation
Source§impl Default for MinMaxCompensation
impl Default for MinMaxCompensation
Source§fn default() -> MinMaxCompensation
fn default() -> MinMaxCompensation
Source§impl PartialEq for MinMaxCompensation
impl PartialEq for MinMaxCompensation
impl Copy for MinMaxCompensation
impl Pod for MinMaxCompensation
impl StructuralPartialEq for MinMaxCompensation
Auto Trait Implementations§
impl Freeze for MinMaxCompensation
impl RefUnwindSafe for MinMaxCompensation
impl Send for MinMaxCompensation
impl Sync for MinMaxCompensation
impl Unpin for MinMaxCompensation
impl UnwindSafe for MinMaxCompensation
Blanket Implementations§
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> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
Source§type Bits = T
type Bits = T
Self must have the same layout as the specified Bits except for
the possible invalid bit patterns being checked during
is_valid_bit_pattern.Source§fn is_valid_bit_pattern(_bits: &T) -> bool
fn is_valid_bit_pattern(_bits: &T) -> bool
bits
as &Self.Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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