Skip to content

Commit 9b3dac4

Browse files
authored
Merge branch 'main' into ps250227-capDeletionSuppressedErrors
2 parents 6662a8b + 2fcb23a commit 9b3dac4

File tree

39 files changed

+460
-267
lines changed

39 files changed

+460
-267
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.elasticsearch.common.settings.Settings;
1313
import org.elasticsearch.common.util.concurrent.EsExecutors;
1414
import org.elasticsearch.core.Booleans;
15-
import org.elasticsearch.core.UpdateForV9;
1615
import org.elasticsearch.jdk.RuntimeVersionFeature;
1716

1817
import java.io.IOException;
@@ -150,7 +149,6 @@ private static Stream<String> maybeWorkaroundG1Bug() {
150149
return Stream.of();
151150
}
152151

153-
@UpdateForV9(owner = UpdateForV9.Owner.CORE_INFRA)
154152
private static Stream<String> maybeAllowSecurityManager(boolean useEntitlements) {
155153
if (RuntimeVersionFeature.isSecurityManagerAvailable()) {
156154
// Will become conditional on useEntitlements once entitlements can run without SM

docs/changelog/122381.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 122381
2+
summary: Adds implementations of dotProduct and cosineSimilarity painless methods to operate on float vectors for byte fields
3+
area: Vector Search
4+
type: enhancement
5+
issues:
6+
- 117274

libs/core/src/main/java/org/elasticsearch/jdk/RuntimeVersionFeature.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@
99

1010
package org.elasticsearch.jdk;
1111

12-
import org.elasticsearch.core.UpdateForV9;
13-
1412
public class RuntimeVersionFeature {
1513
private RuntimeVersionFeature() {}
1614

17-
@UpdateForV9(owner = UpdateForV9.Owner.CORE_INFRA) // Remove once we removed all references to SecurityManager in code
1815
public static boolean isSecurityManagerAvailable() {
1916
return Runtime.version().feature() < 24;
2017
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,19 @@ public static float ipFloatBit(float[] q, byte[] d) {
8080
return IMPL.ipFloatBit(q, d);
8181
}
8282

83+
/**
84+
* Compute the inner product of two vectors, where the query vector is a float vector and the document vector is a byte vector.
85+
* @param q the query vector
86+
* @param d the document vector
87+
* @return the inner product of the two vectors
88+
*/
89+
public static float ipFloatByte(float[] q, byte[] d) {
90+
if (q.length != d.length) {
91+
throw new IllegalArgumentException("vector dimensions incompatible: " + q.length + "!= " + d.length);
92+
}
93+
return IMPL.ipFloatByte(q, d);
94+
}
95+
8396
/**
8497
* AND bit count computed over signed bytes.
8598
* Copied from Lucene's XOR implementation

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ public float ipFloatBit(float[] q, byte[] d) {
3939
return ipFloatBitImpl(q, d);
4040
}
4141

42+
@Override
43+
public float ipFloatByte(float[] q, byte[] d) {
44+
return ipFloatByteImpl(q, d);
45+
}
46+
4247
public static int ipByteBitImpl(byte[] q, byte[] d) {
4348
assert q.length == d.length * Byte.SIZE;
4449
int acc0 = 0;
@@ -101,4 +106,12 @@ public static long ipByteBinByteImpl(byte[] q, byte[] d) {
101106
}
102107
return ret;
103108
}
109+
110+
public static float ipFloatByteImpl(float[] q, byte[] d) {
111+
float ret = 0;
112+
for (int i = 0; i < q.length; i++) {
113+
ret += q[i] * d[i];
114+
}
115+
return ret;
116+
}
104117
}

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
@@ -18,4 +18,6 @@ public interface ESVectorUtilSupport {
1818
int ipByteBit(byte[] q, byte[] d);
1919

2020
float ipFloatBit(float[] q, byte[] d);
21+
22+
float ipFloatByte(float[] q, byte[] d);
2123
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ public float ipFloatBit(float[] q, byte[] d) {
5858
return DefaultESVectorUtilSupport.ipFloatBitImpl(q, d);
5959
}
6060

61+
@Override
62+
public float ipFloatByte(float[] q, byte[] d) {
63+
return DefaultESVectorUtilSupport.ipFloatByteImpl(q, d);
64+
}
65+
6166
private static final VectorSpecies<Byte> BYTE_SPECIES_128 = ByteVector.SPECIES_128;
6267
private static final VectorSpecies<Byte> BYTE_SPECIES_256 = ByteVector.SPECIES_256;
6368

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,28 @@ public void testIpByteBit() {
3232
public void testIpFloatBit() {
3333
float[] q = new float[16];
3434
byte[] d = new byte[] { (byte) Integer.parseInt("01100010", 2), (byte) Integer.parseInt("10100111", 2) };
35-
random().nextFloat();
35+
for (int i = 0; i < q.length; i++) {
36+
q[i] = random().nextFloat();
37+
}
3638
float expected = q[1] + q[2] + q[6] + q[8] + q[10] + q[13] + q[14] + q[15];
3739
assertEquals(expected, ESVectorUtil.ipFloatBit(q, d), 1e-6);
3840
}
3941

42+
public void testIpFloatByte() {
43+
float[] q = new float[16];
44+
byte[] d = new byte[16];
45+
for (int i = 0; i < q.length; i++) {
46+
q[i] = random().nextFloat();
47+
}
48+
random().nextBytes(d);
49+
50+
float expected = 0;
51+
for (int i = 0; i < q.length; i++) {
52+
expected += q[i] * d[i];
53+
}
54+
assertEquals(expected, ESVectorUtil.ipFloatByte(q, d), 1e-6);
55+
}
56+
4057
public void testBitAndCount() {
4158
testBasicBitAndImpl(ESVectorUtil::andBitCountLong);
4259
}

modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/GeoIpDownloaderTaskExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ private void stopTask(Runnable onFailure) {
398398
ActionListener.runAfter(listener, () -> {
399399
IndexAbstraction databasesAbstraction = clusterService.state()
400400
.metadata()
401-
.getProject()
401+
.getDefaultProject()
402402
.getIndicesLookup()
403403
.get(DATABASES_INDEX);
404404
if (databasesAbstraction != null) {

modules/lang-painless/src/yamlRestTest/resources/rest-api-spec/test/painless/145_dense_vector_byte_basic.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,38 @@ setup:
107107
- match: {hits.hits.2._id: "1"}
108108
- match: {hits.hits.2._score: 1632.0}
109109
---
110+
"Dot Product float":
111+
- requires:
112+
capabilities:
113+
- path: /_search
114+
capabilities: [byte_float_dot_product_capability]
115+
test_runner_features: [capabilities]
116+
reason: "float vector queries capability added"
117+
- do:
118+
headers:
119+
Content-Type: application/json
120+
search:
121+
rest_total_hits_as_int: true
122+
body:
123+
query:
124+
script_score:
125+
query: {match_all: {} }
126+
script:
127+
source: "dotProduct(params.query_vector, 'vector')"
128+
params:
129+
query_vector: [0.5, 111.3, -13.0, 14.8, -156.0]
130+
131+
- match: {hits.total: 3}
132+
133+
- match: {hits.hits.0._id: "2"}
134+
- match: {hits.hits.0._score: 32865.2}
135+
136+
- match: {hits.hits.1._id: "3"}
137+
- match: {hits.hits.1._score: 21413.4}
138+
139+
- match: {hits.hits.2._id: "1"}
140+
- match: {hits.hits.2._score: 1862.3}
141+
---
110142
"Cosine Similarity":
111143
- do:
112144
headers:
@@ -198,3 +230,39 @@ setup:
198230
- match: {hits.hits.2._id: "1"}
199231
- gte: {hits.hits.2._score: 0.509}
200232
- lte: {hits.hits.2._score: 0.512}
233+
234+
---
235+
"Cosine Similarity float":
236+
- requires:
237+
capabilities:
238+
- path: /_search
239+
capabilities: [byte_float_dot_product_capability]
240+
test_runner_features: [capabilities]
241+
reason: "float vector queries capability added"
242+
- do:
243+
headers:
244+
Content-Type: application/json
245+
search:
246+
rest_total_hits_as_int: true
247+
body:
248+
query:
249+
script_score:
250+
query: {match_all: {} }
251+
script:
252+
source: "cosineSimilarity(params.query_vector, 'vector')"
253+
params:
254+
query_vector: [0.5, 111.3, -13.0, 14.8, -156.0]
255+
256+
- match: {hits.total: 3}
257+
258+
- match: {hits.hits.0._id: "2"}
259+
- gte: {hits.hits.0._score: 0.989}
260+
- lte: {hits.hits.0._score: 0.992}
261+
262+
- match: {hits.hits.1._id: "3"}
263+
- gte: {hits.hits.1._score: 0.885}
264+
- lte: {hits.hits.1._score: 0.888}
265+
266+
- match: {hits.hits.2._id: "1"}
267+
- gte: {hits.hits.2._score: 0.505}
268+
- lte: {hits.hits.2._score: 0.508}

0 commit comments

Comments
 (0)