Skip to content

Commit 7e16d12

Browse files
committed
Merge remote-tracking branch 'elastic/main' into support-ordinals-values-aggs
2 parents 9c98de6 + de1351d commit 7e16d12

File tree

34 files changed

+2648
-128
lines changed

34 files changed

+2648
-128
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;

docs/changelog/127856.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 127856
2+
summary: Fix services API Google Vertex AI Rerank location field requirement
3+
area: Machine Learning
4+
type: bug
5+
issues: []

docs/reference/elasticsearch/mapping-reference/keyword.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ Will become:
264264

265265
```console-result
266266
{
267-
"kwd": ["bar", "foo", "NA"]
267+
"kwd": ["NA", "bar", "foo"]
268268
}
269269
```
270270

docs/reference/elasticsearch/mapping-reference/text.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ Will become:
158158
```console-result
159159
{
160160
"text": [
161-
"jumped over the lazy dog",
162161
"NA",
162+
"jumped over the lazy dog",
163163
"the quick brown fox"
164164
]
165165
}
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

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,7 @@ public interface ESVectorUtilSupport {
2828
void centerAndCalculateOSQStatsEuclidean(float[] target, float[] centroid, float[] centered, float[] stats);
2929

3030
void centerAndCalculateOSQStatsDp(float[] target, float[] centroid, float[] centered, float[] stats);
31+
32+
float soarResidual(float[] v1, float[] centroid, float[] originalResidual);
33+
3134
}

libs/simdvec/src/main/java/org/elasticsearch/simdvec/internal/vectorization/ESVectorizationProvider.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
import java.util.Objects;

0 commit comments

Comments
 (0)