From 15a534909f53af7db1e15d858ac71ff6e7708966 Mon Sep 17 00:00:00 2001 From: dive2tech Date: Wed, 28 Jan 2026 01:38:03 -0500 Subject: [PATCH] fix: avoid ZeroDivisionError when fulltext column weights sum to zero (#12856) ### What problem does this PR solve? When all fulltext_search_columns use explicit weight 0 (e.g. "col^0"), weight_sum is 0 and dividing by it raises ZeroDivisionError. Use equal weights 1/n when weight_sum <= 0 and n > 0; otherwise normalize as before. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) - [x] New Feature (non-breaking change which adds functionality) - [x] Documentation Update - [x] Refactoring --- rag/utils/ob_conn.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/rag/utils/ob_conn.py b/rag/utils/ob_conn.py index 78a77e9c9..8a3ef49d4 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."