1414import org .apache .lucene .store .IOContext ;
1515import org .apache .lucene .store .IndexInput ;
1616import org .apache .lucene .store .MMapDirectory ;
17+ import org .apache .lucene .util .hnsw .RandomVectorScorer ;
1718import org .apache .lucene .util .hnsw .UpdateableRandomVectorScorer ;
1819import org .apache .lucene .util .quantization .QuantizedByteVectorValues ;
1920import org .elasticsearch .common .logging .LogConfigurator ;
4849import static org .elasticsearch .benchmark .vector .scorer .BenchmarkUtils .createRandomInt7VectorData ;
4950import static org .elasticsearch .benchmark .vector .scorer .BenchmarkUtils .getScorerFactoryOrDie ;
5051import static org .elasticsearch .benchmark .vector .scorer .BenchmarkUtils .luceneScoreSupplier ;
52+ import static org .elasticsearch .benchmark .vector .scorer .BenchmarkUtils .luceneScorer ;
5153import static org .elasticsearch .benchmark .vector .scorer .BenchmarkUtils .readNodeCorrectionConstant ;
5254import static org .elasticsearch .benchmark .vector .scorer .BenchmarkUtils .supportsHeapSegments ;
5355import static org .elasticsearch .benchmark .vector .scorer .BenchmarkUtils .vectorValues ;
@@ -100,6 +102,9 @@ public class VectorScorerInt7uBulkBenchmark {
100102 UpdateableRandomVectorScorer luceneDotScorer ;
101103 UpdateableRandomVectorScorer nativeDotScorer ;
102104
105+ RandomVectorScorer luceneDotScorerQuery ;
106+ RandomVectorScorer nativeDotScorerQuery ;
107+
103108 @ Setup (Level .Trial )
104109 public void setup () throws IOException {
105110 factory = getScorerFactoryOrDie ();
@@ -127,6 +132,17 @@ public void setup() throws IOException {
127132 .orElseThrow ()
128133 .scorer ();
129134 nativeDotScorer .setScoringOrdinal (targetOrd );
135+
136+ if (supportsHeapSegments ()) {
137+ // setup for getInt7SQVectorScorer / query vector scoring
138+ float [] queryVec = new float [dims ];
139+ for (int i = 0 ; i < dims ; i ++) {
140+ queryVec [i ] = random .nextFloat ();
141+ }
142+ luceneDotScorerQuery = luceneScorer (dotProductValues , VectorSimilarityFunction .DOT_PRODUCT , queryVec );
143+ nativeDotScorerQuery = factory .getInt7SQVectorScorer (VectorSimilarityFunction .DOT_PRODUCT , dotProductValues , queryVec )
144+ .orElseThrow ();
145+ }
130146 }
131147
132148 @ TearDown
@@ -151,6 +167,14 @@ public float[] dotProductLuceneMultipleRandom() throws IOException {
151167 return scores ;
152168 }
153169
170+ @ Benchmark
171+ public float [] dotProductLuceneQueryMultipleRandom () throws IOException {
172+ for (int v = 0 ; v < numVectorsToScore ; v ++) {
173+ scores [v ] = luceneDotScorerQuery .score (ordinals [v ]);
174+ }
175+ return scores ;
176+ }
177+
154178 @ Benchmark
155179 public float [] dotProductNativeMultipleSequential () throws IOException {
156180 for (int v = 0 ; v < numVectorsToScore ; v ++) {
@@ -167,6 +191,14 @@ public float[] dotProductNativeMultipleRandom() throws IOException {
167191 return scores ;
168192 }
169193
194+ @ Benchmark
195+ public float [] dotProductNativeQueryMultipleRandom () throws IOException {
196+ for (int v = 0 ; v < numVectorsToScore ; v ++) {
197+ scores [v ] = nativeDotScorerQuery .score (ordinals [v ]);
198+ }
199+ return scores ;
200+ }
201+
170202 @ Benchmark
171203 public float [] dotProductNativeMultipleSequentialBulk () throws IOException {
172204 nativeDotScorer .bulkScore (ids , scores , ordinals .length );
@@ -179,6 +211,12 @@ public float[] dotProductNativeMultipleRandomBulk() throws IOException {
179211 return scores ;
180212 }
181213
214+ @ Benchmark
215+ public float [] dotProductNativeQueryMultipleRandomBulk () throws IOException {
216+ nativeDotScorerQuery .bulkScore (ordinals , scores , ordinals .length );
217+ return scores ;
218+ }
219+
182220 @ Benchmark
183221 public float [] dotProductScalarMultipleSequential () throws IOException {
184222 var queryVector = dotProductValues .vectorValue (targetOrd );
0 commit comments