Skip to main content

Module vector_quantizer

Module vector_quantizer 

Source
Expand description

§Vector Quantizer

Production-grade product quantization (PQ) for compressing high-dimensional embedding vectors into compact codes for efficient approximate nearest-neighbor (ANN) search.

§Overview

Product Quantization divides a high-dimensional vector into M subspaces, each of dimension D/M, and quantizes each subspace independently using a small codebook of K centroids learned via k-means. Each sub-vector is then represented by the index of its nearest centroid — a single u8 value — so the full vector is stored as M bytes regardless of the original dimensionality.

§Algorithm

  1. Training: For each subspace, run k-means on the projected sub-vectors to learn codes_per_subspace centroids. Initialization picks every N/K-th training vector to seed the codebook (deterministic, no external RNG dependency).

  2. Encoding: Map each sub-vector to the index (u8) of its nearest centroid.

  3. Decoding: Reconstruct the approximate full vector by concatenating the centroid vectors retrieved from each codebook.

  4. Distance: Asymmetric distance computes exact sub-vector distances from query to reconstructed codes; symmetric distance decodes both codes first.

Structs§

Codebook
A learned codebook for one PQ subspace.
QuantizationConfig
Configuration for VectorQuantizer.
QuantizationStats
Runtime statistics for a VectorQuantizer.
QuantizerCode
Compact quantized representation of a vector.
VectorQuantizer
Product-quantization based vector compressor.

Enums§

VqError
Errors produced by VectorQuantizer operations.