Skip to main content

Module rabitq

Module rabitq 

Source
Expand description

RaBitQ — Random Binary Quantization.

Reference: “RaBitQ: Quantizing High-Dimensional Vectors with a Theoretical Error Bound for Approximate Nearest Neighbor Search” (SIGMOD 2024).

Key idea: apply a random rotation P to each vector, then quantize each rotated dimension to 1 bit (sign). The unbiased inner-product estimator uses precomputed scale factors and a Hamming distance (XOR + popcount), achieving significantly better recall than naive binary quantization at the same 1 bit/dim storage cost.

Storage per vector: ceil(dim/8) bytes (code) + 4 bytes (scale) + 4 bytes (norm) For dim=1536: 192 + 4 + 4 = 200 bytes vs F16 = 3 072 bytes → 15× compression.

Structs§

RaBitQCodebook
RaBitQ projection codebook: holds the random rotation matrix P.
RaBitQVec
Binary-quantized representation of a single database vector.

Functions§

bits_from_signs
Pack the sign bits of a float slice into bytes. Bit i in the output = (v[i] > 0.0).
encode_batch
Batch-encode a slice of vectors using rayon parallelism.