Skip to content

Commit 4d1d920

Browse files
author
Milder Hernandez Cagua
committed
Add suggestions
1 parent 0893c5d commit 4d1d920

File tree

4 files changed

+102
-55
lines changed

4 files changed

+102
-55
lines changed

api-test/integration-tests/pom.xml

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -144,31 +144,6 @@
144144
</execution>
145145
</executions>
146146
</plugin>
147-
148-
<plugin>
149-
<groupId>io.fabric8</groupId>
150-
<artifactId>docker-maven-plugin</artifactId>
151-
<version>0.45.0</version> <!-- Use the latest version -->
152-
<executions>
153-
<execution>
154-
<id>build-image</id>
155-
<phase>package</phase>
156-
<goals>
157-
<goal>build</goal>
158-
</goals>
159-
</execution>
160-
</executions>
161-
<configuration>
162-
<images>
163-
<image>
164-
<name>pgvector:latest</name>
165-
<build>
166-
<dockerFile>${project.basedir}/api-test/integration-tests/src/test/java/com/microsoft/semantickernel/tests/jdbc/pgvector/Dockerfile</dockerFile>
167-
</build>
168-
</image>
169-
</images>
170-
</configuration>
171-
</plugin>
172147
</plugins>
173148
</build>
174149

semantickernel-experimental/src/main/java/com/microsoft/semantickernel/connectors/data/jdbc/JDBCVectorStoreDefaultQueryProvider.java

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,14 @@
2525
import java.util.List;
2626
import java.util.Map;
2727
import java.util.stream.Collectors;
28+
import java.util.stream.Stream;
2829

2930
public class JDBCVectorStoreDefaultQueryProvider
3031
implements JDBCVectorStoreQueryProvider {
31-
/**
32-
* Map of supported key types to their SQL types.
33-
* Can be modified by subclasses.
34-
*/
35-
protected Map<Class<?>, String> supportedKeyTypes;
3632

37-
/**
38-
* Map of supported data types to their SQL types.
39-
* Can be modified by subclasses.
40-
*/
41-
protected Map<Class<?>, String> supportedDataTypes;
42-
43-
/**
44-
* Map of supported vector types to their SQL types.
45-
* Can be modified by subclasses.
46-
*/
47-
protected Map<Class<?>, String> supportedVectorTypes;
33+
private Map<Class<?>, String> supportedKeyTypes;
34+
private Map<Class<?>, String> supportedDataTypes;
35+
private Map<Class<?>, String> supportedVectorTypes;
4836
private final DataSource dataSource;
4937
private final String collectionsTable;
5038
private final String prefixForCollectionTables;
@@ -95,14 +83,9 @@ public static Builder builder() {
9583
* @return the formatted wildcard string
9684
*/
9785
protected String getWildcardString(int wildcards) {
98-
StringBuilder wildcardString = new StringBuilder();
99-
for (int i = 0; i < wildcards; ++i) {
100-
wildcardString.append("?");
101-
if (i < wildcards - 1) {
102-
wildcardString.append(", ");
103-
}
104-
}
105-
return wildcardString.toString();
86+
return Stream.generate(() -> "?")
87+
.limit(wildcards)
88+
.collect(Collectors.joining(", "));
10689
}
10790

10891
/**
@@ -133,6 +116,36 @@ protected String getCollectionTableName(String collectionName) {
133116
return validateSQLidentifier(prefixForCollectionTables + collectionName);
134117
}
135118

119+
/**
120+
* Gets the supported key types and their corresponding SQL types.
121+
*
122+
* @return the supported key types
123+
*/
124+
@Override
125+
public Map<Class<?>, String> getSupportedKeyTypes() {
126+
return new HashMap<>(this.supportedKeyTypes);
127+
}
128+
129+
/**
130+
* Gets the supported data types and their corresponding SQL types.
131+
*
132+
* @return the supported data types
133+
*/
134+
@Override
135+
public Map<Class<?>, String> getSupportedDataTypes() {
136+
return new HashMap<>(this.supportedDataTypes);
137+
}
138+
139+
/**
140+
* Gets the supported vector types and their corresponding SQL types.
141+
*
142+
* @return the supported vector types
143+
*/
144+
@Override
145+
public Map<Class<?>, String> getSupportedVectorTypes() {
146+
return new HashMap<>(this.supportedVectorTypes);
147+
}
148+
136149
/**
137150
* Prepares the vector store.
138151
* Executes any necessary setup steps for the vector store.
@@ -165,11 +178,12 @@ public void validateSupportedTypes(Class<?> recordClass,
165178
VectorStoreRecordDefinition recordDefinition) {
166179
VectorStoreRecordDefinition.validateSupportedTypes(
167180
Collections.singletonList(recordDefinition.getKeyDeclaredField(recordClass)),
168-
supportedKeyTypes.keySet());
181+
getSupportedKeyTypes().keySet());
169182
VectorStoreRecordDefinition.validateSupportedTypes(
170-
recordDefinition.getDataDeclaredFields(recordClass), supportedDataTypes.keySet());
183+
recordDefinition.getDataDeclaredFields(recordClass), getSupportedDataTypes().keySet());
171184
VectorStoreRecordDefinition.validateSupportedTypes(
172-
recordDefinition.getVectorDeclaredFields(recordClass), supportedVectorTypes.keySet());
185+
recordDefinition.getVectorDeclaredFields(recordClass),
186+
getSupportedVectorTypes().keySet());
173187
}
174188

175189
/**
@@ -213,8 +227,8 @@ public void createCollection(String collectionName, Class<?> recordClass,
213227
String createStorageTable = "CREATE TABLE IF NOT EXISTS "
214228
+ getCollectionTableName(collectionName)
215229
+ " (" + keyDeclaredField.getName() + " VARCHAR(255) PRIMARY KEY, "
216-
+ getColumnNamesAndTypes(dataDeclaredFields, supportedDataTypes) + ", "
217-
+ getColumnNamesAndTypes(vectorDeclaredFields, supportedVectorTypes) + ");";
230+
+ getColumnNamesAndTypes(dataDeclaredFields, getSupportedDataTypes()) + ", "
231+
+ getColumnNamesAndTypes(vectorDeclaredFields, getSupportedVectorTypes()) + ");";
218232

219233
String insertCollectionQuery = "INSERT INTO " + validateSQLidentifier(collectionsTable)
220234
+ " (collectionId) VALUES (?)";

semantickernel-experimental/src/main/java/com/microsoft/semantickernel/connectors/data/jdbc/JDBCVectorStoreQueryProvider.java

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

1111
import java.sql.ResultSet;
1212
import java.util.List;
13+
import java.util.Map;
1314

1415
/**
1516
* The JDBC vector store query provider.
@@ -26,6 +27,27 @@ public interface JDBCVectorStoreQueryProvider {
2627
*/
2728
String DEFAULT_PREFIX_FOR_COLLECTION_TABLES = "SKCollection_";
2829

30+
/**
31+
* Gets the supported key types and their corresponding SQL types.
32+
*
33+
* @return the supported key types
34+
*/
35+
Map<Class<?>, String> getSupportedKeyTypes();
36+
37+
/**
38+
* Gets the supported data types and their corresponding SQL types.
39+
*
40+
* @return the supported data types
41+
*/
42+
Map<Class<?>, String> getSupportedDataTypes();
43+
44+
/**
45+
* Gets the supported vector types and their corresponding SQL types.
46+
*
47+
* @return the supported vector types
48+
*/
49+
Map<Class<?>, String> getSupportedVectorTypes();
50+
2951
/**
3052
* Prepares the vector store.
3153
* Executes any necessary setup steps for the vector store.

semantickernel-experimental/src/main/java/com/microsoft/semantickernel/connectors/data/postgres/PostgreSQLVectorStoreQueryProvider.java

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,15 @@
2525
import java.util.Collections;
2626
import java.util.HashMap;
2727
import java.util.List;
28+
import java.util.Map;
2829

2930
public class PostgreSQLVectorStoreQueryProvider extends
3031
JDBCVectorStoreDefaultQueryProvider implements JDBCVectorStoreQueryProvider {
32+
33+
private Map<Class<?>, String> supportedKeyTypes;
34+
private Map<Class<?>, String> supportedDataTypes;
35+
private Map<Class<?>, String> supportedVectorTypes;
36+
3137
private final DataSource dataSource;
3238
private final String collectionsTable;
3339
private final String prefixForCollectionTables;
@@ -63,6 +69,36 @@ private PostgreSQLVectorStoreQueryProvider(DataSource dataSource, String collect
6369
supportedVectorTypes.put(Collection.class, "VECTOR(%d)");
6470
}
6571

72+
/**
73+
* Gets the supported key types and their corresponding SQL types.
74+
*
75+
* @return the supported key types
76+
*/
77+
@Override
78+
public Map<Class<?>, String> getSupportedKeyTypes() {
79+
return new HashMap<>(this.supportedKeyTypes);
80+
}
81+
82+
/**
83+
* Gets the supported data types and their corresponding SQL types.
84+
*
85+
* @return the supported data types
86+
*/
87+
@Override
88+
public Map<Class<?>, String> getSupportedDataTypes() {
89+
return new HashMap<>(this.supportedDataTypes);
90+
}
91+
92+
/**
93+
* Gets the supported vector types and their corresponding SQL types.
94+
*
95+
* @return the supported vector types
96+
*/
97+
@Override
98+
public Map<Class<?>, String> getSupportedVectorTypes() {
99+
return new HashMap<>(this.supportedVectorTypes);
100+
}
101+
66102
/**
67103
* Creates a new builder.
68104
* @return the builder
@@ -103,7 +139,7 @@ private String getColumnNamesAndTypesForVectorFields(List<VectorStoreRecordVecto
103139
}
104140

105141
if (declaredField.getType().equals(String.class)) {
106-
columnNames.append(field.getName())
142+
columnNames.append(field.getName()).append(" ")
107143
.append(supportedVectorTypes.get(String.class));
108144
} else {
109145
// Get the vector type and dimensions

0 commit comments

Comments
 (0)