check rerank document is not empty (#1740)

Co-authored-by: jyong <jyong@dify.ai>
This commit is contained in:
Jyong 2023-12-11 16:12:11 +08:00 committed by GitHub
parent 994fceece3
commit d5695b3170
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -24,7 +24,10 @@ class CohereReranking(BaseReranking):
super().__init__(model_provider, client, name)
def rerank(self, query: str, documents: List[Document], score_threshold: Optional[float], top_k: Optional[int]) -> Optional[List[Document]]:
def rerank(self, query: str, documents: List[Document], score_threshold: Optional[float], top_k: Optional[int]) -> \
Optional[List[Document]]:
if not documents:
return []
docs = []
doc_id = []
unique_documents = []
@ -34,7 +37,7 @@ class CohereReranking(BaseReranking):
docs.append(document.page_content)
unique_documents.append(document)
documents = unique_documents
results = self.client.rerank(query=query, documents=docs, model=self.name, top_n=top_k)
rerank_documents = []

View File

@ -21,6 +21,8 @@ class XinferenceReranking(BaseReranking):
super().__init__(model_provider, client, name)
def rerank(self, query: str, documents: List[Document], score_threshold: Optional[float], top_k: Optional[int]) -> Optional[List[Document]]:
if not documents:
return []
docs = []
doc_id = []
unique_documents = []