One high-dimensional problem becomes several smaller clustering problems.
An eight-dimensional vector with four subspaces becomes four independent two-dimensional slices. Each slice selects one centroid from its own codebook.
Interactive embedding compression laboratory
Product Quantization splits a vector into subspaces, learns a small codebook in each one, and stores centroid IDs instead of every float. The result is compact, fast, and approximate.
The database begins as eight-dimensional float vectors. Step forward to split, train, encode, and search.
Every result below is recomputed from the visible teaching vectors. The vector-only compression estimate excludes codebooks, IDs, and index metadata.
PQ is not scalar rounding. Each sub-vector is replaced by the ID of its nearest learned centroid, and those IDs jointly approximate the full vector.
An eight-dimensional vector with four subspaces becomes four independent two-dimensional slices. Each slice selects one centroid from its own codebook.
Asymmetric Distance Computation compares each exact query slice with every centroid once, then scores database codes by table lookup. It avoids quantizing the query.
Increasing the number of subspaces usually reduces reconstruction error because each centroid models fewer dimensions, but every extra centroid ID lengthens the code.
More centroids can reduce distortion, provided the training set is large and representative enough to learn them reliably.
A small reconstruction error can still swap close neighbors. Tune the codec against retrieval metrics on held-out queries.
Scroll through the exact state transitions. The browser lab uses deterministic k-means so every slider change can be replayed and inspected.
The embedding dimension must be divisible by the number of subquantizers. Dimension order matters because correlated features can make one split much harder to quantize than another.
K-means minimizes squared reconstruction error within each slice. Production codebooks need representative training vectors; a tiny or shifted sample creates brittle assignments.
The concatenated IDs are the PQ code. Reconstructing a vector means concatenating the selected centroids, but ADC can search without materializing that reconstruction.
For each database code, read one value from each subspace table and add them. The ranking is fast and compact, but only approximate, so measure neighbor recall.
Expand each slice to see what a production experiment should hold constant while testing the compression-recall frontier.
Compression ratio is not a retrieval metric.
A smaller code is only useful when the nearest neighbors needed by the downstream task remain discoverable at an acceptable latency.
The codebook is part of the model.
Changing the embedding distribution without retraining or validating the quantizer can move vectors across centroid boundaries and degrade recall.
ADC keeps one side precise.
Leaving the query uncompressed removes one source of error and lets a single lookup table score many compact database codes.
Benchmark the same vectors and queries with exact search, then vary one codec choice at a time.
The original PQ formulation, optimized space decomposition, fast ADC work, and Faiss index documentation ground the mechanics shown in the lab.