Skip to content

When version 1.0.0-M5 uses elastic as vectorstore, the query will report that the method cannot be found #2220

Closed
@ytfrdfiw

Description

@ytfrdfiw

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)'

Image

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions