pub struct QuantizedVectors {
pub dims: usize,
pub num_vectors: usize,
pub data: Vec<u8>,
pub mins: Vec<f32>,
pub scales: Vec<f32>,
pub norms: Vec<f32>,
pub metric: DistanceMetric,
}Expand description
Int8 quantized vectors with per-dimension calibration data.
Fields§
§dims: usize§num_vectors: usize§data: Vec<u8>Flat quantized data: data[i * dims .. (i+1) * dims] = vector i.
mins: Vec<f32>Per-dimension minimum values.
scales: Vec<f32>Per-dimension scale: (max - min) / 255.0.
norms: Vec<f32>Per-vector precomputed norms (approximate, for cosine distance).
metric: DistanceMetricDistance metric.
Implementations§
Source§impl QuantizedVectors
impl QuantizedVectors
Sourcepub fn quantize(vectors: &[Vec<f32>], metric: DistanceMetric) -> Self
pub fn quantize(vectors: &[Vec<f32>], metric: DistanceMetric) -> Self
Quantize a set of float32 vectors to int8.
Sourcepub fn asymmetric_distance(&self, idx: usize, query: &[f32]) -> f32
pub fn asymmetric_distance(&self, idx: usize, query: &[f32]) -> f32
Compute asymmetric distance between quantized stored vector and float32 query vector.
For cosine, the query is expected to be unit-length (caller
normalizes at entry per [[optimize-cosine-norm-precompute]]).
stored_norm is the norm of the dequantized stored vector,
which approximates 1.0 but drifts due to int8 quantization
rounding — keeping it cancels that drift in the score.
Sourcepub fn from_bytes(data: &[u8]) -> Self
pub fn from_bytes(data: &[u8]) -> Self
Deserialize from bytes.
Auto Trait Implementations§
impl Freeze for QuantizedVectors
impl RefUnwindSafe for QuantizedVectors
impl Send for QuantizedVectors
impl Sync for QuantizedVectors
impl Unpin for QuantizedVectors
impl UnsafeUnpin for QuantizedVectors
impl UnwindSafe for QuantizedVectors
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
Mutably borrows from an owned value. Read more
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>
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 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>
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