Description
Bug description
When I use es8.15.5 as the vector storage of rag, and then use the following to conduct a local conversation, the following error is reported
java.lang.NoSuchMethodError: 'co.elastic.clients.elasticsearch._types.KnnSearch$Builder co.elastic.clients.elasticsearch._types.KnnSearch$Builder.k(java.lang.Long)'
Environment
spring-ai version: 1.0.0-M5
os: windows 10
jdk: 21
es:8.15.5(8.17.1 as same)
Through the java stack, I have found the cause of the problem. It is because 1.0.0-M5 integrates the elasticsearch-java.jar and elasticsearch-rest-client.jar of 8.15.5 by default. This version no longer has the long version of the .k method. Only 8.13.4 and previous versions have it.
the root cause as following:
when I use String content = chatClient.prompt().user(message).call().content();
will invoke method as
org.springframework.ai.vectorstore.elasticsearch.ElasticsearchVectorStore#doSimilaritySearch
SearchResponse res = this.elasticsearchClient.search(
sr -> sr.index(this.options.getIndexName())
.knn(knn -> knn.queryVector(EmbeddingUtils.toList(vectors))
.similarity(finalThreshold)
.k((long) searchRequest.getTopK())
.field("embedding")
.numCandidates((long) (1.5 * searchRequest.getTopK()))
.filter(fl -> fl.queryString(
qs -> qs.query(getElasticsearchQueryString(searchRequest.getFilterExpression()))))),
Document.class);
Versions elasticsearch-java-8.13.4.jar .k() function prototype as following,
co.elastic.clients.elasticsearch._types.KnnSearch.Builder#k
public final Builder k(@nullable Long value) {
this.k = value;
return this;
}
but 8.14 and higher prototype as:
co.elastic.clients.elasticsearch._types.KnnSearch.Builder#k
public final Builder k(@nullable Integer value) {
this.k = value;
return this;
}
Therefore, I think it is caused by the mismatch between elasticsearch-java.jar and elasticsearch-rest-client.jar versions. Please refer to whether the version should be lowered or modified by modifying the org.springframework.ai.vectorstore.elasticsearch.ElasticsearchVectorStore#doSimilaritySearch function.
Please forgive me if the above is incorrect. @rozza