Skip to content

Commit 4e6003d

Browse files
T21: Use float[] instead of List<Double> in EmbeddingModelTypes
Avoids boxing 1536+ Double objects per embedding. float[] matches Spring AI's native embedding representation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 6c3a107 commit 4e6003d

3 files changed

Lines changed: 5 additions & 13 deletions

File tree

TASK_QUEUE.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
"severity": "low",
7979
"category": "improvement",
8080
"depends_on": [],
81-
"status": "todo",
81+
"status": "completed",
8282
"notes": "DABH review comment: https://github.com/temporalio/sdk-java/pull/2829/files#r3054058971"
8383
},
8484
{

temporal-spring-ai/src/main/java/io/temporal/springai/activity/EmbeddingModelActivityImpl.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public EmbeddingModelActivityImpl(EmbeddingModel embeddingModel) {
2525
@Override
2626
public EmbeddingModelTypes.EmbedOutput embed(EmbeddingModelTypes.EmbedTextInput input) {
2727
float[] embedding = embeddingModel.embed(input.text());
28-
return new EmbeddingModelTypes.EmbedOutput(toDoubleList(embedding));
28+
return new EmbeddingModelTypes.EmbedOutput(embedding);
2929
}
3030

3131
@Override
@@ -38,8 +38,7 @@ public EmbeddingModelTypes.EmbedBatchOutput embedBatch(
3838
.mapToObj(
3939
i -> {
4040
var embedding = response.getResults().get(i);
41-
return new EmbeddingModelTypes.EmbeddingResult(
42-
i, toDoubleList(embedding.getOutput()));
41+
return new EmbeddingModelTypes.EmbeddingResult(i, embedding.getOutput());
4342
})
4443
.collect(Collectors.toList());
4544

@@ -62,11 +61,4 @@ public EmbeddingModelTypes.EmbedBatchOutput embedBatch(
6261
public EmbeddingModelTypes.DimensionsOutput dimensions() {
6362
return new EmbeddingModelTypes.DimensionsOutput(embeddingModel.dimensions());
6463
}
65-
66-
private List<Double> toDoubleList(float[] floats) {
67-
return IntStream.range(0, floats.length)
68-
.mapToDouble(i -> floats[i])
69-
.boxed()
70-
.collect(Collectors.toList());
71-
}
7264
}

temporal-spring-ai/src/main/java/io/temporal/springai/model/EmbeddingModelTypes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public record EmbedBatchInput(List<String> texts) {}
3131
*
3232
* @param embedding the embedding vector
3333
*/
34-
public record EmbedOutput(List<Double> embedding) {}
34+
public record EmbedOutput(float[] embedding) {}
3535

3636
/**
3737
* Output containing multiple embedding vectors.
@@ -47,7 +47,7 @@ public record EmbedBatchOutput(List<EmbeddingResult> embeddings, EmbeddingMetada
4747
* @param index the index in the original input list
4848
* @param embedding the embedding vector
4949
*/
50-
public record EmbeddingResult(int index, List<Double> embedding) {}
50+
public record EmbeddingResult(int index, float[] embedding) {}
5151

5252
/**
5353
* Metadata about the embedding operation.

0 commit comments

Comments
 (0)