Skip to main content

Module quantize

Module quantize 

Source
Expand description

v6.0.0 — SQ8 scalar quantization for vector columns.

Per-vector affine f32 → u8 quantization. Each Sq8Vector carries its own (min, max) so quantization is purely streaming — no two-pass corpus scan needed to learn global parameters. Trade-off: 8 bytes overhead per vector (negligible at dim ≥ 64) in exchange for INSERT-time simplicity.

This file is the v6.0.0 standalone module: types + quantize / dequantize + ADC distance + serde + recall oracle. Integration with DataType::Vector + HNSW write path lands in v6.0.1.

Structs§

Sq8Vector
SQ8-quantized vector: every dimension stored as one byte plus a shared (min, max) reconstruction frame.

Enums§

QuantizeError
Error type for Sq8Vector byte-encoding parse failures.

Functions§

dequantize
Reconstruct the approximate f32 vector. For a vector with max == min (constant or single-element input) every component reconstructs as min exactly.
quantize
Quantize an f32 vector to SQ8 using per-vector affine mapping.
sq8_cosine_distance
Symmetric cosine distance 1 - dot / (||a|| ||b||). Zero-norm operand yields f32::INFINITY so it sorts last (matches the f32 cosine_distance in eval.rs).
sq8_cosine_distance_asymmetric
Asymmetric cosine distance against an un-quantized query. v6.0.2: aarch64 NEON path for the three accumulators; norm-sqrt + zero- guard stays in this safe wrapper.
sq8_inner_product
Symmetric inner product, returned negated so smaller = closer (matches pgvector <#> and SPG’s NswMetric::InnerProduct).
sq8_inner_product_asymmetric
Asymmetric inner product (negated). v6.0.2: aarch64 NEON path under the same dim >= 16 && dim % 16 == 0 pre-condition as the L2 asymmetric variant.
sq8_l2_distance_sq
Symmetric L2² distance between two SQ8 vectors of equal dim. Returns f32::INFINITY on dim mismatch (mirrors vec_l2_sq’s behaviour in lib.rs).
sq8_l2_distance_sq_asymmetric
Asymmetric L2² between a stored SQ8 vector and an un-quantized query vector. Same semantics as vec_l2_sq for the kNN scan case (one query, many vectors).