From 8449986d57282d69629a3e89cf3503e134c32e94 Mon Sep 17 00:00:00 2001 From: Ilayaperumal Gopinathan Date: Thu, 15 May 2025 09:04:47 +0100 Subject: [PATCH] Fix qdrant vector store value factory - Fix the QdrantValueFactory to handle "java.util.List" type - Update the integration test to use List type values Resolves #3164 Signed-off-by: Ilayaperumal Gopinathan --- .../ai/vectorstore/qdrant/QdrantValueFactory.java | 15 +++++++++++++++ .../vectorstore/qdrant/QdrantVectorStoreIT.java | 5 +++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/vector-stores/spring-ai-qdrant-store/src/main/java/org/springframework/ai/vectorstore/qdrant/QdrantValueFactory.java b/vector-stores/spring-ai-qdrant-store/src/main/java/org/springframework/ai/vectorstore/qdrant/QdrantValueFactory.java index 336384ae66b..b328f418985 100644 --- a/vector-stores/spring-ai-qdrant-store/src/main/java/org/springframework/ai/vectorstore/qdrant/QdrantValueFactory.java +++ b/vector-stores/spring-ai-qdrant-store/src/main/java/org/springframework/ai/vectorstore/qdrant/QdrantValueFactory.java @@ -32,6 +32,7 @@ * Utility methods for building io.qdrant.client.grpc.JsonWithInt.Value from Java objects. * * @author Anush Shetty + * @author Ilayaperumal Gopinathan * @since 0.8.1 */ final class QdrantValueFactory { @@ -65,6 +66,10 @@ private static Value value(Object value) { return value((Map) value); } + if (value instanceof List) { + return value((List) value); + } + switch (value.getClass().getSimpleName()) { case "String": return ValueFactory.value((String) value); @@ -81,6 +86,16 @@ private static Value value(Object value) { } } + private static Value value(List elements) { + List values = new ArrayList(elements.size()); + + for (Object element : elements) { + values.add(value(element)); + } + + return ValueFactory.list(values); + } + private static Value value(Object[] elements) { List values = new ArrayList(elements.length); diff --git a/vector-stores/spring-ai-qdrant-store/src/test/java/org/springframework/ai/vectorstore/qdrant/QdrantVectorStoreIT.java b/vector-stores/spring-ai-qdrant-store/src/test/java/org/springframework/ai/vectorstore/qdrant/QdrantVectorStoreIT.java index 9b90d518a13..004bf32d226 100644 --- a/vector-stores/spring-ai-qdrant-store/src/test/java/org/springframework/ai/vectorstore/qdrant/QdrantVectorStoreIT.java +++ b/vector-stores/spring-ai-qdrant-store/src/test/java/org/springframework/ai/vectorstore/qdrant/QdrantVectorStoreIT.java @@ -79,10 +79,11 @@ public class QdrantVectorStoreIT extends BaseVectorStoreTests { List documents = List.of( new Document("Spring AI rocks!! Spring AI rocks!! Spring AI rocks!! Spring AI rocks!! Spring AI rocks!!", Collections.singletonMap("meta1", "meta1")), - new Document("Hello World Hello World Hello World Hello World Hello World Hello World Hello World"), + new Document("Hello World Hello World Hello World Hello World Hello World Hello World Hello World", + Collections.singletonMap("meta1", List.of("meta-list"))), new Document( "Great Depression Great Depression Great Depression Great Depression Great Depression Great Depression", - Collections.singletonMap("meta2", "meta2"))); + Collections.singletonMap("meta2", List.of("meta-list")))); @BeforeAll static void setup() throws InterruptedException, ExecutionException {