Skip to content

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

fix: avoid ZeroDivisionError when fulltext column weights sum to zero (#12856)

dive2tech15a534909f53
diff --git a/rag/utils/ob_conn.py b/rag/utils/ob_conn.py
index 78a77e9c99..8a3ef49d43 100644
--- a/rag/utils/ob_conn.py
+++ b/rag/utils/ob_conn.py
@@ -928,8 +928,14 @@ class OBConnection(DocStoreConnection):
# adjust the weight to 0~1
weight_sum = sum(fulltext_search_weight.values())
- for column_name in fulltext_search_weight.keys():
- fulltext_search_weight[column_name] = fulltext_search_weight[column_name] / weight_sum
+ n = len(fulltext_search_weight)
+ if weight_sum <= 0 and n > 0:
+ # All weights are 0 (e.g. "col^0"); use equal weights to avoid ZeroDivisionError
+ for column_name in fulltext_search_weight:
+ fulltext_search_weight[column_name] = 1.0 / n
+ else:
+ for column_name in fulltext_search_weight:
+ fulltext_search_weight[column_name] = fulltext_search_weight[column_name] / weight_sum
elif isinstance(m, MatchDenseExpr):
assert m.embedding_data_type == "float", f"embedding data type '{m.embedding_data_type}' is not float."