Skip to content

Commit a7116e9

Browse files
committed
Fix NPE when metadata is null in MilvusVectorStore
Adds a null check before injecting the distance property into metadata to prevent a NullPointerException if metadata is missing from the row record. Signed-off-by: little_huang <[email protected]>
1 parent c8434a7 commit a7116e9

File tree

1 file changed

+4
-2
lines changed
  • vector-stores/spring-ai-milvus-store/src/main/java/org/springframework/ai/vectorstore/milvus

1 file changed

+4
-2
lines changed

vector-stores/spring-ai-milvus-store/src/main/java/org/springframework/ai/vectorstore/milvus/MilvusVectorStore.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,10 @@ public List<Document> doSimilaritySearch(SearchRequest request) {
379379
JsonObject metadata = new JsonObject();
380380
try {
381381
metadata = (JsonObject) rowRecord.get(this.metadataFieldName);
382-
// inject the distance into the metadata.
383-
metadata.addProperty(DocumentMetadata.DISTANCE.value(), 1 - getResultSimilarity(rowRecord));
382+
if (metadata != null) {
383+
// inject the distance into the metadata.
384+
metadata.addProperty(DocumentMetadata.DISTANCE.value(), 1 - getResultSimilarity(rowRecord));
385+
}
384386
}
385387
catch (ParamException e) {
386388
// skip the ParamException if metadata doesn't exist for the custom

0 commit comments

Comments
 (0)