Skip to content

Commit 7bb054f

Browse files
authored
Extend reflection to retrieve vector values from DefaultFlatVectorScorer$FloatScoringSupplier too (#138503)
While running gpu:yamlRestTest tests, under some circumstances the scorer is not Lucene99MemorySegmentFloatVectorScorerSupplier, but DefaultFlatVectorScorer$FloatScoringSupplier. This PR extend reflection to support the "fast path" to access vector values to this class too.
1 parent 5e91ec0 commit 7bb054f

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

distribution/tools/server-cli/src/main/java/org/elasticsearch/server/cli/SystemJvmOptions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ static List<String> systemJvmOptions(Settings nodeSettings, final Map<String, St
6262
"-Dio.netty.recycler.maxCapacityPerThread=0",
6363
// Needed to get access to raw vectors from Lucene scorers
6464
"--add-opens=org.apache.lucene.core/org.apache.lucene.codecs.lucene99=org.elasticsearch.server",
65+
"--add-opens=org.apache.lucene.core/org.apache.lucene.codecs.hnsw=org.elasticsearch.server",
6566
"--add-opens=org.apache.lucene.core/org.apache.lucene.internal.vectorization=org.elasticsearch.server",
6667
// log4j 2
6768
"-Dlog4j.shutdownHookEnabled=false",

libs/gpu-codec/src/main/java/org/elasticsearch/gpu/codec/ES92GpuHnswVectorsWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ private void mergeByteVectorField(
620620
}
621621
}
622622
} else {
623-
logger.warn("Cannot get merged raw vectors from scorer.");
623+
logger.warn("Cannot get merged raw vectors from scorer. Performances will be degraded.");
624624
var byteVectorValues = getMergedByteVectorValues(fieldInfo, mergeState);
625625

626626
// TODO: revert to CuVSMatrix.deviceBuilder when cuvs has fixed the multiple copies problem

server/src/main/java/org/elasticsearch/index/codec/vectors/reflect/VectorsFormatReflectionUtils.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@
2222
public class VectorsFormatReflectionUtils {
2323
private static final VarHandle FLOAT_SUPPLIER_HANDLE;
2424
private static final VarHandle BYTE_SUPPLIER_HANDLE;
25-
private static final VarHandle FLOAT_VECTORS_HANDLE;
25+
private static final VarHandle L99_FLOAT_VECTORS_HANDLE;
26+
private static final VarHandle DEFAULT_FLOAT_VECTORS_HANDLE;
2627

2728
private static final Class<?> FLAT_CLOSEABLE_RANDOM_VECTOR_SCORER_SUPPLIER_CLASS;
2829
private static final Class<?> SCALAR_QUANTIZED_CLOSEABLE_RANDOM_VECTOR_SCORER_SUPPLIER_CLASS;
29-
private static final Class<?> FLOAT_SCORING_SUPPLIER_CLASS;
30+
private static final Class<?> L99_FLOAT_SCORING_SUPPLIER_CLASS;
31+
private static final Class<?> DEFAULT_FLOAT_SCORING_SUPPLIER_CLASS;
32+
3033
static {
3134
try {
3235
FLAT_CLOSEABLE_RANDOM_VECTOR_SCORER_SUPPLIER_CLASS = Class.forName(
@@ -39,11 +42,17 @@ public class VectorsFormatReflectionUtils {
3942
RandomVectorScorerSupplier.class
4043
);
4144

42-
FLOAT_SCORING_SUPPLIER_CLASS = Class.forName(
45+
L99_FLOAT_SCORING_SUPPLIER_CLASS = Class.forName(
4346
"org.apache.lucene.internal.vectorization.Lucene99MemorySegmentFloatVectorScorerSupplier"
4447
);
45-
lookup = MethodHandles.privateLookupIn(FLOAT_SCORING_SUPPLIER_CLASS, MethodHandles.lookup());
46-
FLOAT_VECTORS_HANDLE = lookup.findVarHandle(FLOAT_SCORING_SUPPLIER_CLASS, "values", FloatVectorValues.class);
48+
lookup = MethodHandles.privateLookupIn(L99_FLOAT_SCORING_SUPPLIER_CLASS, MethodHandles.lookup());
49+
L99_FLOAT_VECTORS_HANDLE = lookup.findVarHandle(L99_FLOAT_SCORING_SUPPLIER_CLASS, "values", FloatVectorValues.class);
50+
51+
DEFAULT_FLOAT_SCORING_SUPPLIER_CLASS = Class.forName(
52+
"org.apache.lucene.codecs.hnsw.DefaultFlatVectorScorer$FloatScoringSupplier"
53+
);
54+
lookup = MethodHandles.privateLookupIn(DEFAULT_FLOAT_SCORING_SUPPLIER_CLASS, MethodHandles.lookup());
55+
DEFAULT_FLOAT_VECTORS_HANDLE = lookup.findVarHandle(DEFAULT_FLOAT_SCORING_SUPPLIER_CLASS, "vectors", FloatVectorValues.class);
4756

4857
SCALAR_QUANTIZED_CLOSEABLE_RANDOM_VECTOR_SCORER_SUPPLIER_CLASS = Class.forName(
4958
Lucene99ScalarQuantizedVectorsWriter.class.getCanonicalName() + "$ScalarQuantizedCloseableRandomVectorScorerSupplier"
@@ -79,8 +88,13 @@ public static RandomVectorScorerSupplier getScalarQuantizedRandomVectorScorerInn
7988
}
8089

8190
public static HasIndexSlice getFloatScoringSupplierVectorOrNull(RandomVectorScorerSupplier scorerSupplier) {
82-
if (FLOAT_SCORING_SUPPLIER_CLASS.isAssignableFrom(scorerSupplier.getClass())) {
83-
var vectorValues = FLOAT_VECTORS_HANDLE.get(scorerSupplier);
91+
if (L99_FLOAT_SCORING_SUPPLIER_CLASS.isAssignableFrom(scorerSupplier.getClass())) {
92+
var vectorValues = L99_FLOAT_VECTORS_HANDLE.get(scorerSupplier);
93+
if (vectorValues instanceof HasIndexSlice indexSlice) {
94+
return indexSlice;
95+
}
96+
} else if (DEFAULT_FLOAT_SCORING_SUPPLIER_CLASS.isAssignableFrom(scorerSupplier.getClass())) {
97+
var vectorValues = DEFAULT_FLOAT_VECTORS_HANDLE.get(scorerSupplier);
8498
if (vectorValues instanceof HasIndexSlice indexSlice) {
8599
return indexSlice;
86100
}

x-pack/plugin/gpu/src/yamlRestTest/java/org/elasticsearch/xpack/gpu/GPUClientYamlTestSuiteIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ private static ElasticsearchCluster createCluster() {
3333
.setting("xpack.security.enabled", "false")
3434
// Needed to get access to raw vectors from Lucene scorers
3535
.jvmArg("--add-opens=org.apache.lucene.core/org.apache.lucene.codecs.lucene99=org.elasticsearch.server")
36+
.jvmArg("--add-opens=org.apache.lucene.core/org.apache.lucene.codecs.hnsw=org.elasticsearch.server")
3637
.jvmArg("--add-opens=org.apache.lucene.core/org.apache.lucene.internal.vectorization=org.elasticsearch.server");
3738

3839
var libraryPath = System.getenv("LD_LIBRARY_PATH");

0 commit comments

Comments
 (0)