fix: After enabling identity authentication in the application, the knowledge base retrieves the reference document list variable, but there is no content retrieved when asking questions on the application dialogue page#4286
Conversation
…nowledge base retrieves the reference document list variable, but there is no content retrieved when asking questions on the application dialogue page
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
| ).distinct()] | ||
|
|
||
| get_knowledge_list_of_authorized = DatabaseModelManage.get_model('get_knowledge_list_of_authorized') | ||
| chat_user_type = self.workflow_manage.get_body().get('chat_user_type') |
There was a problem hiding this comment.
This code snippet seems to be part of a Django application for querying knowledge data based on specified parameters. However, there are some improvements and corrections that can be made:
-
List Comprehension: When converting
document_id_listfrom a queryset into a list of strings using[str(k) for k in ...], it might lead to unnecessary memory usage ifdocument_id_listis already a list of ids. -
Distinct Method: The
.distinct()method should not typically include any arguments when used with values lists, so you can remove(flat=True)since the default behavior is to return unique elements. -
Consistency: Ensure consistency between variable names and their types within the function to improve readability and prevent typos.
Here's the corrected version:
def execute(self, knowledge_id_list, knowledge_setting, question, show_knowledge):
search_scope_reference = workflow_manage.build_search_scope(knowledge_id_list, knowledge_setting)
document_id_list = []
if isinstance(search_scope_reference, Document): # 文案库中的文档id数组
document_id_list.append(search_scope_reference.id)
elif isinstance(search_scope_reference, ReferenceContentBase): # 虚拟知识集(参考内容)
reference_content_base = search_scope_reference
reference_document_ids = query_set(ReferenceDocumentInfo).filter(reference_content=reference_content_base.reference_id).values_list('info_id', flat=True)
if len(reference_document_ids) == 0:
knowledge_id_list = [
str(doc.knowledge_id)
for doc in database_model.manage.get_model(get_knowledge_list_of_authorized, {}).order_by('-createdate').all()
]
else:
knowledge_id_list.extend([doc.knowledge_id for doc in query_set(Document).filter(id__in=reference_document_ids).values_list('knowledge_id', flat=True)])
else: # 搜索范围为其他类型的数据结构需要进一步处理...
# Note: Ensure proper formatting and adherence to Python best practices throughout the project.These changes ensure better performance and maintainability of the code while aligning with Django ORM conventions.
fix: After enabling identity authentication in the application, the knowledge base retrieves the reference document list variable, but there is no content retrieved when asking questions on the application dialogue page