Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.springframework.ai.vectorstore.qdrant;

import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

Expand All @@ -30,6 +31,7 @@
* Utility methods for building Java objects from io.qdrant.client.grpc.JsonWithInt.Value.
*
* @author Anush Shetty
* @author Heonwoo Kim
* @since 0.8.1
*/
final class QdrantObjectFactory {
Expand All @@ -41,7 +43,11 @@ private QdrantObjectFactory() {

public static Map<String, Object> toObjectMap(Map<String, Value> payload) {
Assert.notNull(payload, "Payload map must not be null");
return payload.entrySet().stream().collect(Collectors.toMap(e -> e.getKey(), e -> object(e.getValue())));
Map<String, Object> map = new HashMap<>();
for (Map.Entry<String, Value> entry : payload.entrySet()) {
map.put(entry.getKey(), object(entry.getValue()));
}
return map;
}

private static Object object(ListValue listValue) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2023-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.ai.vectorstore.qdrant;

import java.util.Map;

import io.qdrant.client.grpc.JsonWithInt.NullValue;
import io.qdrant.client.grpc.JsonWithInt.Value;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

/**
* Tests for {@link QdrantObjectFactory}.
*
* @author Heonwoo Kim
*/

class QdrantObjectFactoryTests {

@Test
void toObjectMapShouldHandleNullValues() {
Map<String, Value> payloadWithNull = Map.of("name", Value.newBuilder().setStringValue("Spring AI").build(),
"version", Value.newBuilder().setDoubleValue(1.0).build(), "is_ga",
Value.newBuilder().setBoolValue(true).build(), "description",
Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build());

Map<String, Object> result = QdrantObjectFactory.toObjectMap(payloadWithNull);

assertThat(result).isNotNull();
assertThat(result).hasSize(4);
assertThat(result.get("name")).isEqualTo("Spring AI");
assertThat(result.get("version")).isEqualTo(1.0);
assertThat(result.get("is_ga")).isEqualTo(true);
assertThat(result).containsKey("description");
assertThat(result.get("description")).isNull();
}

}