Skip to content

Commit ff352fb

Browse files
DonalEvanschrisparrinello
authored andcommitted
Fix mutateInstance() imlementations in inference module (elastic#137138)
Closes elastic#134166
1 parent 0bdc26e commit ff352fb

File tree

83 files changed

+1072
-222
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+1072
-222
lines changed

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/custom/CustomServiceSettings.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,10 @@ public Integer getMaxInputTokens() {
339339
return textEmbeddingSettings.maxInputTokens;
340340
}
341341

342+
TextEmbeddingSettings getTextEmbeddingSettings() {
343+
return textEmbeddingSettings;
344+
}
345+
342346
public String getUrl() {
343347
return url;
344348
}

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/custom/response/CompletionResponseParser.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
7070
return builder;
7171
}
7272

73+
String getCompletionResultPath() {
74+
return completionResultPath;
75+
}
76+
7377
@Override
7478
public boolean equals(Object o) {
7579
if (this == o) return true;

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/custom/response/RerankResponseParser.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,18 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
9393
return builder;
9494
}
9595

96+
String getRelevanceScorePath() {
97+
return relevanceScorePath;
98+
}
99+
100+
String getRerankIndexPath() {
101+
return rerankIndexPath;
102+
}
103+
104+
String getDocumentTextPath() {
105+
return documentTextPath;
106+
}
107+
96108
@Override
97109
public boolean equals(Object o) {
98110
if (this == o) return true;

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/custom/response/SparseEmbeddingResponseParser.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
7777
return builder;
7878
}
7979

80+
String getTokenPath() {
81+
return tokenPath;
82+
}
83+
84+
String getWeightPath() {
85+
return weightPath;
86+
}
87+
8088
@Override
8189
public boolean equals(Object o) {
8290
if (this == o) return true;

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elasticsearch/CustomElandInternalTextEmbeddingServiceSettings.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ private static CommonFields commonFieldsFromMap(Map<String, Object> map, Validat
106106
private final DenseVectorFieldMapper.ElementType elementType;
107107

108108
CustomElandInternalTextEmbeddingServiceSettings(
109-
Integer numAllocations,
109+
@Nullable Integer numAllocations,
110110
int numThreads,
111111
String modelId,
112-
AdaptiveAllocationsSettings adaptiveAllocationsSettings,
112+
@Nullable AdaptiveAllocationsSettings adaptiveAllocationsSettings,
113113
@Nullable String deploymentId,
114-
Integer dimensions,
114+
@Nullable Integer dimensions,
115115
SimilarityMeasure similarityMeasure,
116116
DenseVectorFieldMapper.ElementType elementType
117117
) {

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elasticsearch/ElasticsearchInternalServiceSettings.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ protected static ElasticsearchInternalServiceSettings.Builder fromMap(
112112
}
113113

114114
public ElasticsearchInternalServiceSettings(
115-
Integer numAllocations,
115+
@Nullable Integer numAllocations,
116116
int numThreads,
117117
String modelId,
118-
AdaptiveAllocationsSettings adaptiveAllocationsSettings,
118+
@Nullable AdaptiveAllocationsSettings adaptiveAllocationsSettings,
119119
@Nullable String deploymentId
120120
) {
121121
this.numAllocations = numAllocations;

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/ModelSecretsTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected ModelSecrets createTestInstance() {
5151

5252
@Override
5353
protected ModelSecrets mutateInstance(ModelSecrets instance) {
54-
return randomValueOtherThan(instance, ModelSecretsTests::createRandomInstance);
54+
return new ModelSecrets(randomValueOtherThan(instance.getSecretSettings(), ModelSecretsTests::randomSecretSettings));
5555
}
5656

5757
public record FakeSecretSettings(String apiKey) implements SecretSettings {

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/action/GetRerankerWindowSizeActionRequestTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ protected GetRerankerWindowSizeAction.Request createTestInstance() {
2626

2727
@Override
2828
protected GetRerankerWindowSizeAction.Request mutateInstance(GetRerankerWindowSizeAction.Request instance) throws IOException {
29-
return randomValueOtherThan(instance, this::createTestInstance);
29+
return new GetRerankerWindowSizeAction.Request(randomValueOtherThan(instance.getInferenceEntityId(), () -> randomAlphaOfLength(8)));
3030
}
3131
}

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/action/GetRerankerWindowSizeActionResponseTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import org.elasticsearch.common.io.stream.Writeable;
1111
import org.elasticsearch.test.AbstractWireSerializingTestCase;
12+
import org.elasticsearch.test.ESTestCase;
1213
import org.elasticsearch.xpack.core.inference.action.GetRerankerWindowSizeAction;
1314

1415
import java.io.IOException;
@@ -26,6 +27,6 @@ protected GetRerankerWindowSizeAction.Response createTestInstance() {
2627

2728
@Override
2829
protected GetRerankerWindowSizeAction.Response mutateInstance(GetRerankerWindowSizeAction.Response instance) throws IOException {
29-
return randomValueOtherThan(instance, this::createTestInstance);
30+
return new GetRerankerWindowSizeAction.Response(randomValueOtherThan(instance.getWindowSize(), ESTestCase::randomNonNegativeInt));
3031
}
3132
}

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/action/InferenceActionResponseTests.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.elasticsearch.TransportVersion;
1111
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
1212
import org.elasticsearch.common.io.stream.Writeable;
13+
import org.elasticsearch.inference.InferenceServiceResults;
1314
import org.elasticsearch.xpack.core.inference.action.InferenceAction;
1415
import org.elasticsearch.xpack.core.inference.results.DenseEmbeddingFloatResultsTests;
1516
import org.elasticsearch.xpack.core.inference.results.SparseEmbeddingResultsTests;
@@ -38,16 +39,18 @@ protected Writeable.Reader<InferenceAction.Response> instanceReader() {
3839

3940
@Override
4041
protected InferenceAction.Response createTestInstance() {
41-
var result = randomBoolean()
42-
? DenseEmbeddingFloatResultsTests.createRandomResults()
43-
: SparseEmbeddingResultsTests.createRandomResults();
42+
return new InferenceAction.Response(getRandomResults());
43+
}
4444

45-
return new InferenceAction.Response(result);
45+
private InferenceServiceResults getRandomResults() {
46+
return randomBoolean() ? DenseEmbeddingFloatResultsTests.createRandomResults() : SparseEmbeddingResultsTests.createRandomResults();
4647
}
4748

4849
@Override
4950
protected InferenceAction.Response mutateInstance(InferenceAction.Response instance) throws IOException {
50-
return randomValueOtherThan(instance, this::createTestInstance);
51+
var originalResults = instance.getResults();
52+
53+
return new InferenceAction.Response(randomValueOtherThan(originalResults, this::getRandomResults));
5154
}
5255

5356
@Override

0 commit comments

Comments
 (0)