pub struct Int4Vector {
pub data: Vec<u8>,
pub dims: usize,
pub params: Int4Params,
pub norm: f32,
}Expand description
Unstable: INT4 quantization format is under active design; struct layout may change.
Quantized INT4 vector with packed nibble storage.
Fields§
§data: Vec<u8>Unstable: packed nibble data; bit packing scheme may change.
dims: usizeUnstable: number of original dimensions.
params: Int4ParamsUnstable: quantization parameters; may be separated from the vector.
norm: f32Unstable: L2 norm; may be removed or moved.
Implementations§
Source§impl Int4Vector
impl Int4Vector
Sourcepub fn from_f32(vector: &[f32]) -> Self
pub fn from_f32(vector: &[f32]) -> Self
Unstable: quantization format; nibble packing may change.
Each pair of consecutive dimensions is packed into one byte:
- High nibble (bits 7..4) = even-indexed value
- Low nibble (bits 3..0) = odd-indexed value
Sourcepub fn to_f32(&self) -> Vec<f32>
pub fn to_f32(&self) -> Vec<f32>
Unstable: dequantization output semantics may change.
Reverses the quantization: v[i] = q[i] / scale - max_abs
§Precision
INT4 unsigned symmetric quantization maps [-max_abs, max_abs] to [0, 15]
(16 levels), so the quantization step size is 2 * max_abs / 15. The maximum
per-element round-trip error is bounded by half a step: max_abs / 15.
For a 384-dim unit-norm embedding (max_abs ≈ 1.0), expect element-wise
absolute error ≤ 0.067 and relative dot-product error ≤ 15% (see
test_int4_dot_product_vs_f32 and test_int4_roundtrip_accuracy).
Use Int8 tier when higher fidelity is required.
Sourcepub fn dot_product(&self, other: &Int4Vector) -> f32
pub fn dot_product(&self, other: &Int4Vector) -> f32
Unstable: INT4 dot product approximation; formula may change.
Returns the dequantized dot product suitable for cosine distance computation.
Sourcepub fn cosine_similarity(&self, other: &Int4Vector) -> f32
pub fn cosine_similarity(&self, other: &Int4Vector) -> f32
Unstable: INT4 cosine similarity approximation; delegates to dot_product.
Sourcepub fn cosine_distance(&self, other: &Int4Vector) -> f32
pub fn cosine_distance(&self, other: &Int4Vector) -> f32
Unstable: complement of cosine_similarity; definition may evolve.
Trait Implementations§
Source§impl Clone for Int4Vector
impl Clone for Int4Vector
Source§fn clone(&self) -> Int4Vector
fn clone(&self) -> Int4Vector
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more