Skip to content

Commit d43c4bb

Browse files
committed
Embedding support in Java Generator
1 parent d20ab4e commit d43c4bb

File tree

21 files changed

+290
-3
lines changed

21 files changed

+290
-3
lines changed

android/src/main/java/com/genexus/db/ForEachCursor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ public void setTimestamp(int index, java.sql.Timestamp value) throws SQLExceptio
217217
public void setBLOBFile(int index, String fileName) throws SQLException {}
218218
public void setBLOBFile(int index, String fileName, boolean isMultiMedia) throws SQLException {}
219219
public void setBLOBFile(int index, String fileName, boolean isMultiMedia, boolean downloadContent) throws SQLException {}
220+
public void setEmbedding(int index, Float[] value) throws SQLException {}
220221

221222
public void setVarchar(int index, String value, int length, boolean allowsNull) throws SQLException {}
222223
public void setLongVarchar(int index, String value, boolean allowsNull) throws SQLException {}

android/src/main/java/com/genexus/db/driver/GXCallableStatement.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,11 @@ public byte[] getBytes(int columnIndex) throws SQLException
651651
return stmt.getBytes(columnIndex);
652652
}
653653

654+
public Float[] getGxembedding (int columnIndex) throws SQLException
655+
{
656+
return null;
657+
}
658+
654659
public java.util.UUID getGUID(int columnIndex) throws SQLException
655660
{
656661
if (DEBUG)

android/src/main/java/com/genexus/db/driver/GXPreparedStatement.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1307,7 +1307,9 @@ else if (file.exists() && !fileNameNew.startsWith(blobBasePath))
13071307
}
13081308
}
13091309
}
1310-
1310+
1311+
public void setEmbedding(int index, Float[] value) throws SQLException{
1312+
}
13111313
public void setBinaryStream(int index, java.io.InputStream value, int length) throws SQLException
13121314
{
13131315
if (DEBUG)

android/src/main/java/com/genexus/db/driver/GXResultSet.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,11 @@ public byte[] getBytes(int columnIndex) throws SQLException
770770
return result.getBytes(columnIndex);
771771
}
772772

773+
public Float[] getGxembedding (int columnIndex) throws SQLException
774+
{
775+
return null;
776+
}
777+
773778
public java.util.UUID getGUID(int columnIndex) throws SQLException
774779
{
775780
java.util.UUID value;

common/src/main/java/com/genexus/db/BufferIFieldGetter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ public byte[] getBytes(int columnIndex) throws SQLException {
8585
return ((byte[]) value[columnIndex - 1]);
8686
}
8787

88+
public Float[] getGxembedding(int columnIndex) throws SQLException {
89+
return ((Float[]) value[columnIndex - 1]);
90+
}
91+
8892
public java.sql.Date getDate(int columnIndex) throws SQLException {
8993
return ((java.sql.Date) value[columnIndex - 1]);
9094
}

common/src/main/java/com/genexus/db/CachedIFieldGetter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,11 @@ public byte[] getBytes(int columnIndex) throws SQLException
220220
else
221221
return ((byte[][])value[index])[0];
222222
}
223+
224+
public Float[] getGxembedding(int columnIndex) throws SQLException
225+
{
226+
return ((Float[][])value[getColumnIndex(columnIndex)])[0];
227+
}
223228

224229
public java.sql.Date getDate(int columnIndex) throws SQLException
225230
{

common/src/main/java/com/genexus/db/IFieldGetter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@ public interface IFieldGetter
3333
String getMultimediaUri(int columnIndex) throws SQLException;
3434
String getMultimediaUri(int columnIndex, boolean absPath) throws SQLException;
3535
java.util.UUID getGUID(int columnIndex) throws SQLException;
36+
Float[] getGxembedding(int columnIndex) throws SQLException;
3637
}

common/src/main/java/com/genexus/db/IFieldSetter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public interface IFieldSetter
3535
public void setBLOBFile(int index, String fileName) throws SQLException;
3636
public void setBLOBFile(int index, String fileName, boolean isMultiMedia) throws SQLException;
3737
public void setBLOBFile(int index, String fileName, boolean isMultiMedia, boolean downloadContent) throws SQLException;
38+
public void setEmbedding(int index, Float[] value) throws SQLException;
3839

3940
public void setVarchar(int index, String value, int length, boolean allowsNull) throws SQLException;
4041
public void setLongVarchar(int index, String value, boolean allowsNull) throws SQLException;

gxembedding/pom.xml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>com.genexus</groupId>
9+
<artifactId>parent</artifactId>
10+
<version>${revision}${changelist}</version>
11+
</parent>
12+
13+
<artifactId>gxembedding</artifactId>
14+
<name>GeneXus Embedding</name>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>${project.groupId}</groupId>
19+
<artifactId>gxcommon</artifactId>
20+
<version>${project.version}</version>
21+
</dependency>
22+
</dependencies>
23+
24+
<build>
25+
<finalName>gxembedding</finalName>
26+
</build>
27+
</project>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package com.genexus.db;
2+
3+
import com.genexus.CommonUtil;
4+
import com.genexus.GXBaseCollection;
5+
import com.genexus.SdtMessages_Message;
6+
import com.genexus.embedding.EmbeddingService;
7+
8+
import java.util.ArrayList;
9+
import java.util.Arrays;
10+
import java.util.List;
11+
import java.util.stream.Collectors;
12+
13+
public class GXEmbedding {
14+
15+
private String model;
16+
private int dimensions;
17+
private List<Float> embedding;
18+
19+
public GXEmbedding() {
20+
}
21+
22+
public GXEmbedding(String model, int dimensions) {
23+
this.model = model;
24+
this.dimensions = dimensions;
25+
embedding = new ArrayList<>(dimensions);
26+
}
27+
28+
public GXEmbedding(Float[] embedding, String model, int dimensions) {
29+
this.model = model;
30+
this.dimensions = dimensions;
31+
this.embedding = Arrays.asList(embedding);
32+
}
33+
34+
public GXEmbedding(List<Float> embedding) {
35+
this.embedding = embedding;
36+
}
37+
38+
public String getModel() {
39+
return model;
40+
}
41+
42+
public int getDimensions() {
43+
return dimensions;
44+
}
45+
46+
public void setEmbedding(List<Float> embedding) {
47+
this.embedding = embedding;
48+
}
49+
50+
public Float[] getFloatArray() {
51+
return embedding.toArray(new Float[0]);
52+
}
53+
54+
public static GXEmbedding generateEmbedding(GXEmbedding embeddingInfo, String text, GXBaseCollection<SdtMessages_Message> Messages) {
55+
try {
56+
List<Float> embedding = EmbeddingService.getInstance().getEmbedding(embeddingInfo.getModel(), embeddingInfo.getDimensions(), text);
57+
embeddingInfo.setEmbedding(embedding);
58+
}
59+
catch (Exception ex) {
60+
CommonUtil.ErrorToMessages("GenerateEmbedding Error", ex.getMessage(), Messages);
61+
}
62+
return embeddingInfo;
63+
}
64+
65+
public String toString()
66+
{
67+
return embedding.stream()
68+
.map(String::valueOf)
69+
.collect(Collectors.joining(","));
70+
}
71+
}

0 commit comments

Comments
 (0)