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.

Comment From: KonngExplorer

Is there a solution? I also encountered this problem.

Comment From: ytfrdfiw

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

Comment From: kingja51

    <dependency>
        <groupId>org.springframework.ai</groupId>
        <artifactId>spring-ai-elasticsearch-store-spring-boot-starter</artifactId>
    </dependency>

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

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

Comment From: kingja51

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
    </dependency>

를 같이 쓰게 되면 여기에서 또 다른 에러가 발생합니다. 정말 빨리 해결해 줘야 할 것 같습니다.