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 ;
@@ -80,10 +82,10 @@ public class VectorScorerInt7uBulkBenchmark {
8082
8183 // 128k is typically enough to not fit in L1 (core) cache for most processors;
8284 // 1.5M is typically enough to not fit in L2 (core) cache;
83- // 40M is typically enough to not fit in L3 cache
84- @ Param ({ "128000 " , "1500000 " , "30000000 " })
85+ // 130M is enough to not fit in L3 cache
86+ @ Param ({ "128 " , "1500 " , "130000 " })
8587 public int numVectors ;
86- public int numVectorsToScore = 20_000 ;
88+ public int numVectorsToScore ;
8789
8890 Path path ;
8991 Directory dir ;
@@ -100,8 +102,12 @@ 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 {
110+ numVectorsToScore = Math .min (numVectors , 20_000 );
105111 factory = getScorerFactoryOrDie ();
106112
107113 var random = ThreadLocalRandom .current ();
@@ -127,6 +133,17 @@ public void setup() throws IOException {
127133 .orElseThrow ()
128134 .scorer ();
129135 nativeDotScorer .setScoringOrdinal (targetOrd );
136+
137+ if (supportsHeapSegments ()) {
138+ // setup for getInt7SQVectorScorer / query vector scoring
139+ float [] queryVec = new float [dims ];
140+ for (int i = 0 ; i < dims ; i ++) {
141+ queryVec [i ] = random .nextFloat ();
142+ }
143+ luceneDotScorerQuery = luceneScorer (dotProductValues , VectorSimilarityFunction .DOT_PRODUCT , queryVec );
144+ nativeDotScorerQuery = factory .getInt7SQVectorScorer (VectorSimilarityFunction .DOT_PRODUCT , dotProductValues , queryVec )
145+ .orElseThrow ();
146+ }
130147 }
131148
132149 @ TearDown
@@ -151,6 +168,14 @@ public float[] dotProductLuceneMultipleRandom() throws IOException {
151168 return scores ;
152169 }
153170
171+ @ Benchmark
172+ public float [] dotProductLuceneQueryMultipleRandom () throws IOException {
173+ for (int v = 0 ; v < numVectorsToScore ; v ++) {
174+ scores [v ] = luceneDotScorerQuery .score (ordinals [v ]);
175+ }
176+ return scores ;
177+ }
178+
154179 @ Benchmark
155180 public float [] dotProductNativeMultipleSequential () throws IOException {
156181 for (int v = 0 ; v < numVectorsToScore ; v ++) {
@@ -167,6 +192,14 @@ public float[] dotProductNativeMultipleRandom() throws IOException {
167192 return scores ;
168193 }
169194
195+ @ Benchmark
196+ public float [] dotProductNativeQueryMultipleRandom () throws IOException {
197+ for (int v = 0 ; v < numVectorsToScore ; v ++) {
198+ scores [v ] = nativeDotScorerQuery .score (ordinals [v ]);
199+ }
200+ return scores ;
201+ }
202+
170203 @ Benchmark
171204 public float [] dotProductNativeMultipleSequentialBulk () throws IOException {
172205 nativeDotScorer .bulkScore (ids , scores , ordinals .length );
@@ -179,6 +212,12 @@ public float[] dotProductNativeMultipleRandomBulk() throws IOException {
179212 return scores ;
180213 }
181214
215+ @ Benchmark
216+ public float [] dotProductNativeQueryMultipleRandomBulk () throws IOException {
217+ nativeDotScorerQuery .bulkScore (ordinals , scores , ordinals .length );
218+ return scores ;
219+ }
220+
182221 @ Benchmark
183222 public float [] dotProductScalarMultipleSequential () throws IOException {
184223 var queryVector = dotProductValues .vectorValue (targetOrd );
0 commit comments