fix multi retrieval with resource score issue (#1578)

Co-authored-by: jyong <jyong@dify.ai>
This commit is contained in:
Jyong 2023-11-21 13:47:55 +08:00 committed by GitHub
parent 519fb90d5a
commit 0d9ce1bab0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View File

@ -80,6 +80,9 @@ class DatasetMultiRetrieverTool(BaseTool):
hit_callback = DatasetIndexToolCallbackHandler(self.conversation_message_task)
hit_callback.on_tool_end(all_documents)
document_score_list = {}
for item in all_documents:
document_score_list[item.metadata['doc_id']] = item.metadata['score']
document_context_list = []
index_node_ids = [document.metadata['doc_id'] for document in all_documents]
@ -120,8 +123,10 @@ class DatasetMultiRetrieverTool(BaseTool):
'document_name': document.name,
'data_source_type': document.data_source_type,
'segment_id': segment.id,
'retriever_from': self.retriever_from
'retriever_from': self.retriever_from,
'score': document_score_list.get(segment.index_node_id, None)
}
if self.retriever_from == 'dev':
source['hit_count'] = segment.hit_count
source['word_count'] = segment.word_count

View File

@ -196,10 +196,10 @@ class DatasetRetrieverTool(BaseTool):
'document_name': document.name,
'data_source_type': document.data_source_type,
'segment_id': segment.id,
'retriever_from': self.retriever_from
'retriever_from': self.retriever_from,
'score': document_score_list.get(segment.index_node_id, None)
}
if dataset.indexing_technique != "economy":
source['score'] = document_score_list.get(segment.index_node_id)
if self.retriever_from == 'dev':
source['hit_count'] = segment.hit_count
source['word_count'] = segment.word_count