In chat mode, the conversation hits the knowledge base search error #6087

Closed
opened 2026-02-21 18:14:01 -05:00 by yindo · 5 comments
Owner

Originally created by @jlokys on GitHub (Oct 14, 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.9.2

Cloud or Self Hosted

Self Hosted (Docker), Self Hosted (Source)

Steps to reproduce

Upgraded version to 0.9.2
In chat mode, the conversation hits the knowledge base search error, as follows:

Traceback (most recent call last):
  File "E:\wsm\dify\api\core\app\apps\chat\app_generator.py", line 203, in _generate_worker
    runner.run(
  File "E:\wsm\dify\api\core\app\apps\chat\app_runner.py", line 159, in run
    context = dataset_retrieval.retrieve(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\wsm\dify\api\core\rag\retrieval\dataset_retrieval.py", line 235, in retrieve
    retrieval_resource_list = sorted(retrieval_resource_list, key=lambda x: x.get("score"), reverse=True)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: '<' not supported between instances of 'NoneType' and 'NoneType'

The index mode of the knowledge base settings is set to Economical, and there is no score field in the search results, and an error is reported during subsequent execution.
image

✔️ Expected Behavior

No response

Actual Behavior

No response

Originally created by @jlokys on GitHub (Oct 14, 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.9.2 ### Cloud or Self Hosted Self Hosted (Docker), Self Hosted (Source) ### Steps to reproduce Upgraded version to 0.9.2 In chat mode, the conversation hits the knowledge base search error, as follows: ``` Traceback (most recent call last): File "E:\wsm\dify\api\core\app\apps\chat\app_generator.py", line 203, in _generate_worker runner.run( File "E:\wsm\dify\api\core\app\apps\chat\app_runner.py", line 159, in run context = dataset_retrieval.retrieve( ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\wsm\dify\api\core\rag\retrieval\dataset_retrieval.py", line 235, in retrieve retrieval_resource_list = sorted(retrieval_resource_list, key=lambda x: x.get("score"), reverse=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: '<' not supported between instances of 'NoneType' and 'NoneType' ``` The index mode of the knowledge base settings is set to Economical, and there is no score field in the search results, and an error is reported during subsequent execution. ![image](https://github.com/user-attachments/assets/8cd15b02-8ad9-4ad5-9bd0-972be52172a0) ### ✔️ Expected Behavior _No response_ ### ❌ Actual Behavior _No response_
yindo added the 🐞 bug🤔 cant-reproduce labels 2026-02-21 18:14:01 -05:00
yindo closed this issue 2026-02-21 18:14:01 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Oct 14, 2024):

The error you're encountering is due to NoneType values in the retrieval_resource_list when attempting to sort it by the "score" attribute. This happens because the list contains elements where the "score" is None, leading to a TypeError during sorting.

To resolve this, you can modify the sorting logic to handle None values. One approach is to provide a default value for None scores during sorting, like this:

retrieval_resource_list = sorted(
    retrieval_resource_list, 
    key=lambda x: x.get("score", 0),  # Use a default score of 0 for None values
    reverse=True
)

This change ensures that any None scores are treated as zero, preventing the TypeError from occurring.

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Oct 14, 2024): <!-- Answer --> The error you're encountering is due to `NoneType` values in the `retrieval_resource_list` when attempting to sort it by the `"score"` attribute. This happens because the list contains elements where the `"score"` is `None`, leading to a `TypeError` during sorting. To resolve this, you can modify the sorting logic to handle `None` values. One approach is to provide a default value for `None` scores during sorting, like this: ```python retrieval_resource_list = sorted( retrieval_resource_list, key=lambda x: x.get("score", 0), # Use a default score of 0 for None values reverse=True ) ``` This change ensures that any `None` scores are treated as zero, preventing the `TypeError` from occurring. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@crazywoola commented on GitHub (Oct 14, 2024):

https://github.com/langgenius/dify/pull/9155

@crazywoola commented on GitHub (Oct 14, 2024): https://github.com/langgenius/dify/pull/9155
Author
Owner

@zykee commented on GitHub (Oct 14, 2024):

I miss the same problem, and I deploy it with docker.

@zykee commented on GitHub (Oct 14, 2024): I miss the same problem, and I deploy it with docker.
Author
Owner

@tearfulDalvik commented on GitHub (Oct 15, 2024):

same problem

@tearfulDalvik commented on GitHub (Oct 15, 2024): same problem
Author
Owner

@wangxm345566462 commented on GitHub (Oct 16, 2024):

same problem
image

@wangxm345566462 commented on GitHub (Oct 16, 2024): same problem ![image](https://github.com/user-attachments/assets/b9ebe5c3-5197-4e83-9954-ab02c8de64ad)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#6087