Skip to content

Commit 756e1ad

Browse files
committed
resolve conflict of git rebase
1 parent 219a4d8 commit 756e1ad

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

data/semantickernel-data-oracle/src/main/java/com/microsoft/semantickernel/data/jdbc/oracle/OracleVectorStoreQueryProvider.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import java.sql.SQLException;
4646
import java.time.OffsetDateTime;
4747
import java.util.ArrayList;
48+
import java.util.Arrays;
4849
import java.util.Collections;
4950
import java.util.List;
5051
import java.util.Map;
@@ -328,6 +329,25 @@ private void setUpsertStatementValues(PreparedStatement upsertStatement, Object
328329
// Some field types require special treatment to convert the java type to the
329330
// DB type
330331
if (field instanceof VectorStoreRecordVectorField) {
332+
333+
// Convert the vector field to a string
334+
if (field.getFieldType().equals(String.class)) {
335+
String json = (valueNode == null || valueNode.isNull())
336+
? null
337+
: valueNode.asText();
338+
double[] values = (json == null)
339+
? null
340+
: objectMapper.readValue(json, double[].class);
341+
342+
int dim = ((VectorStoreRecordVectorField) field).getDimensions();
343+
if (values != null && values.length != dim) {
344+
throw new SKException("Vector dimension mismatch: expected " + dim);
345+
}
346+
347+
upsertStatement.setObject(i + 1, values, OracleTypes.VECTOR_FLOAT32);
348+
continue;
349+
}
350+
331351
// If the vector field is not set as a string convert to an array of doubles
332352
// and set the value
333353
if (!field.getFieldType().equals(String.class)) {
@@ -336,6 +356,7 @@ private void setUpsertStatementValues(PreparedStatement upsertStatement, Object
336356
: StreamSupport.stream((
337357
(ArrayNode)valueNode).spliterator(), false)
338358
.mapToDouble(d -> d.asDouble()).toArray();
359+
339360
upsertStatement.setObject(i + 1, values, OracleTypes.VECTOR_FLOAT32);
340361
continue;
341362
}

data/semantickernel-data-oracle/src/main/java/com/microsoft/semantickernel/data/jdbc/oracle/OracleVectorStoreRecordMapper.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
package com.microsoft.semantickernel.data.jdbc.oracle;
88

9+
import com.fasterxml.jackson.core.JsonProcessingException;
910
import com.fasterxml.jackson.databind.JsonNode;
1011
import com.fasterxml.jackson.databind.ObjectMapper;
1112
import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -210,6 +211,17 @@ public OracleVectorStoreRecordMapper<Record> build() {
210211
}
211212
if (options != null && options.isIncludeVectors()) {
212213
for (VectorStoreRecordVectorField field : vectorStoreRecordDefinition.getVectorFields()) {
214+
215+
// String vector
216+
if (field.getFieldType().equals(String.class)) {
217+
float[] arr = resultSet.getObject(field.getEffectiveStorageName(), float[].class);
218+
String str = (arr == null)
219+
? null
220+
: objectMapper.writeValueAsString(arr);
221+
objectNode.put(field.getEffectiveStorageName(), str);
222+
continue;
223+
}
224+
213225
Object value = resultSet.getObject(field.getEffectiveStorageName(), float[].class);
214226
JsonNode genericNode = objectMapper.valueToTree(value);
215227
objectNode.set(field.getEffectiveStorageName(), genericNode);
@@ -227,6 +239,8 @@ public OracleVectorStoreRecordMapper<Record> build() {
227239
throw new SKException(
228240
"Failure to serialize object, by default the JDBC connector uses Jackson, ensure your model object can be serialized by Jackson, i.e the class is visible, has getters, constructor, annotations etc.",
229241
e);
242+
} catch (JsonProcessingException e) {
243+
throw new RuntimeException(e);
230244
}
231245
});
232246
}

0 commit comments

Comments
 (0)