Skip to content

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

Fix some comments - TODO: rename "Prefetch size" -> rerank candidates (#18705)

Wang Qic0dcc6ea289b
diff --git a/internal/service/chat_pipeline.go b/internal/service/chat_pipeline.go
index faa595c114..a17bc04dc7 100644
--- a/internal/service/chat_pipeline.go
+++ b/internal/service/chat_pipeline.go
@@ -614,6 +614,9 @@ func (s *ChatPipelineService) AsyncChat(
}
var knowledges []string
prefetchSize := int(chat.PrefetchSize)
+ if prefetchSize <= 0 {
+ prefetchSize = 64
+ }
// When hasKnowledgeParam is true, runs (mutually exclusive):
// a) If reasoning is enabled: DeepResearcher replaces vector retrieval.
diff --git a/internal/service/nlp/retrieval.go b/internal/service/nlp/retrieval.go
index b2b45a3979..7805c35cf1 100644
--- a/internal/service/nlp/retrieval.go
+++ b/internal/service/nlp/retrieval.go
@@ -76,6 +76,8 @@ type RetrievalResult struct {
// - Prefetch candidates for reranking
// - Perform reranking via Rerank()
// - Sort indices by score descending and filter by threshold
+// - Require Page * PageSize to fit within PrefetchSize
+// - Support only the first page when a rerank model is configured
// - Calculate pagination to extract actual page returned from reranked results
// - Build chunks
// - Build document aggregation if specified
@@ -115,16 +117,12 @@ func (s *RetrievalService) Retrieval(ctx context.Context, req *RetrievalRequest)
pageSize := req.PageSize
prefetchSize := *req.PrefetchSize
if prefetchSize <= 0 || req.Page > prefetchSize/pageSize {
- requiredSize := "overflow"
- if req.Page <= int(^uint(0)>>1)/pageSize {
- requiredSize = strconv.Itoa(req.Page * pageSize)
- }
- return nil, fmt.Errorf("prefetch_size(%d) must be greater than page * page_size(%s) to ensure correct pagination", prefetchSize, requiredSize)
+ return nil, fmt.Errorf("prefetch_size(%d) must be greater than or equal to page(%d) * page_size(%d)", prefetchSize, req.Page, pageSize)
}
if req.RerankModel != nil && req.Page != 1 {
return nil, fmt.Errorf("Pagination is not supported when rerank_mdl is specified. Please set page=1 to retrieve the top %d results.", pageSize)
}
- common.Info("Retrieval prefetch params", zap.Int("page", req.Page), zap.Int("pageSize", pageSize), zap.Int("prefetchSize", prefetchSize))
+ common.Debug("Retrieval prefetch params", zap.Int("page", req.Page), zap.Int("pageSize", pageSize), zap.Int("prefetchSize", prefetchSize))
// Execute search via Search()
searchReq := &RetrievalSearchRequest{
diff --git a/rag/nlp/search.py b/rag/nlp/search.py
index 6acf475247..a84192d413 100644
--- a/rag/nlp/search.py
+++ b/rag/nlp/search.py
@@ -606,7 +606,7 @@ class Dealer:
}
if isinstance(must_not, dict) and must_not:
req["must_not"] = must_not
- logging.info(f"[Search] page={page}, page_size={page_size}, prefetch_size={prefetch_size}")
+ logging.debug(f"[Search] page={page}, page_size={page_size}, prefetch_size={prefetch_size}")
if isinstance(tenant_ids, str):
tenant_ids = tenant_ids.split(",")