Skip to content

Commit 1e7632c

Browse files
committed
Correctly implement profiling. Rename ProfilingQuery to QueryProfilerProvider
1 parent eff2be1 commit 1e7632c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

server/src/main/java/org/elasticsearch/index/mapper/vectors/VectorSimilarityByteValueSource.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import org.apache.lucene.search.DoubleValues;
1919
import org.apache.lucene.search.DoubleValuesSource;
2020
import org.apache.lucene.search.IndexSearcher;
21+
import org.elasticsearch.search.profile.query.QueryProfiler;
22+
import org.elasticsearch.search.vectors.QueryProfilerProvider;
2123

2224
import java.io.IOException;
2325
import java.util.Arrays;
@@ -27,11 +29,12 @@
2729
* DoubleValuesSource that is used to calculate scores according to a similarity function for a KnnByteVectorField, using the
2830
* original vector values stored in the index
2931
*/
30-
public class VectorSimilarityByteValueSource extends DoubleValuesSource {
32+
public class VectorSimilarityByteValueSource extends DoubleValuesSource implements QueryProfilerProvider {
3133

3234
private final String field;
3335
private final byte[] target;
3436
private final VectorSimilarityFunction vectorSimilarityFunction;
37+
private long vectorOpsCount;
3538

3639
public VectorSimilarityByteValueSource(String field, byte[] target, VectorSimilarityFunction vectorSimilarityFunction) {
3740
this.field = field;
@@ -51,6 +54,7 @@ public DoubleValues getValues(LeafReaderContext ctx, DoubleValues scores) throws
5154

5255
@Override
5356
public double doubleValue() throws IOException {
57+
vectorOpsCount++;
5458
return vectorSimilarityFunction.compare(target, vectorValues.vectorValue(docId));
5559
}
5660

@@ -72,6 +76,11 @@ public DoubleValuesSource rewrite(IndexSearcher reader) throws IOException {
7276
return this;
7377
}
7478

79+
@Override
80+
public void profile(QueryProfiler queryProfiler) {
81+
queryProfiler.addVectorOpsCount(vectorOpsCount);
82+
}
83+
7584
@Override
7685
public int hashCode() {
7786
return Objects.hash(field, Arrays.hashCode(target), vectorSimilarityFunction);

0 commit comments

Comments
 (0)