Storing float32 embeddings costs 4 bytes per dimension. Scalar quantisation maps each dimension's calibrated range to uint8 (one byte), a 4× saving with little loss in retrieval quality. It's the default in many vector databases.
Implement:
fit_ranges(E): per-dimension (mins, maxs) from calibration embeddingsquantize(E, ranges): round((x - min) / (max - min) * 255), clipped to [0, 255], as np.uint8. A dimension with max == min maps to 0.dequantize(Q, ranges): the inverse mapping back to floatstopk_overlap(Q, D, ranges, queries, k): for each query, compare the top-k document indices by dot product using the dequantised documents against the exact top-k, and return the mean overlap fraction