Skip to content

Commit

Permalink
Delegate xorBitCount to Lucene (elastic#114249)
Browse files Browse the repository at this point in the history
Now that we're on Lucene 9.12 we don't need our own optimized xorBitCount, can just delegate to Lucene's optimized one (which is identical).
  • Loading branch information
ChrisHegarty authored Oct 8, 2024
1 parent 2a0d5ff commit 6d6fc66
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
import org.apache.lucene.index.SegmentReadState;
import org.apache.lucene.index.SegmentWriteState;
import org.apache.lucene.index.VectorSimilarityFunction;
import org.apache.lucene.util.VectorUtil;
import org.apache.lucene.util.hnsw.RandomAccessVectorValues;
import org.apache.lucene.util.hnsw.RandomVectorScorer;
import org.apache.lucene.util.hnsw.RandomVectorScorerSupplier;
import org.apache.lucene.util.quantization.RandomAccessQuantizedByteVectorValues;
import org.elasticsearch.script.field.vectors.ESVectorUtil;

import java.io.IOException;

Expand Down Expand Up @@ -105,7 +105,7 @@ public RandomVectorScorer getRandomVectorScorer(
}

static float hammingScore(byte[] a, byte[] b) {
return ((a.length * Byte.SIZE) - ESVectorUtil.xorBitCount(a, b)) / (float) (a.length * Byte.SIZE);
return ((a.length * Byte.SIZE) - VectorUtil.xorBitCount(a, b)) / (float) (a.length * Byte.SIZE);
}

static class HammingVectorScorer extends RandomVectorScorer.AbstractRandomVectorScorer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public double l1Norm(List<Number> queryVector) {

@Override
public int hamming(byte[] queryVector) {
return ESVectorUtil.xorBitCount(queryVector, vectorValue);
return VectorUtil.xorBitCount(queryVector, vectorValue);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public double l1Norm(List<Number> queryVector) {

@Override
public int hamming(byte[] queryVector) {
return ESVectorUtil.xorBitCount(queryVector, docVector);
return VectorUtil.xorBitCount(queryVector, docVector);
}

@Override
Expand Down

This file was deleted.

0 comments on commit 6d6fc66

Please sign in to comment.