Skip to content

Commit f72c5b2

Browse files
committed
more renaming
1 parent 0c66a2e commit f72c5b2

File tree

15 files changed

+30
-61
lines changed

15 files changed

+30
-61
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
import java.io.IOException;
1515
import java.util.List;
1616

17-
public interface EmbeddingResults<C extends EmbeddingResults.Chunk, R extends EmbeddingResults.Embedding<C>> extends InferenceServiceResults {
17+
public interface EmbeddingResults<C extends EmbeddingResults.Chunk, R extends EmbeddingResults.Embedding<C>>
18+
extends
19+
InferenceServiceResults {
1820

1921
interface Chunk {
2022
ChunkedInference.Chunk toChunk(XContent xcontent) throws IOException;
@@ -25,7 +27,7 @@ interface Chunk {
2527
}
2628

2729
interface Embedding<C extends Chunk> {
28-
C toEmbeddingChunk(String text, ChunkedInference.TextOffset offset);
30+
C toChunk(String text, ChunkedInference.TextOffset offset);
2931
}
3032

3133
List<R> embeddings();

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ public static SparseEmbeddingResults of(List<? extends InferenceResults> results
5151

5252
for (InferenceResults result : results) {
5353
if (result instanceof TextExpansionResults expansionResults) {
54-
embeddings.add(SparseEmbeddingResults.Embedding.create(expansionResults.getWeightedTokens(), expansionResults.isTruncated()));
54+
embeddings.add(
55+
SparseEmbeddingResults.Embedding.create(expansionResults.getWeightedTokens(), expansionResults.isTruncated())
56+
);
5557
} else if (result instanceof org.elasticsearch.xpack.core.ml.inference.results.ErrorInferenceResults errorResult) {
5658
if (errorResult.getException() instanceof ElasticsearchStatusException statusException) {
5759
throw statusException;
@@ -118,8 +120,11 @@ public List<? extends InferenceResults> transformToLegacyFormat() {
118120
.toList();
119121
}
120122

121-
public record Embedding(List<WeightedToken> tokens, boolean isTruncated) implements Writeable, ToXContentObject,
122-
EmbeddingResults.Embedding<Chunk> {
123+
public record Embedding(List<WeightedToken> tokens, boolean isTruncated)
124+
implements
125+
Writeable,
126+
ToXContentObject,
127+
EmbeddingResults.Embedding<Chunk> {
123128

124129
public static final String EMBEDDING = "embedding";
125130
public static final String IS_TRUNCATED = "is_truncated";
@@ -170,7 +175,7 @@ public String toString() {
170175
}
171176

172177
@Override
173-
public Chunk toEmbeddingChunk(String text, ChunkedInference.TextOffset offset) {
178+
public Chunk toChunk(String text, ChunkedInference.TextOffset offset) {
174179
return new Chunk(tokens, text, offset);
175180
}
176181
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.elasticsearch.xpack.core.ml.inference.results.MlTextEmbeddingResults;
1919

2020
import java.io.IOException;
21-
import java.util.ArrayList;
2221
import java.util.Iterator;
2322
import java.util.LinkedHashMap;
2423
import java.util.List;

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
@@ -188,7 +188,7 @@ public int hashCode() {
188188
}
189189

190190
@Override
191-
public Chunk toEmbeddingChunk(String text, ChunkedInference.TextOffset offset) {
191+
public Chunk toChunk(String text, ChunkedInference.TextOffset offset) {
192192
return new Chunk(values, text, offset);
193193
}
194194
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,12 @@ public int hashCode() {
222222
}
223223

224224
@Override
225-
public Chunk toEmbeddingChunk(String text, ChunkedInference.TextOffset offset) {
225+
public Chunk toChunk(String text, ChunkedInference.TextOffset offset) {
226226
return new Chunk(values, text, offset);
227227
}
228228
}
229229

230-
public record Chunk(float[] embedding, String matchedText, ChunkedInference.TextOffset offset)
231-
implements
232-
EmbeddingResults.Chunk {
230+
public record Chunk(float[] embedding, String matchedText, ChunkedInference.TextOffset offset) implements EmbeddingResults.Chunk {
233231

234232
public ChunkedInference.Chunk toChunk(XContent xcontent) throws IOException {
235233
return new ChunkedInference.Chunk(matchedText, offset, toBytesReference(xcontent, embedding));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ private ChunkedInference mergeResultsWithInputs(int index) {
227227
AtomicReferenceArray<EmbeddingResults.Embedding<?>> result = results.get(index);
228228
for (int i = 0; i < request.size(); i++) {
229229
EmbeddingResults.Chunk chunk = result.get(i)
230-
.toEmbeddingChunk(
230+
.toChunk(
231231
request.get(i).chunkText(),
232232
new ChunkedInference.TextOffset(request.get(i).chunk.start(), request.get(i).chunk.end())
233233
);

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/external/response/amazonbedrock/embeddings/AmazonBedrockEmbeddingsResponse.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,8 @@ public static TextEmbeddingFloatResults fromResponse(InvokeModelResponse respons
6969
}
7070
}
7171

72-
private static List<TextEmbeddingFloatResults.Embedding> parseEmbeddings(
73-
XContentParser jsonParser,
74-
AmazonBedrockProvider provider
75-
) throws IOException {
72+
private static List<TextEmbeddingFloatResults.Embedding> parseEmbeddings(XContentParser jsonParser, AmazonBedrockProvider provider)
73+
throws IOException {
7674
switch (provider) {
7775
case AMAZONTITAN -> {
7876
return parseTitanEmbeddings(jsonParser);
@@ -121,8 +119,7 @@ private static List<TextEmbeddingFloatResults.Embedding> parseCohereEmbeddings(X
121119
return embeddingList;
122120
}
123121

124-
private static TextEmbeddingFloatResults.Embedding parseCohereEmbeddingsListItem(XContentParser parser)
125-
throws IOException {
122+
private static TextEmbeddingFloatResults.Embedding parseCohereEmbeddingsListItem(XContentParser parser) throws IOException {
126123
List<Float> embeddingValuesList = parseList(parser, XContentUtils::parseFloat);
127124
return TextEmbeddingFloatResults.Embedding.of(embeddingValuesList);
128125
}

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/external/response/azureaistudio/AzureAiStudioEmbeddingsResponseEntityTests.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ public void testFromResponse_CreatesResultsForASingleItem() throws IOException {
5555
new HttpResult(mock(HttpResponse.class), responseJson.getBytes(StandardCharsets.UTF_8))
5656
);
5757

58-
assertThat(
59-
parsedResults.embeddings(),
60-
is(List.of(TextEmbeddingFloatResults.Embedding.of(List.of(0.014539449F, -0.015288644F))))
61-
);
58+
assertThat(parsedResults.embeddings(), is(List.of(TextEmbeddingFloatResults.Embedding.of(List.of(0.014539449F, -0.015288644F)))));
6259
}
6360
}

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/external/response/cohere/CohereEmbeddingsResponseEntityTests.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,7 @@ public void testFromResponse_ParsesBytes_FromBinaryEmbeddingsEntry() throws IOEx
264264

265265
MatcherAssert.assertThat(
266266
parsedResults.embeddings(),
267-
is(
268-
List.of(
269-
new TextEmbeddingByteResults.Embedding(
270-
new byte[] { (byte) -55, (byte) 74, (byte) 101, (byte) 67, (byte) 83 }
271-
)
272-
)
273-
)
267+
is(List.of(new TextEmbeddingByteResults.Embedding(new byte[] { (byte) -55, (byte) 74, (byte) 101, (byte) 67, (byte) 83 })))
274268
);
275269
}
276270

@@ -413,9 +407,7 @@ public void testFromResponse_CreatesResultsForMultipleItems_ObjectFormat_Binary(
413407
is(
414408
List.of(
415409
new TextEmbeddingByteResults.Embedding(new byte[] { (byte) -55, (byte) 74, (byte) 101, (byte) 67 }),
416-
new TextEmbeddingByteResults.Embedding(
417-
new byte[] { (byte) 34, (byte) -64, (byte) 97, (byte) 65, (byte) -42 }
418-
)
410+
new TextEmbeddingByteResults.Embedding(new byte[] { (byte) 34, (byte) -64, (byte) 97, (byte) 65, (byte) -42 })
419411
)
420412
)
421413
);

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/external/response/googleaistudio/GoogleAiStudioEmbeddingsResponseEntityTests.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ public void testFromResponse_CreatesResultsForASingleItem() throws IOException {
4141
new HttpResult(mock(HttpResponse.class), responseJson.getBytes(StandardCharsets.UTF_8))
4242
);
4343

44-
assertThat(
45-
parsedResults.embeddings(),
46-
is(List.of(TextEmbeddingFloatResults.Embedding.of(List.of(-0.00606332F, 0.058092743F))))
47-
);
44+
assertThat(parsedResults.embeddings(), is(List.of(TextEmbeddingFloatResults.Embedding.of(List.of(-0.00606332F, 0.058092743F)))));
4845
}
4946

5047
public void testFromResponse_CreatesResultsForMultipleItems() throws IOException {

0 commit comments

Comments
 (0)