api/core/app/apps/base_app_generate_response_converter.py:71 _get_simple_metadata #5714

Closed
opened 2026-02-21 18:12:17 -05:00 by yindo · 2 comments
Owner

Originally created by @haike-1213 on GitHub (Sep 21, 2024).

Originally assigned to: @JohnJyong on GitHub.

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.8

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

image

✔️ Expected Behavior

image
Issue Description: The code logic for handling the "retriever_resources" key in the metadata dictionary is incorrect. Specifically:
The code checks if "retriever_resources" exists in metadata.
If it exists, it clears the list.
It then iterates over and rebuilds the list.
Problem Reason:
The list is cleared before iteration, causing the subsequent loop to have no effect because the list is empty.
Suggested Fix:
Remove the operation that clears the list to preserve the existing data structure.
Iterate and rebuild the list as needed.
Relevant Code Snippet:

if "retriever_resources" in metadata:
    # This line clears the list
    metadata["retriever_resources"] = []
    for resource in metadata["retriever_resources"]:
        metadata["retriever_resources"].append(
            {
                "segment_id": resource["segment_id"],
                "position": resource["position"],
                "document_name": resource["document_name"],
                "score": resource["score"],
                "content": resource["content"],
            }
        )

Suggested Modified Code:

if "retriever_resources" in metadata:
    updated_resources = []
    for resource in metadata["retriever_resources"]:
        updated_resources.append(
            {
                "segment_id": resource["segment_id"],
                "position": resource["position"],
                "document_name": resource["document_name"],
                "score": resource["score"],
                "content": resource["content"],
            }
        )
    metadata["retriever_resources"] = updated_resources

Actual Behavior

image

Originally created by @haike-1213 on GitHub (Sep 21, 2024). Originally assigned to: @JohnJyong on GitHub. ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.8 ### Cloud or Self Hosted Self Hosted (Source) ### Steps to reproduce ![image](https://github.com/user-attachments/assets/9e18f776-a94a-4212-ac16-42066ecaa16b) ### ✔️ Expected Behavior ![image](https://github.com/user-attachments/assets/ce499f20-6ab8-4564-9af4-4b081a79ce2f) Issue Description: The code logic for handling the "retriever_resources" key in the metadata dictionary is incorrect. Specifically: The code checks if "retriever_resources" exists in metadata. If it exists, it clears the list. It then iterates over and rebuilds the list. Problem Reason: The list is cleared before iteration, causing the subsequent loop to have no effect because the list is empty. Suggested Fix: Remove the operation that clears the list to preserve the existing data structure. Iterate and rebuild the list as needed. Relevant Code Snippet: ``` if "retriever_resources" in metadata: # This line clears the list metadata["retriever_resources"] = [] for resource in metadata["retriever_resources"]: metadata["retriever_resources"].append( { "segment_id": resource["segment_id"], "position": resource["position"], "document_name": resource["document_name"], "score": resource["score"], "content": resource["content"], } ) ``` Suggested Modified Code: ``` if "retriever_resources" in metadata: updated_resources = [] for resource in metadata["retriever_resources"]: updated_resources.append( { "segment_id": resource["segment_id"], "position": resource["position"], "document_name": resource["document_name"], "score": resource["score"], "content": resource["content"], } ) metadata["retriever_resources"] = updated_resources ``` ### ❌ Actual Behavior ![image](https://github.com/user-attachments/assets/ecbdd1e4-0df6-4e96-9edb-8eda85e4a44e)
yindo added the 🐞 bug label 2026-02-21 18:12:17 -05:00
yindo closed this issue 2026-02-21 18:12:17 -05:00
Author
Owner

@crazywoola commented on GitHub (Sep 21, 2024):

Please use the proper md syntax to format the code.

@crazywoola commented on GitHub (Sep 21, 2024): Please use the proper md syntax to format the code.
Author
Owner

@haike-1213 commented on GitHub (Sep 21, 2024):

image
The original code is obviously meaningless?

@haike-1213 commented on GitHub (Sep 21, 2024): ![image](https://github.com/user-attachments/assets/d06def5a-7021-43ee-82cb-19d0c4412fd2) The original code is obviously meaningless?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#5714