Skip to content

Commit 2477af2

Browse files
committed
remove Chunk generic
1 parent b31158e commit 2477af2

File tree

6 files changed

+12
-16
lines changed

6 files changed

+12
-16
lines changed

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919
* A call to the inference service may contain multiple input texts, so this results may
2020
* contain multiple results.
2121
*/
22-
public interface EmbeddingResults<C extends EmbeddingResults.Chunk, E extends EmbeddingResults.Embedding<C, E>>
23-
extends
24-
InferenceServiceResults {
22+
public interface EmbeddingResults<E extends EmbeddingResults.Embedding<E>> extends InferenceServiceResults {
2523

2624
/**
2725
* A resulting embedding together with the offset into the input text.
@@ -35,11 +33,11 @@ interface Chunk {
3533
/**
3634
* A resulting embedding for one of the input texts to the inference service.
3735
*/
38-
interface Embedding<C extends Chunk, E extends EmbeddingResults.Embedding<C, E>> {
36+
interface Embedding<E extends Embedding<E>> {
3937
/**
4038
* Combines the resulting embedding with the offset into the input text into a chunk.
4139
*/
42-
C toChunk(ChunkedInference.TextOffset offset);
40+
Chunk toChunk(ChunkedInference.TextOffset offset);
4341

4442
/**
4543
* Merges the existing embedding and provided embedding into a new embedding.

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@
3737

3838
import static org.elasticsearch.xpack.core.ml.inference.trainedmodel.InferenceConfig.DEFAULT_RESULTS_FIELD;
3939

40-
public record SparseEmbeddingResults(List<Embedding> embeddings)
41-
implements
42-
EmbeddingResults<SparseEmbeddingResults.Chunk, SparseEmbeddingResults.Embedding> {
40+
public record SparseEmbeddingResults(List<Embedding> embeddings) implements EmbeddingResults<SparseEmbeddingResults.Embedding> {
4341

4442
public static final String NAME = "sparse_embedding_results";
4543
public static final String SPARSE_EMBEDDING = TaskType.SPARSE_EMBEDDING.toString();
@@ -126,7 +124,7 @@ public record Embedding(List<WeightedToken> tokens, boolean isTruncated)
126124
implements
127125
Writeable,
128126
ToXContentObject,
129-
EmbeddingResults.Embedding<Chunk, Embedding> {
127+
EmbeddingResults.Embedding<Embedding> {
130128

131129
public static final String EMBEDDING = "embedding";
132130
public static final String IS_TRUNCATED = "is_truncated";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public record Embedding(byte[] values, int[] sumMergedValues, int numberOfMerged
124124
implements
125125
Writeable,
126126
ToXContentObject,
127-
EmbeddingResults.Embedding<Chunk, Embedding> {
127+
EmbeddingResults.Embedding<Embedding> {
128128

129129
public static final String EMBEDDING = "embedding";
130130

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public record Embedding(float[] values, int numberOfMergedEmbeddings)
161161
implements
162162
Writeable,
163163
ToXContentObject,
164-
EmbeddingResults.Embedding<Chunk, Embedding> {
164+
EmbeddingResults.Embedding<Embedding> {
165165
public static final String EMBEDDING = "embedding";
166166

167167
public Embedding(float[] values) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
package org.elasticsearch.xpack.core.inference.results;
99

10-
public interface TextEmbeddingResults<C extends EmbeddingResults.Chunk, E extends EmbeddingResults.Embedding<C, E>>
10+
public interface TextEmbeddingResults<C extends EmbeddingResults.Chunk, E extends EmbeddingResults.Embedding<E>>
1111
extends
12-
EmbeddingResults<C, E> {
12+
EmbeddingResults<E> {
1313

1414
/**
1515
* Returns the first text embedding entry in the result list's array size.

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/chunking/EmbeddingRequestChunker.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* processing and map the results back to the original element
3737
* in the input list.
3838
*/
39-
public class EmbeddingRequestChunker<C extends EmbeddingResults.Chunk, E extends EmbeddingResults.Embedding<C, E>> {
39+
public class EmbeddingRequestChunker<E extends EmbeddingResults.Embedding<E>> {
4040

4141
// Visible for testing
4242
record Request(int inputIndex, int chunkIndex, ChunkOffset chunk, List<String> inputs) {
@@ -150,12 +150,12 @@ private class DebatchingListener implements ActionListener<InferenceServiceResul
150150

151151
@Override
152152
public void onResponse(InferenceServiceResults inferenceServiceResults) {
153-
if (inferenceServiceResults instanceof EmbeddingResults<?, ?> == false) {
153+
if (inferenceServiceResults instanceof EmbeddingResults<?> == false) {
154154
onFailure(unexpectedResultTypeException(inferenceServiceResults.getWriteableName()));
155155
return;
156156
}
157157
@SuppressWarnings("unchecked")
158-
EmbeddingResults<C, E> embeddingResults = (EmbeddingResults<C, E>) inferenceServiceResults;
158+
EmbeddingResults<E> embeddingResults = (EmbeddingResults<E>) inferenceServiceResults;
159159
if (embeddingResults.embeddings().size() != request.requests.size()) {
160160
onFailure(numResultsDoesntMatchException(embeddingResults.embeddings().size(), request.requests.size()));
161161
return;

0 commit comments

Comments
 (0)