Skip to content

Commit fc933d4

Browse files
authored
[ML] Remove InferenceServiceResults#transformToLegacyFormat (#125924)
1 parent 610ba23 commit fc933d4

File tree

11 files changed

+2
-137
lines changed

11 files changed

+2
-137
lines changed

server/src/main/java/org/elasticsearch/inference/InferenceServiceResults.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,12 @@ public interface InferenceServiceResults extends NamedWriteable, ChunkedToXConte
2424

2525
/**
2626
* <p>Transform the result to match the format required for the TransportCoordinatedInferenceAction.
27-
* For the inference plugin TextEmbeddingResults, the {@link #transformToLegacyFormat()} transforms the
28-
* results into an intermediate format only used by the plugin's return value. It doesn't align with what the
29-
* TransportCoordinatedInferenceAction expects. TransportCoordinatedInferenceAction expects an ml plugin
30-
* TextEmbeddingResults.</p>
31-
*
32-
* <p>For other results like SparseEmbeddingResults, this method can be a pass through to the transformToLegacyFormat.</p>
27+
* TransportCoordinatedInferenceAction expects an ml plugin TextEmbeddingResults or SparseEmbeddingResults.</p>
3328
*/
3429
default List<? extends InferenceResults> transformToCoordinationFormat() {
3530
throw new UnsupportedOperationException("transformToCoordinationFormat() is not implemented");
3631
}
3732

38-
/**
39-
* Transform the result to match the format required for versions prior to
40-
* {@link org.elasticsearch.TransportVersions#V_8_12_0}
41-
*/
42-
default List<? extends InferenceResults> transformToLegacyFormat() {
43-
throw new UnsupportedOperationException("transformToLegacyFormat() is not implemented");
44-
}
45-
4633
/**
4734
* Convert the result to a map to aid with test assertions
4835
*/

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/inference/action/InferenceAction.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -580,12 +580,8 @@ public Flow.Publisher<InferenceServiceResults.Result> publisher() {
580580

581581
@Override
582582
public void writeTo(StreamOutput out) throws IOException {
583-
if (out.getTransportVersion().onOrAfter(TransportVersions.V_8_12_0)) {
584-
out.writeNamedWriteable(results);
585-
} else {
586-
out.writeNamedWriteable(results.transformToLegacyFormat().get(0));
587-
}
588583
// streaming isn't supported via Writeable yet
584+
out.writeNamedWriteable(results);
589585
}
590586

591587
@Override

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/inference/results/ChatCompletionResults.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,6 @@ public List<? extends InferenceResults> transformToCoordinationFormat() {
6868
return results;
6969
}
7070

71-
@Override
72-
public List<? extends InferenceResults> transformToLegacyFormat() {
73-
throw new UnsupportedOperationException();
74-
}
75-
7671
public List<Result> getResults() {
7772
return results;
7873
}

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/inference/results/RankedDocsResults.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,6 @@ public List<? extends InferenceResults> transformToCoordinationFormat() {
196196
throw new UnsupportedOperationException("Coordination format not supported by " + NAME);
197197
}
198198

199-
@Override
200-
public List<? extends InferenceResults> transformToLegacyFormat() {
201-
throw new UnsupportedOperationException("Legacy format not supported by " + NAME);
202-
}
203-
204199
@Override
205200
public Map<String, Object> asMap() {
206201
Map<String, Object> map = new LinkedHashMap<>();

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/inference/results/SparseEmbeddingResults.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,6 @@ public Map<String, Object> asMap() {
100100

101101
@Override
102102
public List<? extends InferenceResults> transformToCoordinationFormat() {
103-
return transformToLegacyFormat();
104-
}
105-
106-
@Override
107-
public List<? extends InferenceResults> transformToLegacyFormat() {
108103
return embeddings.stream()
109104
.map(
110105
embedding -> new TextExpansionResults(

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/inference/results/TextEmbeddingBitResults.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,6 @@ public List<? extends InferenceResults> transformToCoordinationFormat() {
8383
.toList();
8484
}
8585

86-
@Override
87-
@SuppressWarnings("deprecation")
88-
public List<? extends InferenceResults> transformToLegacyFormat() {
89-
var legacyEmbedding = new LegacyTextEmbeddingResults(
90-
embeddings.stream().map(embedding -> new LegacyTextEmbeddingResults.Embedding(embedding.toFloatArray())).toList()
91-
);
92-
93-
return List.of(legacyEmbedding);
94-
}
95-
9686
public Map<String, Object> asMap() {
9787
Map<String, Object> map = new LinkedHashMap<>();
9888
map.put(TEXT_EMBEDDING_BITS, embeddings);

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/inference/results/TextEmbeddingByteResults.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,6 @@ public List<? extends InferenceResults> transformToCoordinationFormat() {
8585
.toList();
8686
}
8787

88-
@Override
89-
@SuppressWarnings("deprecation")
90-
public List<? extends InferenceResults> transformToLegacyFormat() {
91-
var legacyEmbedding = new LegacyTextEmbeddingResults(
92-
embeddings.stream().map(embedding -> new LegacyTextEmbeddingResults.Embedding(embedding.toFloatArray())).toList()
93-
);
94-
95-
return List.of(legacyEmbedding);
96-
}
97-
9888
public Map<String, Object> asMap() {
9989
Map<String, Object> map = new LinkedHashMap<>();
10090
map.put(TEXT_EMBEDDING_BYTES, embeddings);

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/inference/results/TextEmbeddingFloatResults.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,6 @@ public List<? extends InferenceResults> transformToCoordinationFormat() {
122122
return embeddings.stream().map(embedding -> new MlTextEmbeddingResults(TEXT_EMBEDDING, embedding.asDoubleArray(), false)).toList();
123123
}
124124

125-
@Override
126-
@SuppressWarnings("deprecation")
127-
public List<? extends InferenceResults> transformToLegacyFormat() {
128-
var legacyEmbedding = new LegacyTextEmbeddingResults(
129-
embeddings.stream().map(embedding -> new LegacyTextEmbeddingResults.Embedding(embedding.values)).toList()
130-
);
131-
132-
return List.of(legacyEmbedding);
133-
}
134-
135125
public Map<String, Object> asMap() {
136126
Map<String, Object> map = new LinkedHashMap<>();
137127
map.put(TEXT_EMBEDDING, embeddings);

x-pack/plugin/inference/src/internalClusterTest/java/org/elasticsearch/xpack/inference/rest/ServerSentEventsRestActionListenerTests.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,6 @@ public List<? extends InferenceResults> transformToCoordinationFormat() {
194194
return List.of();
195195
}
196196

197-
@Override
198-
public List<? extends InferenceResults> transformToLegacyFormat() {
199-
return List.of();
200-
}
201-
202197
@Override
203198
public Map<String, Object> asMap() {
204199
return Map.of();
@@ -283,11 +278,6 @@ public List<? extends InferenceResults> transformToCoordinationFormat() {
283278
return List.of();
284279
}
285280

286-
@Override
287-
public List<? extends InferenceResults> transformToLegacyFormat() {
288-
return List.of();
289-
}
290-
291281
@Override
292282
public Map<String, Object> asMap() {
293283
return Map.of();

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/external/response/elastic/ElasticInferenceServiceAuthorizationResponseEntity.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,6 @@ public List<? extends InferenceResults> transformToCoordinationFormat() {
154154
throw new UnsupportedOperationException("Not implemented");
155155
}
156156

157-
@Override
158-
public List<? extends InferenceResults> transformToLegacyFormat() {
159-
throw new UnsupportedOperationException("not implemented");
160-
}
161-
162157
@Override
163158
public Map<String, Object> asMap() {
164159
throw new UnsupportedOperationException("Not implemented");

0 commit comments

Comments
 (0)