spring-projects / spring-projects/spring-ai

Search failed in RagFlow's ElasticSearch, returned 400

Open
#3,596 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
9.5k
Forks
2.9k
Avg merge
1d 7h
Merged PRs (30d)
6

Description

Bug description

The following error occurred when connecting to RagFlow's ES and searching:

DEBUG  [    Test worker]  org.elasticsearch.client.RestClient      : request [POST http://localhost:1200/ragflow_9dd482844a7c11f0bfa74650b7bbd3b3/_search?typed_keys=true] returned [HTTP/1.1 400 Bad Request]

[es/search] failed: [search_phase_execution_exception] all shards failed
co.elastic.clients.elasticsearch._types.ElasticsearchException: [es/search] failed: [search_phase_execution_exception] all shards failed
	at co.elastic.clients.transport.ElasticsearchTransportBase.getApiResponse(ElasticsearchTransportBase.java:357)
	at co.elastic.clients.transport.ElasticsearchTransportBase.performRequest(ElasticsearchTransportBase.java:141)
	at co.elastic.clients.elasticsearch.ElasticsearchClient.search(ElasticsearchClient.java:5374)
	at co.elastic.clients.elasticsearch.ElasticsearchClient.search(ElasticsearchClient.java:5418)
	at org.springframework.ai.vectorstore.elasticsearch.ElasticsearchVectorStore.doSimilaritySearch(ElasticsearchVectorStore.java:271)
	at org.springframework.ai.vectorstore.observation.AbstractObservationVectorStore.lambda$similaritySearch$7(AbstractObservationVectorStore.java:126)
	at io.micrometer.observation.Observation.observe(Observation.java:564)
	at org.springframework.ai.vectorstore.observation.AbstractObservationVectorStore.similaritySearch(AbstractObservationVectorStore.java:125)
	at org.springframework.ai.chat.client.advisor.vectorstore.QuestionAnswerAdvisor.before(QuestionAnswerAdvisor.java:119)
	at org.springframework.ai.chat.client.advisor.api.BaseAdvisor.adviseCall(BaseAdvisor.java:51)
	at org.springframework.ai.chat.client.advisor.DefaultAroundAdvisorChain.lambda$nextCall$1(DefaultAroundAdvisorChain.java:110)
	at io.micrometer.observation.Observation.observe(Observation.java:564)
	at org.springframework.ai.chat.client.advisor.DefaultAroundAdvisorChain.nextCall(DefaultAroundAdvisorChain.java:110)
	at org.springframework.ai.chat.client.DefaultChatClient$DefaultCallResponseSpec.lambda$doGetObservableChatClientResponse$1(DefaultChatClient.java:469)
	at io.micrometer.observation.Observation.observe(Observation.java:564)
	at org.springframework.ai.chat.client.DefaultChatClient$DefaultCallResponseSpec.doGetObservableChatClientResponse(DefaultChatClient.java:467)
	at org.springframework.ai.chat.client.DefaultChatClient$DefaultCallResponseSpec.doGetObservableChatClientResponse(DefaultChatClient.java:446)
	at org.springframework.ai.chat.client.DefaultChatClient$DefaultCallResponseSpec.content(DefaultChatClient.java:441)
	at cn.edu.zhku.dxy.DxyApplicationTests.chat(DxyApplicationTests.java:60)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

However, when I use the API tool to call the search interface request, it normally returns a 200 status and has results.

Image

Environment

Java: 17
SpringBoot: 3.5.0
spring.dependency-management: 1.1.7
Spring AI: 1.0.0

vector store: ElasticSearch 8.11.3 (from RagFlow 0.19)

Steps to reproduce

  1. After starting RagFlow version 0.19 with Docker, ES8.11.3 will be included. In RagFlow, you can create a knowledge base, and after uploading and analyzing files, vectors are stored in ES.
  2. Using the API tool for querying returns results normally without any issues (RagFlow has default account password verification).
  3. In the SpringAI application, configure ES and write test code.

application.yml

spring:
  elasticsearch:
    uris: http://localhost:1200
    username: elastic
    password: infini_rag_flow
  ai:
    vectorstore:
      elasticsearch:
        initialize-schema: false
        index-name: ragflow_9dd482844a7c11f0bfa74650b7bbd3b3
        dimensions: 1024
        similarity: cosine
        embedding-field-name: q_1024_vec
    siliconflow:
      embeddingModel: BAAI/bge-large-zh-v1.5
    openai:
      api-key: sk-uoB***
      chat:
        completions-path: /v1/chat/completions
        options:
          model: gpt-4o-mini

logging:
  level:
    org.elasticsearch: debug

test

@Test
void chat() {
	PromptTemplate customPromptTemplate = PromptTemplate.builder()
		.renderer(StTemplateRenderer.builder().startDelimiterToken('<').endDelimiterToken('>').build())
		.template("""
				<query>
				
				Context information is below.
				
				---------------------
				<question_answer_context>
				---------------------
				
				Given the context information and no prior knowledge, answer the query.
				
				Follow these rules:
				
				1. If the answer is not in the context, just say that you don't know.
				2. Avoid statements like "Based on the context..." or "The provided information...".
				""")
		.build();
	
	String question = "车费报销?";
	
	QuestionAnswerAdvisor qaAdvisor = QuestionAnswerAdvisor.builder(vectorStore)
		.promptTemplate(customPromptTemplate)
		.build();
	
	String response = ChatClient.builder(chatModel).build()
		.prompt(question)
		.advisors(qaAdvisor)
		.call()
		.content();
}

Expected behavior

Return 200 and include the result.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with DxyApplicationTests.chat and application.yml, then trace the failing request through Spring AI's ElasticsearchVectorStore.doSimilaritySearch. Compare it with the successful API request and verify the Spring AI search returns HTTP 200 with results against the RagFlow index.

Written by the indexing model from the issue text.

Assessment

Tech stack
elasticsearch, java, spring
Domain
backend, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.