Skip to content

Commit f0f3054

Browse files
Merge branch 'main' into semantic-text_index-options_license-tests
2 parents bfc490d + 315aba6 commit f0f3054

File tree

33 files changed

+422
-190
lines changed

33 files changed

+422
-190
lines changed

benchmarks/src/main/java/org/elasticsearch/benchmark/vector/OptimizedScalarQuantizerBenchmark.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public class OptimizedScalarQuantizerBenchmark {
4343

4444
float[] vector;
4545
float[] centroid;
46-
byte[] destination;
46+
byte[] legacyDestination;
47+
int[] destination;
4748

4849
@Param({ "1", "4", "7" })
4950
byte bits;
@@ -54,7 +55,8 @@ public class OptimizedScalarQuantizerBenchmark {
5455
public void init() {
5556
ThreadLocalRandom random = ThreadLocalRandom.current();
5657
// random byte arrays for binary methods
57-
destination = new byte[dims];
58+
legacyDestination = new byte[dims];
59+
destination = new int[dims];
5860
vector = new float[dims];
5961
centroid = new float[dims];
6062
for (int i = 0; i < dims; ++i) {
@@ -65,13 +67,20 @@ public void init() {
6567

6668
@Benchmark
6769
public byte[] scalar() {
68-
osq.scalarQuantize(vector, destination, bits, centroid);
69-
return destination;
70+
osq.legacyScalarQuantize(vector, legacyDestination, bits, centroid);
71+
return legacyDestination;
72+
}
73+
74+
@Benchmark
75+
@Fork(jvmArgsPrepend = { "--add-modules=jdk.incubator.vector" })
76+
public byte[] legacyVector() {
77+
osq.legacyScalarQuantize(vector, legacyDestination, bits, centroid);
78+
return legacyDestination;
7079
}
7180

7281
@Benchmark
7382
@Fork(jvmArgsPrepend = { "--add-modules=jdk.incubator.vector" })
74-
public byte[] vector() {
83+
public int[] vector() {
7584
osq.scalarQuantize(vector, destination, bits, centroid);
7685
return destination;
7786
}

docs/reference/query-languages/esql/images/functions/knn.svg

Lines changed: 1 addition & 1 deletion
Loading

docs/reference/query-languages/esql/kibana/definition/functions/knn.json

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/kibana/docs/functions/knn.md

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs/simdvec/src/main/java/org/elasticsearch/simdvec/ESVectorUtil.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,25 @@ public static float soarDistance(float[] v1, float[] centroid, float[] originalR
258258
}
259259
return IMPL.soarDistance(v1, centroid, originalResidual, soarLambda, rnorm);
260260
}
261+
262+
/**
263+
* Optimized-scalar quantization of the provided vector to the provided destination array.
264+
*
265+
* @param vector the vector to quantize
266+
* @param destination the array to store the result
267+
* @param lowInterval the minimum value, lower values in the original array will be replaced by this value
268+
* @param upperInterval the maximum value, bigger values in the original array will be replaced by this value
269+
* @param bit the number of bits to use for quantization, must be between 1 and 8
270+
*
271+
* @return return the sum of all the elements of the resulting quantized vector.
272+
*/
273+
public static int quantizeVectorWithIntervals(float[] vector, int[] destination, float lowInterval, float upperInterval, byte bit) {
274+
if (vector.length > destination.length) {
275+
throw new IllegalArgumentException("vector dimensions differ: " + vector.length + "!=" + destination.length);
276+
}
277+
if (bit <= 0 || bit > Byte.SIZE) {
278+
throw new IllegalArgumentException("bit must be between 1 and 8, but was: " + bit);
279+
}
280+
return IMPL.quantizeVectorWithIntervals(vector, destination, lowInterval, upperInterval, bit);
281+
}
261282
}

libs/simdvec/src/main/java/org/elasticsearch/simdvec/internal/vectorization/DefaultESVectorUtilSupport.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,4 +269,18 @@ public static float ipFloatByteImpl(float[] q, byte[] d) {
269269
}
270270
return ret;
271271
}
272+
273+
@Override
274+
public int quantizeVectorWithIntervals(float[] vector, int[] destination, float lowInterval, float upperInterval, byte bits) {
275+
float nSteps = ((1 << bits) - 1);
276+
float step = (upperInterval - lowInterval) / nSteps;
277+
int sumQuery = 0;
278+
for (int h = 0; h < vector.length; h++) {
279+
float xi = Math.min(Math.max(vector[h], lowInterval), upperInterval);
280+
int assignment = Math.round((xi - lowInterval) / step);
281+
sumQuery += assignment;
282+
destination[h] = assignment;
283+
}
284+
return sumQuery;
285+
}
272286
}

libs/simdvec/src/main/java/org/elasticsearch/simdvec/internal/vectorization/ESVectorUtilSupport.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,6 @@ public interface ESVectorUtilSupport {
3939

4040
float soarDistance(float[] v1, float[] centroid, float[] originalResidual, float soarLambda, float rnorm);
4141

42+
int quantizeVectorWithIntervals(float[] vector, int[] quantize, float lowInterval, float upperInterval, byte bit);
43+
4244
}

libs/simdvec/src/main21/java/org/elasticsearch/simdvec/internal/vectorization/PanamaESVectorUtilSupport.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,4 +791,32 @@ public static float ipFloatByteImpl(float[] q, byte[] d) {
791791

792792
return sum;
793793
}
794+
795+
@Override
796+
public int quantizeVectorWithIntervals(float[] vector, int[] destination, float lowInterval, float upperInterval, byte bits) {
797+
float nSteps = ((1 << bits) - 1);
798+
float step = (upperInterval - lowInterval) / nSteps;
799+
int sumQuery = 0;
800+
int i = 0;
801+
if (vector.length > 2 * FLOAT_SPECIES.length()) {
802+
int limit = FLOAT_SPECIES.loopBound(vector.length);
803+
FloatVector lowVec = FloatVector.broadcast(FLOAT_SPECIES, lowInterval);
804+
FloatVector upperVec = FloatVector.broadcast(FLOAT_SPECIES, upperInterval);
805+
FloatVector stepVec = FloatVector.broadcast(FLOAT_SPECIES, step);
806+
for (; i < limit; i += FLOAT_SPECIES.length()) {
807+
FloatVector v = FloatVector.fromArray(FLOAT_SPECIES, vector, i);
808+
FloatVector xi = v.max(lowVec).min(upperVec); // clamp
809+
IntVector assignment = xi.sub(lowVec).div(stepVec).add(0.5f).convert(VectorOperators.F2I, 0).reinterpretAsInts(); // round
810+
sumQuery += assignment.reduceLanes(ADD);
811+
assignment.intoArray(destination, i);
812+
}
813+
}
814+
for (; i < vector.length; i++) {
815+
float xi = Math.min(Math.max(vector[i], lowInterval), upperInterval);
816+
int assignment = Math.round((xi - lowInterval) / step);
817+
sumQuery += assignment;
818+
destination[i] = assignment;
819+
}
820+
return sumQuery;
821+
}
794822
}

libs/simdvec/src/test/java/org/elasticsearch/simdvec/ESVectorUtilTests.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,29 @@ public void testSoarDistance() {
286286
assertEquals(expected, result, deltaEps);
287287
}
288288

289+
public void testQuantizeVectorWithIntervals() {
290+
int vectorSize = randomIntBetween(1, 2048);
291+
float[] vector = new float[vectorSize];
292+
293+
byte bits = (byte) randomIntBetween(1, 8);
294+
for (int i = 0; i < vectorSize; ++i) {
295+
vector[i] = random().nextFloat();
296+
}
297+
float low = random().nextFloat();
298+
float high = random().nextFloat();
299+
if (low > high) {
300+
float tmp = low;
301+
low = high;
302+
high = tmp;
303+
}
304+
int[] quantizeExpected = new int[vectorSize];
305+
int[] quantizeResult = new int[vectorSize];
306+
var expected = defaultedProvider.getVectorUtilSupport().quantizeVectorWithIntervals(vector, quantizeExpected, low, high, bits);
307+
var result = defOrPanamaProvider.getVectorUtilSupport().quantizeVectorWithIntervals(vector, quantizeResult, low, high, bits);
308+
assertArrayEquals(quantizeExpected, quantizeResult);
309+
assertEquals(expected, result, 0f);
310+
}
311+
289312
void testIpByteBinImpl(ToLongBiFunction<byte[], byte[]> ipByteBinFunc) {
290313
int iterations = atLeast(50);
291314
for (int i = 0; i < iterations; i++) {

muted-tests.yml

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ tests:
236236
- class: org.elasticsearch.packaging.test.DockerTests
237237
method: test012SecurityCanBeDisabled
238238
issue: https://github.com/elastic/elasticsearch/issues/116636
239+
- class: org.elasticsearch.index.shard.StoreRecoveryTests
240+
method: testAddIndices
241+
issue: https://github.com/elastic/elasticsearch/issues/124104
239242
- class: org.elasticsearch.smoketest.MlWithSecurityIT
240243
method: test {yaml=ml/data_frame_analytics_crud/Test get stats on newly created config}
241244
issue: https://github.com/elastic/elasticsearch/issues/121726
@@ -455,6 +458,12 @@ tests:
455458
- class: org.elasticsearch.packaging.test.DockerTests
456459
method: test073RunEsAsDifferentUserAndGroupWithoutBindMounting
457460
issue: https://github.com/elastic/elasticsearch/issues/128996
461+
- class: org.elasticsearch.upgrades.UpgradeClusterClientYamlTestSuiteIT
462+
method: test {p0=upgraded_cluster/70_ilm/Test Lifecycle Still There And Indices Are Still Managed}
463+
issue: https://github.com/elastic/elasticsearch/issues/129097
464+
- class: org.elasticsearch.upgrades.UpgradeClusterClientYamlTestSuiteIT
465+
method: test {p0=upgraded_cluster/90_ml_data_frame_analytics_crud/Get mixed cluster outlier_detection job}
466+
issue: https://github.com/elastic/elasticsearch/issues/129098
458467
- class: org.elasticsearch.packaging.test.DockerTests
459468
method: test081SymlinksAreFollowedWithEnvironmentVariableFiles
460469
issue: https://github.com/elastic/elasticsearch/issues/128867
@@ -473,21 +482,27 @@ tests:
473482
- class: org.elasticsearch.entitlement.runtime.policy.FileAccessTreeTests
474483
method: testWindowsAbsolutPathAccess
475484
issue: https://github.com/elastic/elasticsearch/issues/129168
476-
- class: org.elasticsearch.xpack.esql.qa.multi_node.EsqlSpecIT
477-
method: test {knn-function.KnnSearchWithKOption ASYNC}
478-
issue: https://github.com/elastic/elasticsearch/issues/129447
479485
- class: org.elasticsearch.xpack.ml.integration.ClassificationIT
480486
method: testWithDatastreams
481487
issue: https://github.com/elastic/elasticsearch/issues/129457
482488
- class: org.elasticsearch.index.engine.ThreadPoolMergeExecutorServiceDiskSpaceTests
483489
method: testMergeTasksAreUnblockedWhenMoreDiskSpaceBecomesAvailable
484490
issue: https://github.com/elastic/elasticsearch/issues/129296
491+
- class: org.elasticsearch.xpack.security.PermissionsIT
492+
method: testCanManageIndexWithNoPermissions
493+
issue: https://github.com/elastic/elasticsearch/issues/129471
494+
- class: org.elasticsearch.xpack.security.PermissionsIT
495+
method: testCanManageIndexAndPolicyDifferentUsers
496+
issue: https://github.com/elastic/elasticsearch/issues/129479
497+
- class: org.elasticsearch.xpack.security.PermissionsIT
498+
method: testCanViewExplainOnUnmanagedIndex
499+
issue: https://github.com/elastic/elasticsearch/issues/129480
485500
- class: org.elasticsearch.xpack.profiling.action.GetStatusActionIT
486501
method: testWaitsUntilResourcesAreCreated
487502
issue: https://github.com/elastic/elasticsearch/issues/129486
488-
- class: org.elasticsearch.xpack.esql.qa.multi_node.EsqlSpecIT
489-
method: test {knn-function.KnnSearchWithKOption SYNC}
490-
issue: https://github.com/elastic/elasticsearch/issues/129512
503+
- class: org.elasticsearch.xpack.security.PermissionsIT
504+
method: testWhenUserLimitedByOnlyAliasOfIndexCanWriteToIndexWhichWasRolledoverByILMPolicy
505+
issue: https://github.com/elastic/elasticsearch/issues/129481
491506
- class: org.elasticsearch.index.engine.ThreadPoolMergeExecutorServiceTests
492507
method: testIORateIsAdjustedForAllRunningMergeTasks
493508
issue: https://github.com/elastic/elasticsearch/issues/129531
@@ -503,15 +518,24 @@ tests:
503518
- class: org.elasticsearch.search.query.VectorIT
504519
method: testFilteredQueryStrategy
505520
issue: https://github.com/elastic/elasticsearch/issues/129517
521+
- class: org.elasticsearch.snapshots.SnapshotShutdownIT
522+
method: testSnapshotShutdownProgressTracker
523+
issue: https://github.com/elastic/elasticsearch/issues/129752
506524
- class: org.elasticsearch.xpack.security.SecurityRolesMultiProjectIT
507525
method: testUpdatingFileBasedRoleAffectsAllProjects
508526
issue: https://github.com/elastic/elasticsearch/issues/129775
509527
- class: org.elasticsearch.qa.verify_version_constants.VerifyVersionConstantsIT
510528
method: testLuceneVersionConstant
511529
issue: https://github.com/elastic/elasticsearch/issues/125638
530+
- class: org.elasticsearch.index.store.FsDirectoryFactoryTests
531+
method: testPreload
532+
issue: https://github.com/elastic/elasticsearch/issues/129852
512533
- class: org.elasticsearch.xpack.rank.rrf.RRFRankClientYamlTestSuiteIT
513534
method: test {yaml=rrf/950_pinned_interaction/rrf with pinned retriever as a sub-retriever}
514535
issue: https://github.com/elastic/elasticsearch/issues/129845
536+
- class: org.elasticsearch.xpack.test.rest.XPackRestIT
537+
method: test {p0=esql/60_usage/Basic ESQL usage output (telemetry) non-snapshot version}
538+
issue: https://github.com/elastic/elasticsearch/issues/129888
515539
- class: org.elasticsearch.gradle.internal.InternalDistributionBwcSetupPluginFuncTest
516540
method: "builds distribution from branches via archives extractedAssemble [bwcDistVersion: 8.2.1, bwcProject: bugfix, expectedAssembleTaskName:
517541
extractedAssemble, #2]"
@@ -525,9 +549,14 @@ tests:
525549
- class: org.elasticsearch.xpack.esql.qa.multi_node.GenerativeIT
526550
method: test
527551
issue: https://github.com/elastic/elasticsearch/issues/130067
552+
- class: geoip.GeoIpMultiProjectIT
553+
issue: https://github.com/elastic/elasticsearch/issues/130073
528554
- class: org.elasticsearch.xpack.esql.qa.single_node.GenerativeIT
529555
method: test
530556
issue: https://github.com/elastic/elasticsearch/issues/130067
557+
- class: org.elasticsearch.xpack.esql.action.EnrichIT
558+
method: testTopN
559+
issue: https://github.com/elastic/elasticsearch/issues/130122
531560
- class: org.elasticsearch.action.support.ThreadedActionListenerTests
532561
method: testRejectionHandling
533562
issue: https://github.com/elastic/elasticsearch/issues/130129

0 commit comments

Comments
 (0)