Skip to content

Commit 811a5bf

Browse files
author
Kaival Parikh
committed
Fix off-heap byte vector scoring at query time
1 parent f4339ee commit 811a5bf

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

lucene/benchmark-jmh/src/java/org/apache/lucene/benchmark/jmh/VectorScorerBenchmark.java

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ public class VectorScorerBenchmark {
7070
IndexInput in;
7171
KnnVectorValues vectorValues;
7272
byte[] vec1, vec2;
73-
UpdateableRandomVectorScorer scorer;
73+
UpdateableRandomVectorScorer scorer1;
74+
RandomVectorScorer scorer2;
7475

7576
@Setup(Level.Iteration)
7677
public void init() throws IOException {
@@ -86,11 +87,11 @@ public void init() throws IOException {
8687
}
8788
in = dir.openInput("vector.data", IOContext.DEFAULT);
8889
vectorValues = vectorValues(size, 2, in, DOT_PRODUCT);
89-
scorer =
90-
FlatVectorScorerUtil.getLucene99FlatVectorsScorer()
91-
.getRandomVectorScorerSupplier(DOT_PRODUCT, vectorValues)
92-
.scorer();
93-
scorer.setScoringOrdinal(0);
90+
91+
FlatVectorsScorer flatVectorsScorer = FlatVectorScorerUtil.getLucene99FlatVectorsScorer();
92+
scorer1 = flatVectorsScorer.getRandomVectorScorerSupplier(DOT_PRODUCT, vectorValues).scorer();
93+
scorer1.setScoringOrdinal(0);
94+
scorer2 = flatVectorsScorer.getRandomVectorScorer(DOT_PRODUCT, vectorValues, vec1);
9495
}
9596

9697
@TearDown
@@ -99,14 +100,25 @@ public void teardown() throws IOException {
99100
}
100101

101102
@Benchmark
102-
public float binaryDotProductDefault() throws IOException {
103-
return scorer.score(1);
103+
public float binaryDotProductIndexingDefault() throws IOException {
104+
return scorer1.score(1);
105+
}
106+
107+
@Benchmark
108+
@Fork(jvmArgsPrepend = {"--add-modules=jdk.incubator.vector"})
109+
public float binaryDotProductIndexingMemSeg() throws IOException {
110+
return scorer1.score(1);
111+
}
112+
113+
@Benchmark
114+
public float binaryDotProductSearchingDefault() throws IOException {
115+
return scorer2.score(1);
104116
}
105117

106118
@Benchmark
107119
@Fork(jvmArgsPrepend = {"--add-modules=jdk.incubator.vector"})
108-
public float binaryDotProductMemSeg() throws IOException {
109-
return scorer.score(1);
120+
public float binaryDotProductSearchingMemSeg() throws IOException {
121+
return scorer2.score(1);
110122
}
111123

112124
static KnnVectorValues vectorValues(

lucene/core/src/java24/org/apache/lucene/internal/vectorization/Lucene99MemorySegmentByteVectorScorer.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
*/
1717
package org.apache.lucene.internal.vectorization;
1818

19+
import static java.lang.foreign.ValueLayout.JAVA_BYTE;
20+
1921
import java.io.IOException;
22+
import java.lang.foreign.Arena;
2023
import java.lang.foreign.MemorySegment;
2124
import java.util.Optional;
2225
import org.apache.lucene.index.ByteVectorValues;
@@ -61,7 +64,7 @@ public static Optional<Lucene99MemorySegmentByteVectorScorer> create(
6164
super(values);
6265
this.input = input;
6366
this.vectorByteSize = values.getVectorByteLength();
64-
this.query = MemorySegment.ofArray(queryVector);
67+
this.query = Arena.ofAuto().allocateFrom(JAVA_BYTE, queryVector);
6568
}
6669

6770
final MemorySegment getSegment(int ord) throws IOException {

0 commit comments

Comments
 (0)