From 00246da0df064ee39cd58ce6e9f5f1b53dce8275 Mon Sep 17 00:00:00 2001 From: yezhoujie Date: Thu, 12 Dec 2024 17:11:43 +0800 Subject: [PATCH] Bug Fix: Correct Parameter Type for KnnSearch$Builder.k Method in ElasticsearchVectorStore.java Addresses a bug in ElasticsearchVectorStore.java where an incorrect parameter type was passed to the KnnSearch$Builder.k method of the ElasticSearchClient during the execution of similaritySearch. The issue caused the following error: ``` Handler dispatch failed: java.lang.NoSuchMethodError: 'co.elastic.clients.elasticsearch._types.KnnSearch$Builder co.elastic.clients.elasticsearch._types.KnnSearch$Builder.k(java.lang.Long)' ``` Root Cause The KnnSearch$Builder.k method requires an Integer parameter, but the code passed a long value, leading to the NoSuchMethodError. ## Fix The fix involves changing the parameter type from long to Integer when calling the KnnSearch$Builder.k method. --- .../ai/vectorstore/ElasticsearchVectorStore.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vector-stores/spring-ai-elasticsearch-store/src/main/java/org/springframework/ai/vectorstore/ElasticsearchVectorStore.java b/vector-stores/spring-ai-elasticsearch-store/src/main/java/org/springframework/ai/vectorstore/ElasticsearchVectorStore.java index 2e4cef70c72..bf044436d0c 100644 --- a/vector-stores/spring-ai-elasticsearch-store/src/main/java/org/springframework/ai/vectorstore/ElasticsearchVectorStore.java +++ b/vector-stores/spring-ai-elasticsearch-store/src/main/java/org/springframework/ai/vectorstore/ElasticsearchVectorStore.java @@ -193,7 +193,7 @@ public List doSimilaritySearch(SearchRequest searchRequest) { sr -> sr.index(this.options.getIndexName()) .knn(knn -> knn.queryVector(EmbeddingUtils.toList(vectors)) .similarity(finalThreshold) - .k((long) searchRequest.getTopK()) + .k(searchRequest.getTopK()) .field("embedding") .numCandidates((long) (1.5 * searchRequest.getTopK())) .filter(fl -> fl.queryString(