|
2 | 2 | package com.microsoft.semantickernel.connectors.data.jdbc; |
3 | 3 |
|
4 | 4 | import com.microsoft.semantickernel.data.VectorStoreRecordCollection; |
| 5 | +import com.microsoft.semantickernel.data.VectorStoreRecordCollectionOptions; |
5 | 6 | import com.microsoft.semantickernel.data.recorddefinition.VectorStoreRecordDefinition; |
| 7 | +import com.microsoft.semantickernel.exceptions.SKException; |
6 | 8 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; |
7 | 9 | import reactor.core.publisher.Mono; |
8 | 10 | import reactor.core.scheduler.Schedulers; |
@@ -55,53 +57,42 @@ public static Builder builder() { |
55 | 57 | * Gets a collection from the vector store. |
56 | 58 | * |
57 | 59 | * @param collectionName The name of the collection. |
58 | | - * @param recordClass The class type of the record. |
59 | | - * @param recordDefinition The record definition. |
| 60 | + * @param options The options for the collection. |
60 | 61 | * @return The collection. |
61 | 62 | */ |
62 | 63 | @Override |
63 | 64 | public <Key, Record> VectorStoreRecordCollection<Key, Record> getCollection( |
64 | | - @Nonnull String collectionName, @Nonnull Class<Key> keyClass, |
65 | | - @Nonnull Class<Record> recordClass, |
66 | | - @Nullable VectorStoreRecordDefinition recordDefinition) { |
67 | | - if (keyClass != String.class) { |
68 | | - throw new IllegalArgumentException("Redis only supports string keys"); |
| 65 | + @Nonnull String collectionName, |
| 66 | + @Nonnull VectorStoreRecordCollectionOptions<Key, Record> options) { |
| 67 | + if (!options.getKeyClass().equals(String.class)) { |
| 68 | + throw new SKException("JDBC only supports string keys"); |
| 69 | + } |
| 70 | + if (options.getRecordClass() == null) { |
| 71 | + throw new SKException("Record class is required"); |
69 | 72 | } |
70 | 73 |
|
71 | | - return (VectorStoreRecordCollection<Key, Record>) getCollection( |
72 | | - collectionName, |
73 | | - recordClass, |
74 | | - recordDefinition); |
75 | | - } |
76 | | - |
77 | | - /** |
78 | | - * Gets a collection from the vector store. |
79 | | - * |
80 | | - * @param collectionName The name of the collection. |
81 | | - * @param recordClass The class type of the record. |
82 | | - * @param recordDefinition The record definition. |
83 | | - * @return The collection. |
84 | | - */ |
85 | | - public <Record> JDBCVectorStoreRecordCollection<Record> getCollection( |
86 | | - @Nonnull String collectionName, |
87 | | - @Nonnull Class<Record> recordClass, |
88 | | - @Nullable VectorStoreRecordDefinition recordDefinition) { |
89 | 74 | if (this.options != null && this.options.getVectorStoreRecordCollectionFactory() != null) { |
90 | | - return this.options.getVectorStoreRecordCollectionFactory() |
| 75 | + return (VectorStoreRecordCollection<Key, Record>) this.options |
| 76 | + .getVectorStoreRecordCollectionFactory() |
91 | 77 | .createVectorStoreRecordCollection( |
92 | 78 | dataSource, |
93 | 79 | collectionName, |
94 | | - recordClass, |
95 | | - recordDefinition); |
| 80 | + options.getRecordClass(), |
| 81 | + options.getRecordDefinition()); |
96 | 82 | } |
97 | 83 |
|
98 | | - return new JDBCVectorStoreRecordCollection<>( |
| 84 | + JDBCVectorStoreRecordCollectionOptions<Record> jdbcOptions = (JDBCVectorStoreRecordCollectionOptions<Record>) options; |
| 85 | + return (VectorStoreRecordCollection<Key, Record>) new JDBCVectorStoreRecordCollection<>( |
99 | 86 | dataSource, |
100 | 87 | collectionName, |
101 | 88 | JDBCVectorStoreRecordCollectionOptions.<Record>builder() |
102 | | - .withRecordClass(recordClass) |
103 | | - .withRecordDefinition(recordDefinition) |
104 | | - .withQueryProvider(this.queryProvider) |
| 89 | + .withCollectionsTableName(jdbcOptions.getCollectionsTableName()) |
| 90 | + .withPrefixForCollectionTables(jdbcOptions.getPrefixForCollectionTables()) |
| 91 | + .withQueryProvider(jdbcOptions.getQueryProvider() == null ? queryProvider |
| 92 | + : jdbcOptions.getQueryProvider()) |
| 93 | + .withRecordClass(jdbcOptions.getRecordClass()) |
| 94 | + .withRecordDefinition(jdbcOptions.getRecordDefinition()) |
| 95 | + .withVectorStoreRecordMapper(jdbcOptions.getVectorStoreRecordMapper()) |
105 | 96 | .build()); |
106 | 97 | } |
107 | 98 |
|
|
0 commit comments