fix retrieval resource positon missed (#9155)

Co-authored-by: Bowen Liang <liangbowen@gf.com.cn>
This commit is contained in:
Jyong 2024-10-11 10:32:42 +08:00 committed by GitHub
parent a34891851b
commit cabdb4ef17
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 1 deletions

View File

@ -1,3 +1,5 @@
from typing import Optional
from pydantic import BaseModel
@ -7,4 +9,4 @@ class DocumentContext(BaseModel):
"""
content: str
score: float
score: Optional[float] = None

View File

@ -231,6 +231,9 @@ class DatasetRetrieval:
source["content"] = segment.content
retrieval_resource_list.append(source)
if hit_callback and retrieval_resource_list:
retrieval_resource_list = sorted(retrieval_resource_list, key=lambda x: x.get("score"), reverse=True)
for position, item in enumerate(retrieval_resource_list, start=1):
item["position"] = position
hit_callback.return_retriever_resource_info(retrieval_resource_list)
if document_context_list:
document_context_list = sorted(document_context_list, key=lambda x: x.score, reverse=True)