Skip to content

Commit 4f67e97

Browse files
committed
Add Exceptions when getter for Id is not found
1 parent 5f9c336 commit 4f67e97

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

samples/semantickernel-concepts/semantickernel-syntax-examples/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/memory/InMemory_DataStorage.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ static class GitHubFile {
5252
@VectorStoreRecordVectorAttribute(dimensions = EMBEDDING_DIMENSIONS, indexKind = "Hnsw")
5353
private final List<Float> embedding;
5454

55-
public GitHubFile() {
56-
this(null, null, null, Collections.emptyList());
57-
}
58-
5955
public GitHubFile(
6056
String id,
6157
String description,
@@ -70,6 +66,7 @@ public GitHubFile(
7066
public String getId() {
7167
return id;
7268
}
69+
7370
public String getDescription() {
7471
return description;
7572
}

semantickernel-experimental/src/main/java/com/microsoft/semantickernel/data/VolatileVectorStoreRecordCollection.java

+22-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
// Copyright (c) Microsoft. All rights reserved.
22
package com.microsoft.semantickernel.data;
33

4-
import com.fasterxml.jackson.core.JsonProcessingException;
5-
import com.fasterxml.jackson.databind.JsonNode;
64
import com.fasterxml.jackson.databind.ObjectMapper;
75
import com.fasterxml.jackson.databind.node.ObjectNode;
86
import com.microsoft.semantickernel.data.recorddefinition.VectorStoreRecordDefinition;
97
import com.microsoft.semantickernel.data.recordoptions.DeleteRecordOptions;
108
import com.microsoft.semantickernel.data.recordoptions.GetRecordOptions;
119
import com.microsoft.semantickernel.data.recordoptions.UpsertRecordOptions;
10+
import com.microsoft.semantickernel.exceptions.SKException;
1211
import reactor.core.publisher.Mono;
1312

1413
import java.util.Collections;
@@ -143,11 +142,17 @@ public Mono<List<Record>> getBatchAsync(List<String> keys, GetRecordOptions opti
143142
@Override
144143
public Mono<String> upsertAsync(Record data, UpsertRecordOptions options) {
145144
return Mono.fromCallable(() -> {
146-
ObjectNode objectNode = objectMapper.valueToTree(data);
147-
String key = objectNode.get(recordDefinition.getKeyField().getName()).asText();
145+
try {
146+
ObjectNode objectNode = objectMapper.valueToTree(data);
147+
String key = objectNode.get(recordDefinition.getKeyField().getName()).asText();
148148

149-
getCollection().put(key, data);
150-
return key;
149+
getCollection().put(key, data);
150+
return key;
151+
} catch (Exception e) {
152+
throw new SKException(
153+
"Failure to serialize object. Ensure your model object can be serialized by Jackson, i.e the class is visible, has getters, constructor, annotations etc.",
154+
e);
155+
}
151156
});
152157
}
153158

@@ -163,10 +168,17 @@ public Mono<List<String>> upsertBatchAsync(List<Record> data, UpsertRecordOption
163168
return Mono.fromCallable(() -> {
164169
Map<String, Record> collection = getCollection();
165170
return data.stream().map(record -> {
166-
ObjectNode objectNode = objectMapper.valueToTree(record);
167-
String key = objectNode.get(recordDefinition.getKeyField().getName()).asText();
168-
collection.put(key, record);
169-
return key;
171+
try {
172+
ObjectNode objectNode = objectMapper.valueToTree(record);
173+
String key = objectNode.get(recordDefinition.getKeyField().getName()).asText();
174+
175+
collection.put(key, record);
176+
return key;
177+
} catch (Exception e) {
178+
throw new SKException(
179+
"Failure to serialize object. Ensure your model object can be serialized by Jackson, i.e the class is visible, has getters, constructor, annotations etc.",
180+
e);
181+
}
170182
}).collect(Collectors.toList());
171183
});
172184
}

0 commit comments

Comments
 (0)