From 573d46a4ef22b745c45dc0ce766b78e4b434d371 Mon Sep 17 00:00:00 2001 From: Stephen Hu Date: Tue, 13 May 2025 10:46:31 +0800 Subject: [PATCH] FIX:ZeroDivisionError when using large page_size in client.retrieve() (#7595) ### What problem does this PR solve? Close #7592 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- api/apps/api_app.py | 2 +- rag/nlp/search.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/api/apps/api_app.py b/api/apps/api_app.py index 27e1606de..cc417c9a2 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 dbf451d7c..c37b956f6 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,