Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix weight rerank of knowledge retrieval (#10931)

AkisAyacb0c55daa7bf
diff --git a/api/core/rag/rerank/rerank_model.py b/api/core/rag/rerank/rerank_model.py
index fc82b2080b2..6ae432a526b 100644
--- a/api/core/rag/rerank/rerank_model.py
+++ b/api/core/rag/rerank/rerank_model.py
@@ -27,11 +27,11 @@ class RerankModelRunner(BaseRerankRunner):
:return:
"""
docs = []
- doc_id = set()
+ doc_ids = set()
unique_documents = []
for document in documents:
- if document.provider == "dify" and document.metadata["doc_id"] not in doc_id:
- doc_id.add(document.metadata["doc_id"])
+ if document.provider == "dify" and document.metadata["doc_id"] not in doc_ids:
+ doc_ids.add(document.metadata["doc_id"])
docs.append(document.page_content)
unique_documents.append(document)
elif document.provider == "external":
diff --git a/api/core/rag/rerank/weight_rerank.py b/api/core/rag/rerank/weight_rerank.py
index b706f29bb18..4719be012f9 100644
--- a/api/core/rag/rerank/weight_rerank.py
+++ b/api/core/rag/rerank/weight_rerank.py
@@ -37,11 +37,10 @@ class WeightRerankRunner(BaseRerankRunner):
:return:
"""
unique_documents = []
- doc_id = set()
+ doc_ids = set()
for document in documents:
- doc_id = document.metadata.get("doc_id")
- if doc_id not in doc_id:
- doc_id.add(doc_id)
+ if document.metadata["doc_id"] not in doc_ids:
+ doc_ids.add(document.metadata["doc_id"])
unique_documents.append(document)
documents = unique_documents