Skip to content

Apache Lucene open-source search software

Adjust return type for VectorUtil methods (#12122)

Luca Cavanna57397f0cabaf
diff --git a/lucene/core/src/java/org/apache/lucene/index/VectorSimilarityFunction.java b/lucene/core/src/java/org/apache/lucene/index/VectorSimilarityFunction.java
index d5ebcabb7a3..3646cf65584 100644
--- a/lucene/core/src/java/org/apache/lucene/index/VectorSimilarityFunction.java
+++ b/lucene/core/src/java/org/apache/lucene/index/VectorSimilarityFunction.java
@@ -37,7 +37,7 @@ public enum VectorSimilarityFunction {
@Override
public float compare(byte[] v1, byte[] v2) {
- return 1 / (1 + squareDistance(v1, v2));
+ return 1 / (1f + squareDistance(v1, v2));
}
},
diff --git a/lucene/core/src/java/org/apache/lucene/util/VectorUtil.java b/lucene/core/src/java/org/apache/lucene/util/VectorUtil.java
index 8800d434ba6..2a08436ec0b 100644
--- a/lucene/core/src/java/org/apache/lucene/util/VectorUtil.java
+++ b/lucene/core/src/java/org/apache/lucene/util/VectorUtil.java
@@ -181,7 +181,7 @@ public final class VectorUtil {
}
/** Returns the sum of squared differences of the two vectors. */
- public static float squareDistance(byte[] a, byte[] b) {
+ public static int squareDistance(byte[] a, byte[] b) {
// Note: this will not overflow if dim < 2^18, since max(byte * byte) = 2^14.
int squareSum = 0;
for (int i = 0; i < a.length; i++) {
@@ -249,7 +249,7 @@ public final class VectorUtil {
* @param b bytes containing another vector, of the same dimension
* @return the value of the dot product of the two vectors
*/
- public static float dotProduct(byte[] a, byte[] b) {
+ public static int dotProduct(byte[] a, byte[] b) {
assert a.length == b.length;
int total = 0;
for (int i = 0; i < a.length; i++) {