Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ytfrdfiw opened this issue Feb 12, 2025 · 4 comments

Comments

@ytfrdfiw
Copy link

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.

@KonngExplorer
Copy link

Is there a solution? I also encountered this problem.

@ytfrdfiw
Copy link
Author

ytfrdfiw commented Feb 13, 2025

modify pom.xml as following:

<dependency>
            <groupId>org.springframework.ai</groupId>
            <artifactId>spring-ai-elasticsearch-store-spring-boot-starter</artifactId>
          <exclusions>
                <exclusion>
                    <groupId>co.elastic.clients</groupId>
                    <artifactId>elasticsearch-java</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

and add following:

<dependency>
             <groupId>co.elastic.clients</groupId>
             <artifactId>elasticsearch-java</artifactId>
             <version>8.13.4</version>
            <exclusions>
                <exclusion>
                    <artifactId>elasticsearch-rest-client</artifactId>
                    <groupId>org.elasticsearch.client</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <artifactId>elasticsearch-rest-client</artifactId>
            <groupId>org.elasticsearch.client</groupId>
            <version>8.13.4</version>
        </dependency>

@KonngExplorer

@kingja51
Copy link

kingja51 commented Feb 13, 2025

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.4.2</version>
    <relativePath/>
</parent>     

에서

org.springframework.ai
spring-ai-elasticsearch-store-spring-boot-starter

    <dependency>
        <groupId>co.elastic.clients</groupId>
        <artifactId>elasticsearch-java</artifactId>
        <version>8.13.3</version>
    </dependency>

사용하면 spring ai 에서는 에러가 안 납니다.
8.13.3 다른 버전을 사용하면 에러가 납니다.

@kingja51
Copy link

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.3.6</version>
    <relativePath/>
</parent>

으로 낮추면 그런 에러가 없습니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants