Skip to content

Commit 408d865

Browse files
committed
Merge remote-tracking branch 'upstream/main' into counted_keyword_multi_subobject_fix
2 parents f05efa5 + cc6e84e commit 408d865

File tree

30 files changed

+715
-149
lines changed

30 files changed

+715
-149
lines changed

.buildkite/pipelines/periodic.template.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ steps:
8686
ES_RUNTIME_JAVA:
8787
- openjdk21
8888
- openjdk23
89+
- openjdk24
8990
GRADLE_TASK:
9091
- checkPart1
9192
- checkPart2

.buildkite/pipelines/periodic.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ steps:
505505
ES_RUNTIME_JAVA:
506506
- openjdk21
507507
- openjdk23
508+
- openjdk24
508509
GRADLE_TASK:
509510
- checkPart1
510511
- checkPart2

docs/changelog/120751.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 120751
2+
summary: Adding support for binary embedding type to Cohere service embedding type
3+
area: Machine Learning
4+
type: enhancement
5+
issues: []

libs/entitlement/qa/entitlement-test-plugin/src/main/java/org/elasticsearch/entitlement/qa/test/DummyImplementations.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@
5252
* <p>
5353
* A bit like Mockito but way more painful.
5454
*/
55-
public class DummyImplementations {
55+
class DummyImplementations {
56+
57+
static class DummyLocaleServiceProvider extends LocaleServiceProvider {
5658

57-
public static class DummyLocaleServiceProvider extends LocaleServiceProvider {
5859
@Override
5960
public Locale[] getAvailableLocales() {
6061
throw unexpected();

libs/entitlement/qa/entitlement-test-plugin/src/main/java/org/elasticsearch/entitlement/qa/test/RestEntitlementsCheckAction.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,6 @@ static CheckAction alwaysDenied(CheckedRunnable<Exception> action) {
9696

9797
private static final Map<String, CheckAction> checkActions = Stream.concat(
9898
Stream.<Entry<String, CheckAction>>of(
99-
entry("static_reflection", deniedToPlugins(RestEntitlementsCheckAction::staticMethodNeverEntitledViaReflection)),
100-
entry("nonstatic_reflection", deniedToPlugins(RestEntitlementsCheckAction::nonstaticMethodNeverEntitledViaReflection)),
101-
entry("constructor_reflection", deniedToPlugins(RestEntitlementsCheckAction::constructorNeverEntitledViaReflection)),
10299
entry("runtime_exit", deniedToPlugins(RestEntitlementsCheckAction::runtimeExit)),
103100
entry("runtime_halt", deniedToPlugins(RestEntitlementsCheckAction::runtimeHalt)),
104101
entry("system_exit", deniedToPlugins(RestEntitlementsCheckAction::systemExit)),
@@ -341,11 +338,6 @@ private static void systemExit() {
341338
System.exit(123);
342339
}
343340

344-
private static void staticMethodNeverEntitledViaReflection() throws Exception {
345-
Method systemExit = System.class.getMethod("exit", int.class);
346-
systemExit.invoke(null, 123);
347-
}
348-
349341
private static void createClassLoader() throws IOException {
350342
try (var classLoader = new URLClassLoader("test", new URL[0], RestEntitlementsCheckAction.class.getClassLoader())) {
351343
logger.info("Created URLClassLoader [{}]", classLoader.getName());
@@ -356,11 +348,6 @@ private static void processBuilder_start() throws IOException {
356348
new ProcessBuilder("").start();
357349
}
358350

359-
private static void nonstaticMethodNeverEntitledViaReflection() throws Exception {
360-
Method processBuilderStart = ProcessBuilder.class.getMethod("start");
361-
processBuilderStart.invoke(new ProcessBuilder(""));
362-
}
363-
364351
private static void processBuilder_startPipeline() throws IOException {
365352
ProcessBuilder.startPipeline(List.of());
366353
}
@@ -399,10 +386,6 @@ private static void setHttpsConnectionProperties() {
399386
new DummyLocaleServiceProvider();
400387
}
401388

402-
private static void constructorNeverEntitledViaReflection() throws Exception {
403-
DummyLocaleServiceProvider.class.getConstructor().newInstance();
404-
}
405-
406389
private static void breakIteratorProvider$() {
407390
new DummyBreakIteratorProvider();
408391
}

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ tests:
4646
- class: org.elasticsearch.packaging.test.WindowsServiceTests
4747
method: test81JavaOptsInJvmOptions
4848
issue: https://github.com/elastic/elasticsearch/issues/113313
49-
- class: org.elasticsearch.backwards.MixedClusterClientYamlTestSuiteIT
50-
method: test {p0=mtermvectors/10_basic/Tests catching other exceptions per item}
51-
issue: https://github.com/elastic/elasticsearch/issues/113325
5249
- class: org.elasticsearch.xpack.transform.integration.TransformIT
5350
method: testStopWaitForCheckpoint
5451
issue: https://github.com/elastic/elasticsearch/issues/106113

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/mtermvectors/10_basic.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ setup:
33
- do:
44
indices.create:
55
index: testidx
6+
wait_for_active_shards: all
67
body:
78
mappings:
89
properties:
@@ -80,6 +81,7 @@ setup:
8081
- do:
8182
indices.create:
8283
index: testidx2
84+
wait_for_active_shards: all
8385

8486
- do:
8587
indices.put_alias:

server/src/main/java/org/elasticsearch/TransportVersions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ static TransportVersion def(int id) {
173173
public static final TransportVersion INFERENCE_REQUEST_ADAPTIVE_RATE_LIMITING = def(8_839_0_00);
174174
public static final TransportVersion ML_INFERENCE_IBM_WATSONX_RERANK_ADDED = def(8_840_0_00);
175175
public static final TransportVersion ELASTICSEARCH_9_0 = def(9_000_0_00);
176-
176+
public static final TransportVersion COHERE_BIT_EMBEDDING_TYPE_SUPPORT_ADDED = def(9_001_0_00);
177177
/*
178178
* STOP! READ THIS FIRST! No, really,
179179
* ____ _____ ___ ____ _ ____ _____ _ ____ _____ _ _ ___ ____ _____ ___ ____ ____ _____ _
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*
7+
* this file was contributed to by a generative AI
8+
*/
9+
10+
package org.elasticsearch.xpack.core.inference.results;
11+
12+
import org.elasticsearch.common.Strings;
13+
import org.elasticsearch.common.io.stream.StreamInput;
14+
import org.elasticsearch.common.io.stream.StreamOutput;
15+
import org.elasticsearch.common.io.stream.Writeable;
16+
import org.elasticsearch.xcontent.ToXContentObject;
17+
import org.elasticsearch.xcontent.XContentBuilder;
18+
19+
import java.io.IOException;
20+
import java.util.Arrays;
21+
import java.util.List;
22+
23+
public record InferenceByteEmbedding(byte[] values) implements Writeable, ToXContentObject, EmbeddingInt {
24+
public static final String EMBEDDING = "embedding";
25+
26+
public InferenceByteEmbedding(StreamInput in) throws IOException {
27+
this(in.readByteArray());
28+
}
29+
30+
@Override
31+
public void writeTo(StreamOutput out) throws IOException {
32+
out.writeByteArray(values);
33+
}
34+
35+
public static InferenceByteEmbedding of(List<Byte> embeddingValuesList) {
36+
byte[] embeddingValues = new byte[embeddingValuesList.size()];
37+
for (int i = 0; i < embeddingValuesList.size(); i++) {
38+
embeddingValues[i] = embeddingValuesList.get(i);
39+
}
40+
return new InferenceByteEmbedding(embeddingValues);
41+
}
42+
43+
@Override
44+
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
45+
builder.startObject();
46+
47+
builder.startArray(EMBEDDING);
48+
for (byte value : values) {
49+
builder.value(value);
50+
}
51+
builder.endArray();
52+
53+
builder.endObject();
54+
return builder;
55+
}
56+
57+
@Override
58+
public String toString() {
59+
return Strings.toString(this);
60+
}
61+
62+
float[] toFloatArray() {
63+
float[] floatArray = new float[values.length];
64+
for (int i = 0; i < values.length; i++) {
65+
floatArray[i] = ((Byte) values[i]).floatValue();
66+
}
67+
return floatArray;
68+
}
69+
70+
double[] toDoubleArray() {
71+
double[] doubleArray = new double[values.length];
72+
for (int i = 0; i < values.length; i++) {
73+
doubleArray[i] = ((Byte) values[i]).doubleValue();
74+
}
75+
return doubleArray;
76+
}
77+
78+
@Override
79+
public int getSize() {
80+
return values().length;
81+
}
82+
83+
@Override
84+
public boolean equals(Object o) {
85+
if (this == o) return true;
86+
if (o == null || getClass() != o.getClass()) return false;
87+
InferenceByteEmbedding embedding = (InferenceByteEmbedding) o;
88+
return Arrays.equals(values, embedding.values);
89+
}
90+
91+
@Override
92+
public int hashCode() {
93+
return Arrays.hashCode(values);
94+
}
95+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*
7+
* this file was contributed to by a generative AI
8+
*/
9+
10+
package org.elasticsearch.xpack.core.inference.results;
11+
12+
import org.elasticsearch.common.io.stream.StreamInput;
13+
import org.elasticsearch.common.io.stream.StreamOutput;
14+
import org.elasticsearch.common.xcontent.ChunkedToXContentHelper;
15+
import org.elasticsearch.inference.InferenceResults;
16+
import org.elasticsearch.inference.InferenceServiceResults;
17+
import org.elasticsearch.xcontent.ToXContent;
18+
import org.elasticsearch.xpack.core.ml.inference.results.MlTextEmbeddingResults;
19+
20+
import java.io.IOException;
21+
import java.util.ArrayList;
22+
import java.util.Iterator;
23+
import java.util.LinkedHashMap;
24+
import java.util.List;
25+
import java.util.Map;
26+
import java.util.Objects;
27+
28+
/**
29+
* Writes a text embedding result in the follow json format
30+
* {
31+
* "text_embedding_bytes": [
32+
* {
33+
* "embedding": [
34+
* 23
35+
* ]
36+
* },
37+
* {
38+
* "embedding": [
39+
* -23
40+
* ]
41+
* }
42+
* ]
43+
* }
44+
*/
45+
public record InferenceTextEmbeddingBitResults(List<InferenceByteEmbedding> embeddings) implements InferenceServiceResults, TextEmbedding {
46+
public static final String NAME = "text_embedding_service_bit_results";
47+
public static final String TEXT_EMBEDDING_BITS = "text_embedding_bits";
48+
49+
public InferenceTextEmbeddingBitResults(StreamInput in) throws IOException {
50+
this(in.readCollectionAsList(InferenceByteEmbedding::new));
51+
}
52+
53+
@Override
54+
public int getFirstEmbeddingSize() {
55+
return TextEmbeddingUtils.getFirstEmbeddingSize(new ArrayList<>(embeddings));
56+
}
57+
58+
@Override
59+
public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params params) {
60+
return ChunkedToXContentHelper.array(TEXT_EMBEDDING_BITS, embeddings.iterator());
61+
}
62+
63+
@Override
64+
public void writeTo(StreamOutput out) throws IOException {
65+
out.writeCollection(embeddings);
66+
}
67+
68+
@Override
69+
public String getWriteableName() {
70+
return NAME;
71+
}
72+
73+
@Override
74+
public List<? extends InferenceResults> transformToCoordinationFormat() {
75+
return embeddings.stream()
76+
.map(embedding -> new MlTextEmbeddingResults(TEXT_EMBEDDING_BITS, embedding.toDoubleArray(), false))
77+
.toList();
78+
}
79+
80+
@Override
81+
@SuppressWarnings("deprecation")
82+
public List<? extends InferenceResults> transformToLegacyFormat() {
83+
var legacyEmbedding = new LegacyTextEmbeddingResults(
84+
embeddings.stream().map(embedding -> new LegacyTextEmbeddingResults.Embedding(embedding.toFloatArray())).toList()
85+
);
86+
87+
return List.of(legacyEmbedding);
88+
}
89+
90+
public Map<String, Object> asMap() {
91+
Map<String, Object> map = new LinkedHashMap<>();
92+
map.put(TEXT_EMBEDDING_BITS, embeddings);
93+
94+
return map;
95+
}
96+
97+
@Override
98+
public boolean equals(Object o) {
99+
if (this == o) return true;
100+
if (o == null || getClass() != o.getClass()) return false;
101+
InferenceTextEmbeddingBitResults that = (InferenceTextEmbeddingBitResults) o;
102+
return Objects.equals(embeddings, that.embeddings);
103+
}
104+
105+
@Override
106+
public int hashCode() {
107+
return Objects.hash(embeddings);
108+
}
109+
}

0 commit comments

Comments
 (0)