Skip to content

Commit 0c66a2e

Browse files
committed
remove interface "EmbeddingInt"
1 parent 6181080 commit 0c66a2e

File tree

6 files changed

+16
-44
lines changed

6 files changed

+16
-44
lines changed

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

Lines changed: 0 additions & 12 deletions
This file was deleted.

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ public TextEmbeddingBitResults(StreamInput in) throws IOException {
5555

5656
@Override
5757
public int getFirstEmbeddingSize() {
58-
return TextEmbeddingUtils.getFirstEmbeddingSize(new ArrayList<>(embeddings));
58+
if (embeddings.isEmpty()) {
59+
throw new IllegalStateException("Embeddings list is empty");
60+
}
61+
return embeddings.getFirst().values().length;
5962
}
6063

6164
@Override

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.elasticsearch.xpack.core.ml.inference.results.MlTextEmbeddingResults;
2525

2626
import java.io.IOException;
27-
import java.util.ArrayList;
2827
import java.util.Arrays;
2928
import java.util.Iterator;
3029
import java.util.LinkedHashMap;
@@ -62,7 +61,10 @@ public TextEmbeddingByteResults(StreamInput in) throws IOException {
6261

6362
@Override
6463
public int getFirstEmbeddingSize() {
65-
return TextEmbeddingUtils.getFirstEmbeddingSize(new ArrayList<>(embeddings));
64+
if (embeddings.isEmpty()) {
65+
throw new IllegalStateException("Embeddings list is empty");
66+
}
67+
return embeddings.getFirst().values().length;
6668
}
6769

6870
@Override
@@ -117,7 +119,7 @@ public int hashCode() {
117119
return Objects.hash(embeddings);
118120
}
119121

120-
public record Embedding(byte[] values) implements Writeable, ToXContentObject, EmbeddingInt, EmbeddingResults.Embedding<Chunk> {
122+
public record Embedding(byte[] values) implements Writeable, ToXContentObject, EmbeddingResults.Embedding<Chunk> {
121123
public static final String EMBEDDING = "embedding";
122124

123125
public Embedding(StreamInput in) throws IOException {
@@ -172,11 +174,6 @@ float[] toFloatArray() {
172174
return doubleArray;
173175
}
174176

175-
@Override
176-
public int getSize() {
177-
return values().length;
178-
}
179-
180177
@Override
181178
public boolean equals(Object o) {
182179
if (this == o) return true;

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ public static TextEmbeddingFloatResults of(List<? extends InferenceResults> resu
100100

101101
@Override
102102
public int getFirstEmbeddingSize() {
103-
return TextEmbeddingUtils.getFirstEmbeddingSize(new ArrayList<>(embeddings));
103+
if (embeddings.isEmpty()) {
104+
throw new IllegalStateException("Embeddings list is empty");
105+
}
106+
return embeddings.getFirst().values().length;
104107
}
105108

106109
@Override
@@ -153,7 +156,7 @@ public int hashCode() {
153156
return Objects.hash(embeddings);
154157
}
155158

156-
public record Embedding(float[] values) implements Writeable, ToXContentObject, EmbeddingInt, EmbeddingResults.Embedding<Chunk> {
159+
public record Embedding(float[] values) implements Writeable, ToXContentObject, EmbeddingResults.Embedding<Chunk> {
157160
public static final String EMBEDDING = "embedding";
158161

159162
public Embedding(StreamInput in) throws IOException {
@@ -173,11 +176,6 @@ public static Embedding of(List<Float> embeddingValuesList) {
173176
return new Embedding(embeddingValues);
174177
}
175178

176-
@Override
177-
public int getSize() {
178-
return values.length;
179-
}
180-
181179
@Override
182180
public void writeTo(StreamOutput out) throws IOException {
183181
out.writeFloatArray(values);

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,6 @@
1313

1414
public class TextEmbeddingUtils {
1515

16-
/**
17-
* Returns the first text embedding entry's array size.
18-
* @param embeddings the list of embeddings
19-
* @return the size of the text embedding
20-
* @throws IllegalStateException if the list of embeddings is empty
21-
*/
22-
public static int getFirstEmbeddingSize(List<EmbeddingInt> embeddings) throws IllegalStateException {
23-
if (embeddings.isEmpty()) {
24-
throw new IllegalStateException("Embeddings list is empty");
25-
}
26-
27-
return embeddings.get(0).getSize();
28-
}
29-
3016
/**
3117
* Throws an exception if the number of elements in the input text list is different than the results in text embedding
3218
* response.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ public void testGetEmbeddingSize_ReturnsSize_ForTextEmbeddingResults() {
967967

968968
var size = listener.actionGet(TIMEOUT);
969969

970-
assertThat(size, is(textEmbedding.embeddings().get(0).getSize()));
970+
assertThat(size, is(textEmbedding.embeddings().get(0).values().length));
971971
}
972972

973973
public void testGetEmbeddingSize_ReturnsSize_ForTextEmbeddingByteResults() {
@@ -990,7 +990,7 @@ public void testGetEmbeddingSize_ReturnsSize_ForTextEmbeddingByteResults() {
990990

991991
var size = listener.actionGet(TIMEOUT);
992992

993-
assertThat(size, is(textEmbedding.embeddings().get(0).getSize()));
993+
assertThat(size, is(textEmbedding.embeddings().get(0).values().length));
994994
}
995995

996996
private static <K, V> Map<K, V> modifiableMap(Map<K, V> aMap) {

0 commit comments

Comments
 (0)