Skip to content

Commit a7fcc6d

Browse files
committed
Embedding must be initialized with empty values.
1 parent 8d80ee5 commit a7fcc6d

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

java/src/main/java/com/genexus/db/GXEmbedding.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import java.util.ArrayList;
1212
import java.util.Arrays;
13+
import java.util.Collections;
1314
import java.util.List;
1415
import java.util.stream.Collectors;
1516

@@ -26,7 +27,7 @@ public GXEmbedding() {
2627
public GXEmbedding(String model, int dimensions) {
2728
this.model = model;
2829
this.dimensions = dimensions;
29-
embedding = new ArrayList<>(dimensions);
30+
embedding = new ArrayList<>(Collections.nCopies(dimensions, 0.0f));
3031
}
3132

3233
public GXEmbedding(Float[] embedding, String model, int dimensions) {
@@ -48,7 +49,8 @@ public int getDimensions() {
4849
}
4950

5051
public void setEmbedding(List<Float> embedding) {
51-
this.embedding = embedding;
52+
if (!embedding.isEmpty())
53+
this.embedding = embedding;
5254
}
5355

5456
public Float[] getFloatArray() {
@@ -67,6 +69,8 @@ public static GXEmbedding generateEmbedding(GXEmbedding embeddingInfo, String te
6769
}
6870

6971
public static List<Float> getEmbedding(String model, int dimensions, String input) {
72+
if (input.isEmpty())
73+
return new ArrayList<>();
7074
ArrayList<String> inputList = new ArrayList<>();
7175
inputList.add(input);
7276
return getEmbedding(model, dimensions, inputList);

java/src/test/java/com/genexus/embedding/GXEmbeddingTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.genexus.embedding;
22

33
import com.genexus.Application;
4+
import com.genexus.GXBaseCollection;
5+
import com.genexus.SdtMessages_Message;
46
import com.genexus.db.GXEmbedding;
57
import com.genexus.sampleapp.GXcfg;
68
import com.genexus.specific.java.Connect;
@@ -23,5 +25,11 @@ public void EmbeddingTest(){
2325
.collect(Collectors.joining(","));
2426
System.out.println("Embedding: " + result);
2527
Assert.assertNotNull(embedding);
28+
29+
GXBaseCollection<SdtMessages_Message> AV8Messages = new GXBaseCollection<>();
30+
GXEmbedding A7ProductEmbedding = new GXEmbedding("openai/text-embedding-3-small",512) ;
31+
GXEmbedding AV9ProductEmbedding = GXEmbedding.generateEmbedding(A7ProductEmbedding, "", AV8Messages) ;
32+
result = AV9ProductEmbedding.toString();
33+
System.out.println("Empty Embedding: " + result);
2634
}
2735
}

0 commit comments

Comments
 (0)