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.

Resolve 8475 support rerank model from infinity (#10939)

LastHopeOfGPNU1a6b961b5f63
diff --git a/api/core/model_runtime/model_providers/openai_api_compatible/rerank/rerank.py b/api/core/model_runtime/model_providers/openai_api_compatible/rerank/rerank.py
index 508da4bf209..407dc7190ee 100644
--- a/api/core/model_runtime/model_providers/openai_api_compatible/rerank/rerank.py
+++ b/api/core/model_runtime/model_providers/openai_api_compatible/rerank/rerank.py
@@ -64,7 +64,7 @@ class OAICompatRerankModel(RerankModel):
# TODO: Do we need truncate docs to avoid llama.cpp return error?
- data = {"model": model_name, "query": query, "documents": docs, "top_n": top_n}
+ data = {"model": model_name, "query": query, "documents": docs, "top_n": top_n, "return_documents": True}
try:
response = post(str(URL(url) / "rerank"), headers=headers, data=dumps(data), timeout=60)
@@ -83,7 +83,13 @@ class OAICompatRerankModel(RerankModel):
index = result["index"]
# Retrieve document text (fallback if llama.cpp rerank doesn't return it)
- text = result.get("document", {}).get("text", docs[index])
+ text = docs[index]
+ document = result.get("document", {})
+ if document:
+ if isinstance(document, dict):
+ text = document.get("text", docs[index])
+ elif isinstance(document, str):
+ text = document
# Normalize the score
normalized_score = (result["relevance_score"] - min_score) / score_range