When deploying embedding models in production, embeddings are often quantized from floating-point to lower-precision integer representations to reduce memory and accelerate retrieval. However, quantization introduces distortion. A key quality metric is the cosine similarity between the original embedding and its quantized-then-dequantized counterpart.
Implement a function embedding_quantization_quality that:
embeddings of shape (n, d), where each row is an embedding vector, and an integer num_bits specifying the quantization bit-width.mean_cosine_similarity, min_cosine_similarity, and max_cosine_similarity, each rounded to 6 decimal places.Quantization details:
2^num_bits - 1.