1818import org .apache .lucene .search .DoubleValues ;
1919import org .apache .lucene .search .DoubleValuesSource ;
2020import org .apache .lucene .search .IndexSearcher ;
21+ import org .elasticsearch .search .profile .query .QueryProfiler ;
22+ import org .elasticsearch .search .vectors .QueryProfilerProvider ;
2123
2224import java .io .IOException ;
2325import java .util .Arrays ;
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