Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public void execute(Task t) {
"--add-opens=java.base/java.time=ALL-UNNAMED",
"--add-opens=java.management/java.lang.management=ALL-UNNAMED",
"--enable-native-access=ALL-UNNAMED",
"--add-modules=jdk.incubator.vector",
"-XX:+HeapDumpOnOutOfMemoryError"
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,23 @@ public void testQuantizedVectorsWriteAndRead() throws IOException {
);
ESVectorUtil.packAsBinary(quantizedVector, expectedVector);
assertArrayEquals(expectedVector, qvectorValues.vectorValue(docIndexIterator.index()));
assertEquals(corrections, qvectorValues.getCorrectiveTerms(docIndexIterator.index()));
assertQuantizationResultEquals(corrections, qvectorValues.getCorrectiveTerms(docIndexIterator.index()));
}
}
}
}
}

static void assertQuantizationResultEquals(
OptimizedScalarQuantizer.QuantizationResult expected,
OptimizedScalarQuantizer.QuantizationResult obj
) {
assertEquals(expected.lowerInterval(), obj.lowerInterval(), 0.000001f);
assertEquals(expected.upperInterval(), obj.upperInterval(), 0.000001f);
assertEquals(expected.additionalCorrection(), obj.additionalCorrection(), 0.00001f);
assertEquals(expected.quantizedComponentSum(), obj.quantizedComponentSum());
}

public void testSimpleOffHeapSize() throws IOException {
try (Directory dir = newDirectory()) {
testSimpleOffHeapSizeImpl(dir, newIndexWriterConfig(), true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1929,8 +1929,8 @@ public void testKnnVectorsFormat() throws IOException {
+ (setM ? m : DEFAULT_MAX_CONN)
+ ", beamWidth="
+ (setEfConstruction ? efConstruction : DEFAULT_BEAM_WIDTH)
+ ", flatVectorFormat=ES93GenericFlatVectorsFormat(name=ES93GenericFlatVectorsFormat"
+ ", format=Lucene99FlatVectorsFormat(name=Lucene99FlatVectorsFormat, flatVectorScorer=DefaultFlatVectorScorer())))";
+ ", flatVectorFormat=ES93GenericFlatVectorsFormat(name=ES93GenericFlatVectorsFormat, format="
+ "Lucene99FlatVectorsFormat(name=Lucene99FlatVectorsFormat, flatVectorScorer=Lucene99MemorySegmentFlatVectorsScorer())))";
assertEquals(expectedString, knnVectorsFormat.toString());
}

Expand Down Expand Up @@ -1972,12 +1972,12 @@ public void testKnnQuantizedFlatVectorsFormat() throws IOException {
+ ", compressed="
+ quantizedFlatFormat.equals("int4_flat")
+ ", flatVectorScorer=ESQuantizedFlatVectorsScorer("
+ "delegate=ScalarQuantizedVectorScorer(nonQuantizedDelegate=DefaultFlatVectorScorer())"
+ "delegate=ScalarQuantizedVectorScorer(nonQuantizedDelegate=Lucene99MemorySegmentFlatVectorsScorer())"
+ ", factory="
+ (factory != null ? factory : "null")
+ "), "
+ "rawVectorFormat=ES93GenericFlatVectorsFormat(name=ES93GenericFlatVectorsFormat"
+ ", format=Lucene99FlatVectorsFormat(name=Lucene99FlatVectorsFormat, flatVectorScorer=DefaultFlatVectorScorer())))";
+ "rawVectorFormat=ES93GenericFlatVectorsFormat(name=ES93GenericFlatVectorsFormat, format="
+ "Lucene99FlatVectorsFormat(name=Lucene99FlatVectorsFormat, flatVectorScorer=Lucene99MemorySegmentFlatVectorsScorer())))";
assertThat(knnVectorsFormat, hasToString(expectedString));
}
}
Expand Down Expand Up @@ -2023,11 +2023,11 @@ public void testKnnQuantizedHNSWVectorsFormat() throws IOException {
+ (setConfidenceInterval ? confidenceInterval : null)
+ ", bits=7, compressed=false, "
+ "flatVectorScorer=ESQuantizedFlatVectorsScorer(delegate="
+ "ScalarQuantizedVectorScorer(nonQuantizedDelegate=DefaultFlatVectorScorer()), "
+ "ScalarQuantizedVectorScorer(nonQuantizedDelegate=Lucene99MemorySegmentFlatVectorsScorer()), "
+ "factory="
+ (factory != null ? factory : "null")
+ "), flatVectorFormat=ES93GenericFlatVectorsFormat(name=ES93GenericFlatVectorsFormat"
+ ", format=Lucene99FlatVectorsFormat(name=Lucene99FlatVectorsFormat, flatVectorScorer=DefaultFlatVectorScorer())))";
+ "), flatVectorFormat=ES93GenericFlatVectorsFormat(name=ES93GenericFlatVectorsFormat, format="
+ "Lucene99FlatVectorsFormat(name=Lucene99FlatVectorsFormat, flatVectorScorer=Lucene99MemorySegmentFlatVectorsScorer())))";
assertThat(knnVectorsFormat, hasToString(expectedString));
}

Expand Down Expand Up @@ -2126,10 +2126,10 @@ public void testKnnHalfByteQuantizedHNSWVectorsFormat() throws IOException {
+ ", confidenceInterval="
+ (setConfidenceInterval ? confidenceInterval : 0.0f)
+ ", bits=4, compressed=true, flatVectorScorer=ESQuantizedFlatVectorsScorer(delegate="
+ "ScalarQuantizedVectorScorer(nonQuantizedDelegate=DefaultFlatVectorScorer()), factory="
+ "ScalarQuantizedVectorScorer(nonQuantizedDelegate=Lucene99MemorySegmentFlatVectorsScorer()), factory="
+ (factory != null ? factory : "null")
+ "), flatVectorFormat=ES93GenericFlatVectorsFormat(name=ES93GenericFlatVectorsFormat"
+ ", format=Lucene99FlatVectorsFormat(name=Lucene99FlatVectorsFormat, flatVectorScorer=DefaultFlatVectorScorer())))";
+ "), flatVectorFormat=ES93GenericFlatVectorsFormat(name=ES93GenericFlatVectorsFormat, format="
+ "Lucene99FlatVectorsFormat(name=Lucene99FlatVectorsFormat, flatVectorScorer=Lucene99MemorySegmentFlatVectorsScorer())))";
assertThat(knnVectorsFormat, hasToString(expectedString));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import static org.elasticsearch.xpack.esql.core.type.DataType.DENSE_VECTOR;
import static org.elasticsearch.xpack.esql.core.type.DataType.DOUBLE;
import static org.hamcrest.Matchers.closeTo;
import static org.hamcrest.Matchers.equalTo;

public abstract class AbstractVectorSimilarityFunctionTestCase extends AbstractVectorTestCase {
Expand Down Expand Up @@ -51,14 +52,15 @@ protected static Iterable<Object[]> similarityParameters(
float[] leftArray = listToFloatArray(left);
float[] rightArray = listToFloatArray(right);
double expected = similarityFunction.calculateSimilarity(leftArray, rightArray);
double delta = BASE_DELTA * dimensions;
return new TestCaseSupplier.TestCase(
List.of(
new TestCaseSupplier.TypedData(left, DENSE_VECTOR, "vector1"),
new TestCaseSupplier.TypedData(right, DENSE_VECTOR, "vector2")
),
evaluatorName,
DOUBLE,
equalTo(expected) // Random vectors should have cosine similarity close to 0
closeTo(expected, delta) // Random vectors should have cosine similarity close to 0
);
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

public abstract class AbstractVectorTestCase extends AbstractScalarFunctionTestCase {

// Base tolerance for vector score comparisons, scaled by dimensionality to
// accommodate minor floating-point rounding differences from SIMD arithmetic.
static final double BASE_DELTA = 1e-5;

protected static float[] listToFloatArray(List<Float> floatList) {
float[] floatArray = new float[floatList.size()];
for (int i = 0; i < floatList.size(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import static org.elasticsearch.xpack.esql.core.type.DataType.DENSE_VECTOR;
import static org.elasticsearch.xpack.esql.core.type.DataType.DOUBLE;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.closeTo;

@FunctionName("v_magnitude")
public class MagnitudeTests extends AbstractVectorTestCase {
Expand Down Expand Up @@ -63,11 +63,12 @@ protected static Iterable<Object[]> scalarParameters(String className, Magnitude
List<Float> input = randomDenseVector(dimensions);
float[] array = listToFloatArray(input);
double expected = scalarFunction.calculateScalar(array);
double delta = BASE_DELTA * dimensions;
return new TestCaseSupplier.TestCase(
List.of(new TestCaseSupplier.TypedData(input, DENSE_VECTOR, "vector")),
evaluatorName,
DOUBLE,
equalTo(expected)
closeTo(expected, delta)
);
}));

Expand Down