From 0a2ecb54d7a283cab073708651350c28071cf72f Mon Sep 17 00:00:00 2001 From: Jonathan Ellis Date: Fri, 13 Oct 2023 14:41:19 -0500 Subject: [PATCH] r/m PQ::decodedCosine --- .../jvector/pq/ProductQuantization.java | 27 ------------------- 1 file changed, 27 deletions(-) diff --git a/jvector-base/src/main/java/io/github/jbellis/jvector/pq/ProductQuantization.java b/jvector-base/src/main/java/io/github/jbellis/jvector/pq/ProductQuantization.java index 4348ab9ea..92007eecb 100644 --- a/jvector-base/src/main/java/io/github/jbellis/jvector/pq/ProductQuantization.java +++ b/jvector-base/src/main/java/io/github/jbellis/jvector/pq/ProductQuantization.java @@ -125,33 +125,6 @@ public byte[] encode(float[] vector) { return encoded; } - /** - * Computes the cosine of the (approximate) original decoded vector with - * another vector. - *

- * This method can compute the cosine without materializing the decoded vector as a new float[], - * which will be roughly 1.5x as fast as decode() + dot(). - *

- * It is the caller's responsibility to center the `other` vector by subtracting the global centroid - * before calling this method. - */ - public float decodedCosine(byte[] encoded, float[] other) { - float sum = 0.0f; - float aMagnitude = 0.0f; - float bMagnitude = 0.0f; - for (int m = 0; m < M; ++m) { - int offset = subvectorSizesAndOffsets[m][1]; - int centroidIndex = Byte.toUnsignedInt(encoded[m]); - float[] centroidSubvector = codebooks[m][centroidIndex]; - var length = centroidSubvector.length; - sum += VectorUtil.dotProduct(centroidSubvector, 0, other, offset, length); - aMagnitude += VectorUtil.dotProduct(centroidSubvector, 0, centroidSubvector, 0, length); - bMagnitude += VectorUtil.dotProduct(other, offset, other, offset, length); - } - - return (float) (sum / Math.sqrt(aMagnitude * bMagnitude)); - } - /** * Decodes the quantized representation (byte array) to its approximate original vector. */