Skip to content

Commit f0d4cbf

Browse files
solnoneilayaperumalg
authored andcommitted
fix(qdrant): support Long type in payload by converting to String
Qdrant does not support java.lang.Long as a native payload type. Previously, passing a Long value caused the following exception: java.lang.IllegalArgumentException: Unsupported Qdrant value type: class java.lang.Long at org.springframework.ai.vectorstore.qdrant.QdrantValueFactory.value(QdrantValueFactory.java:85) at org.springframework.ai.vectorstore.qdrant.QdrantValueFactory.lambda$toValueMap$1(QdrantValueFactory.java:46) ... To resolve this, Long values are now converted to their String representation in QdrantValueFactory. This preserves precision and avoids serialization issues. test(qdrant): add test to verify Long metadata values are stored as String Adds a test to ensure that Long values in document metadata are safely converted to String before being stored in Qdrant. The test inserts a document with a Long-type "ref_id", performs a similarity search, and verifies that: - the result is not empty, - the retrieved "ref_id" is a String, - the value matches the original Long when parsed. Also ensures cleanup by deleting the inserted document from the store. Auto-cherry-pick to 1.0.x Signed-off-by: Solomon Hsu <solnone@gmail.com>
1 parent cecc046 commit f0d4cbf

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

vector-stores/spring-ai-qdrant-store/src/main/java/org/springframework/ai/vectorstore/qdrant/QdrantValueFactory.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ private static Value value(Object value) {
7575
return ValueFactory.value((String) value);
7676
case "Integer":
7777
return ValueFactory.value((Integer) value);
78+
case "Long":
79+
// use String representation
80+
return ValueFactory.value(String.valueOf(value));
7881
case "Double":
7982
return ValueFactory.value((Double) value);
8083
case "Float":

vector-stores/spring-ai-qdrant-store/src/test/java/org/springframework/ai/vectorstore/qdrant/QdrantVectorStoreIT.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,27 @@ void getNativeClientTest() {
314314
});
315315
}
316316

317+
@Test
318+
void shouldConvertLongToString() {
319+
this.contextRunner.run(context -> {
320+
QdrantVectorStore vectorStore = context.getBean(QdrantVectorStore.class);
321+
var refId = System.currentTimeMillis();
322+
var doc = new Document("Long type ref_id", Map.of("ref_id", refId));
323+
vectorStore.add(List.of(doc));
324+
325+
List<Document> results = vectorStore
326+
.similaritySearch(SearchRequest.builder().query("Long type ref_id").topK(1).build());
327+
assertThat(results).hasSize(1);
328+
Document resultDoc = results.get(0);
329+
var resultRefId = resultDoc.getMetadata().get("ref_id");
330+
assertThat(resultRefId).isInstanceOf(String.class);
331+
assertThat(Double.valueOf((String) resultRefId)).isEqualTo(refId);
332+
333+
// Remove all documents from the store
334+
vectorStore.delete(List.of(resultDoc.getId()));
335+
});
336+
}
337+
317338
@SpringBootConfiguration
318339
public static class TestApplication {
319340

0 commit comments

Comments
 (0)