langgenius / dify

Dify is an open-source LLM app development platform. Dify's intuitive interface combines AI workflow, RAG pipeline, agent capabilities, model management, observability features and more, letting you quickly go from prototype to production.
https://dify.ai
Other
45.26k stars 6.35k forks source link

Empty citations in /messages API response for chatflow app when citations feature is enabled #6368

Open hwk68 opened 1 month ago

hwk68 commented 1 month ago

Self Checks

Dify version

0.6.14

Cloud or Self Hosted

Cloud, Self Hosted (Docker)

Steps to reproduce

  1. Create a chatflow app
  2. Use the Knowledge Retrieval node in the chatflow
  3. Enable the Citations and Attributions feature
  4. Make an API request to the /chat-messages endpoint to start a conversation, ensuring the responses contain citations(retriever_resources[])
  5. Make an API request to the /messages endpoint to retrieve the messages from the conversation in the previous step
  6. Observe that the retriever_resources[] in the response is empty

✔️ Expected Behavior

When using the /messages API endpoint for a chatflow app with the citations feature enabled in the backend, the json response should include relevant citation data in the retriever_resources[] array.

❌ Actual Behavior

When the citations feature is enabled, calling the /messages endpoint for a chatflow app results in an empty retriever_resources[] array in the json response. This issue only occurs with the chatflow(beta) API(Advanced Chat App API); the chatbot API(Chat App API) does not exhibit this problem.

screenshot:

dosubot[bot] commented 1 month ago

Hey @hwacomk68! 👋 I'm here to help you with bug fixes, answer questions, and even guide you on becoming a contributor. Let's squash those bugs together!

The /messages API endpoint returns an empty retriever_resources[] array when the citations feature is enabled because it is designed to return a list of chat history messages without including detailed citation data. In contrast, the /chat-messages endpoint includes the citation data correctly as it is designed to handle the full response of a chat message, including metadata such as retriever_resources [1][2][3].

If you need the citation data, you should use the /chat-messages endpoint, which is intended to provide the complete response, including citations.

To continue talking to Dosu, mention @dosu.

crazywoola commented 1 month ago

I guess that endpoint is missing the reference to those retrieved data.

nazeco commented 1 month ago

I have encountered the same issue.

When using the basic orchestration in a chatbot, the knowledge base references can be correctly found in both the streaming chat and the historical records.

However, when switching to chatflow orchestration, they can only be found in the knowledge-retrieval node of the streaming chat.

I checked the response of the request history interface, and it also returned an empty retriever_resources[] array.

This means that the knowledge base references are only displayed during the chat session and are lost from the chat history after refreshing the page.

nazeco commented 1 month ago

I checked #5927 .

I can found the right retriever_resources array in response event: message_end from /chat-messages.

So any way to get retriever_resources from chat history?

crazywoola commented 2 weeks ago

I guess you can add a PR for this feature. :)