Skip to content

Commit c5988ed

Browse files
Merge branch 'main' of https://github.com/Jan-Kazlouski-elastic/elasticsearch into feature/hugging-face-chat-completion-integration
2 parents a4b5d2c + 9b1815c commit c5988ed

File tree

30 files changed

+2587
-12
lines changed

30 files changed

+2587
-12
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import org.apache.lucene.util.VectorUtil;
1818
import org.apache.lucene.util.quantization.OptimizedScalarQuantizer;
1919
import org.elasticsearch.common.logging.LogConfigurator;
20-
import org.elasticsearch.simdvec.internal.vectorization.ES91OSQVectorsScorer;
20+
import org.elasticsearch.simdvec.ES91OSQVectorsScorer;
2121
import org.elasticsearch.simdvec.internal.vectorization.ESVectorizationProvider;
2222
import org.openjdk.jmh.annotations.Benchmark;
2323
import org.openjdk.jmh.annotations.BenchmarkMode;

build-conventions/settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
plugins {
11-
id "com.gradle.develocity" version "3.19.2"
11+
id "com.gradle.develocity" version "4.0.1"
1212
}
1313

1414
rootProject.name = 'build-conventions'

build-tools-internal/settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pluginManagement {
99
}
1010

1111
plugins {
12-
id "com.gradle.develocity" version "3.19.2"
12+
id "com.gradle.develocity" version "4.0.1"
1313
}
1414

1515
dependencyResolutionManagement {

build-tools/settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pluginManagement {
1010
includeBuild "../build-conventions"
1111
}
1212
plugins {
13-
id "com.gradle.develocity" version "3.19.2"
13+
id "com.gradle.develocity" version "4.0.1"
1414
}
1515
include 'reaper'
1616

gradle/build.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ checkstyle = "com.puppycrawl.tools:checkstyle:10.3"
1616
commmons-io = "commons-io:commons-io:2.2"
1717
docker-compose = "com.avast.gradle:gradle-docker-compose-plugin:0.17.5"
1818
forbiddenApis = "de.thetaphi:forbiddenapis:3.8"
19-
gradle-enterprise = "com.gradle:develocity-gradle-plugin:3.19.2"
19+
gradle-enterprise = "com.gradle:develocity-gradle-plugin:4.0.1"
2020
hamcrest = "org.hamcrest:hamcrest:3.0"
2121
httpcore5 = "org.apache.httpcomponents.core5:httpcore5:5.3.3"
2222
httpclient5 = "org.apache.httpcomponents.client5:httpclient5:5.4.2"

gradle/verification-metadata.xml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -866,9 +866,11 @@
866866
<sha256 value="48234cd74e35d91a31a683820a35b5b6d11b55527f32a5b162c6757408b95d7a" origin="Generated by Gradle"/>
867867
</artifact>
868868
</component>
869-
<component group="com.gradle" name="develocity-gradle-plugin" version="3.19.2">
870-
<artifact name="develocity-gradle-plugin-3.19.2.jar">
871-
<sha256 value="fc611e8858a901619831ea1d9efd289db7fea28a0ca3d091abdd363365d9512b" origin="Generated by Gradle"/>
869+
<component group="com.gradle" name="develocity-gradle-plugin" version="4.0.1">
870+
<artifact name="develocity-gradle-plugin-4.0.1.jar">
871+
<sha256 value="fc611e8858a901619831ea1d9efd289db7fea28a0ca3d091abdd363365d9512b" origin="Generated by Gradle">
872+
<also-trust value="62a98a9df9fbf8c16772787aa5a0009cedcf45c366a0969274bc3b3644c1de25"/>
873+
</sha256>
872874
</artifact>
873875
</component>
874876
<component group="com.gradleup.shadow" name="shadow-gradle-plugin" version="8.3.5">
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* your election, the "Elastic License 2.0", the "GNU Affero General Public
77
* License v3.0 only", or the "Server Side Public License, v 1".
88
*/
9-
package org.elasticsearch.simdvec.internal.vectorization;
9+
package org.elasticsearch.simdvec;
1010

1111
import org.apache.lucene.index.VectorSimilarityFunction;
1212
import org.apache.lucene.store.IndexInput;

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99

1010
package org.elasticsearch.simdvec;
1111

12+
import org.apache.lucene.store.IndexInput;
1213
import org.apache.lucene.util.BitUtil;
1314
import org.apache.lucene.util.Constants;
1415
import org.elasticsearch.simdvec.internal.vectorization.ESVectorUtilSupport;
1516
import org.elasticsearch.simdvec.internal.vectorization.ESVectorizationProvider;
1617

18+
import java.io.IOException;
1719
import java.lang.invoke.MethodHandle;
1820
import java.lang.invoke.MethodHandles;
1921
import java.lang.invoke.MethodType;
@@ -41,6 +43,10 @@ public class ESVectorUtil {
4143

4244
private static final ESVectorUtilSupport IMPL = ESVectorizationProvider.getInstance().getVectorUtilSupport();
4345

46+
public static ES91OSQVectorsScorer getES91OSQVectorsScorer(IndexInput input, int dimension) throws IOException {
47+
return ESVectorizationProvider.getInstance().newES91OSQVectorsScorer(input, dimension);
48+
}
49+
4450
public static long ipByteBinByte(byte[] q, byte[] d) {
4551
if (q.length != d.length * B_QUERY) {
4652
throw new IllegalArgumentException("vector dimensions incompatible: " + q.length + "!= " + B_QUERY + " x " + d.length);
@@ -211,4 +217,40 @@ public static void centerAndCalculateOSQStatsDp(float[] target, float[] centroid
211217
assert stats.length == 6;
212218
IMPL.centerAndCalculateOSQStatsDp(target, centroid, centered, stats);
213219
}
220+
221+
/**
222+
* Calculates the difference between two vectors and stores the result in a third vector.
223+
* @param v1 the first vector
224+
* @param v2 the second vector
225+
* @param result the result vector, must be the same length as the input vectors
226+
*/
227+
public static void subtract(float[] v1, float[] v2, float[] result) {
228+
if (v1.length != v2.length) {
229+
throw new IllegalArgumentException("vector dimensions differ: " + v1.length + "!=" + v2.length);
230+
}
231+
if (result.length != v1.length) {
232+
throw new IllegalArgumentException("vector dimensions differ: " + result.length + "!=" + v1.length);
233+
}
234+
for (int i = 0; i < v1.length; i++) {
235+
result[i] = v1[i] - v2[i];
236+
}
237+
}
238+
239+
/**
240+
* calculates the spill-over score for a vector and a centroid, given its residual with
241+
* its actually nearest centroid
242+
* @param v1 the vector
243+
* @param centroid the centroid
244+
* @param originalResidual the residual with the actually nearest centroid
245+
* @return the spill-over score (soar)
246+
*/
247+
public static float soarResidual(float[] v1, float[] centroid, float[] originalResidual) {
248+
if (v1.length != centroid.length) {
249+
throw new IllegalArgumentException("vector dimensions differ: " + v1.length + "!=" + centroid.length);
250+
}
251+
if (originalResidual.length != v1.length) {
252+
throw new IllegalArgumentException("vector dimensions differ: " + originalResidual.length + "!=" + v1.length);
253+
}
254+
return IMPL.soarResidual(v1, centroid, originalResidual);
255+
}
214256
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,18 @@ public void centerAndCalculateOSQStatsDp(float[] target, float[] centroid, float
138138
stats[5] = centroidDot;
139139
}
140140

141+
@Override
142+
public float soarResidual(float[] v1, float[] centroid, float[] originalResidual) {
143+
assert v1.length == centroid.length;
144+
assert v1.length == originalResidual.length;
145+
float proj = 0;
146+
for (int i = 0; i < v1.length; i++) {
147+
float djk = v1[i] - centroid[i];
148+
proj = fma(djk, originalResidual[i], proj);
149+
}
150+
return proj;
151+
}
152+
141153
public static int ipByteBitImpl(byte[] q, byte[] d) {
142154
return ipByteBitImpl(q, d, 0);
143155
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
package org.elasticsearch.simdvec.internal.vectorization;
1111

1212
import org.apache.lucene.store.IndexInput;
13+
import org.elasticsearch.simdvec.ES91OSQVectorsScorer;
1314

1415
import java.io.IOException;
1516

0 commit comments

Comments
 (0)