Skip to content

Commit 8803094

Browse files
newtorka-d
andauthored
Change OpenAI Emedding vector type from List<Double> to float[] (#252)
* Initial * Release notes --------- Co-authored-by: Alexander Dümont <[email protected]>
1 parent 0329828 commit 8803094

File tree

4 files changed

+4
-12
lines changed

4 files changed

+4
-12
lines changed

docs/release-notes/release_notes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
### 🔧 Compatibility Notes
1010

11-
-
11+
- Changed return type of `List<Double> getEmbedding()` from experimental API `OpenAiEmbeddingData` to `float[]` to match recent Spring AI change.
1212

1313
### ✨ New Functionality
1414

foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/model/OpenAiEmbeddingData.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.fasterxml.jackson.annotation.JsonProperty;
44
import com.google.common.annotations.Beta;
5-
import java.util.List;
65
import javax.annotation.Nonnull;
76
import lombok.EqualsAndHashCode;
87
import lombok.Getter;
@@ -23,7 +22,7 @@ public class OpenAiEmbeddingData {
2322
/** Array of size `1536` (OpenAI's embedding size) containing embedding vector. */
2423
@JsonProperty("embedding")
2524
@Getter(onMethod_ = @Nonnull)
26-
private List<Double> embedding;
25+
private float[] embedding;
2726

2827
/** Index of choice. */
2928
@JsonProperty("index")

foundation-models/openai/src/test/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiClientTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,7 @@ void embedding() {
373373
assertThat(embeddingData.getEmbedding())
374374
.isNotNull()
375375
.isNotEmpty()
376-
.containsExactly(-0.0000000070958645d, 2.123e-300d, -0.0069813123d, -3.385849e-05d)
377-
// ensure double precision
378-
.hasToString("[-7.0958645E-9, 2.123E-300, -0.0069813123, -3.385849E-5]");
376+
.isEqualTo(new float[] {0.0f, 3.4028235E38f, 1.4E-45f, 1.23f, -4.56f});
379377

380378
verify(
381379
postRequestedFor(urlPathEqualTo("/embeddings"))

foundation-models/openai/src/test/resources/__files/embeddingResponse.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
{
22
"data": [
33
{
4-
"embedding": [
5-
-0.0000000070958645,
6-
2.123e-300,
7-
-0.0069813123,
8-
-3.385849e-05
9-
],
4+
"embedding": [ 0.0, 3.4028235E38, 1.4E-45, 1.23, -4.56 ],
105
"index": 0,
116
"object": "embedding"
127
}

0 commit comments

Comments
 (0)