Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

FIX:ZeroDivisionError when using large page_size in client.retrieve() (#7595)

Stephen Hu573d46a4ef22
diff --git a/api/apps/api_app.py b/api/apps/api_app.py
index 27e1606dea..cc417c9a22 100644
--- a/api/apps/api_app.py
+++ b/api/apps/api_app.py
@@ -861,7 +861,7 @@ def retrieval():
doc_ids = req.get("doc_ids", [])
question = req.get("question")
page = int(req.get("page", 1))
- size = int(req.get("size", 30))
+ size = int(req.get("page_size", 30))
similarity_threshold = float(req.get("similarity_threshold", 0.2))
vector_similarity_weight = float(req.get("vector_similarity_weight", 0.3))
top = int(req.get("top_k", 1024))
diff --git a/rag/nlp/search.py b/rag/nlp/search.py
index dbf451d7cb..c37b956f67 100644
--- a/rag/nlp/search.py
+++ b/rag/nlp/search.py
@@ -355,6 +355,8 @@ class Dealer:
RERANK_LIMIT = 64
RERANK_LIMIT = int(RERANK_LIMIT//page_size + ((RERANK_LIMIT%page_size)/(page_size*1.) + 0.5)) * page_size if page_size>1 else 1
+ if RERANK_LIMIT < 1: ## when page_size is very large the RERANK_LIMIT will be 0.
+ RERANK_LIMIT = 1
req = {"kb_ids": kb_ids, "doc_ids": doc_ids, "page": math.ceil(page_size*page/RERANK_LIMIT), "size": RERANK_LIMIT,
"question": question, "vector": True, "topk": top,
"similarity": similarity_threshold,