|
25 | 25 | import java.util.List; |
26 | 26 | import java.util.Map; |
27 | 27 | import java.util.stream.Collectors; |
| 28 | +import java.util.stream.Stream; |
28 | 29 |
|
29 | 30 | public class JDBCVectorStoreDefaultQueryProvider |
30 | 31 | 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; |
36 | 32 |
|
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; |
48 | 36 | private final DataSource dataSource; |
49 | 37 | private final String collectionsTable; |
50 | 38 | private final String prefixForCollectionTables; |
@@ -95,14 +83,9 @@ public static Builder builder() { |
95 | 83 | * @return the formatted wildcard string |
96 | 84 | */ |
97 | 85 | 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(", ")); |
106 | 89 | } |
107 | 90 |
|
108 | 91 | /** |
@@ -133,6 +116,36 @@ protected String getCollectionTableName(String collectionName) { |
133 | 116 | return validateSQLidentifier(prefixForCollectionTables + collectionName); |
134 | 117 | } |
135 | 118 |
|
| 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 | + |
136 | 149 | /** |
137 | 150 | * Prepares the vector store. |
138 | 151 | * Executes any necessary setup steps for the vector store. |
@@ -165,11 +178,12 @@ public void validateSupportedTypes(Class<?> recordClass, |
165 | 178 | VectorStoreRecordDefinition recordDefinition) { |
166 | 179 | VectorStoreRecordDefinition.validateSupportedTypes( |
167 | 180 | Collections.singletonList(recordDefinition.getKeyDeclaredField(recordClass)), |
168 | | - supportedKeyTypes.keySet()); |
| 181 | + getSupportedKeyTypes().keySet()); |
169 | 182 | VectorStoreRecordDefinition.validateSupportedTypes( |
170 | | - recordDefinition.getDataDeclaredFields(recordClass), supportedDataTypes.keySet()); |
| 183 | + recordDefinition.getDataDeclaredFields(recordClass), getSupportedDataTypes().keySet()); |
171 | 184 | VectorStoreRecordDefinition.validateSupportedTypes( |
172 | | - recordDefinition.getVectorDeclaredFields(recordClass), supportedVectorTypes.keySet()); |
| 185 | + recordDefinition.getVectorDeclaredFields(recordClass), |
| 186 | + getSupportedVectorTypes().keySet()); |
173 | 187 | } |
174 | 188 |
|
175 | 189 | /** |
@@ -213,8 +227,8 @@ public void createCollection(String collectionName, Class<?> recordClass, |
213 | 227 | String createStorageTable = "CREATE TABLE IF NOT EXISTS " |
214 | 228 | + getCollectionTableName(collectionName) |
215 | 229 | + " (" + keyDeclaredField.getName() + " VARCHAR(255) PRIMARY KEY, " |
216 | | - + getColumnNamesAndTypes(dataDeclaredFields, supportedDataTypes) + ", " |
217 | | - + getColumnNamesAndTypes(vectorDeclaredFields, supportedVectorTypes) + ");"; |
| 230 | + + getColumnNamesAndTypes(dataDeclaredFields, getSupportedDataTypes()) + ", " |
| 231 | + + getColumnNamesAndTypes(vectorDeclaredFields, getSupportedVectorTypes()) + ");"; |
218 | 232 |
|
219 | 233 | String insertCollectionQuery = "INSERT INTO " + validateSQLidentifier(collectionsTable) |
220 | 234 | + " (collectionId) VALUES (?)"; |
|
0 commit comments