Skip to content

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

fix(serenedb): keep the available_int=0 chunk filter (#18928)

MarMar Labs020f1d3b1647
diff --git a/rag/utils/serenedb_conn.py b/rag/utils/serenedb_conn.py
index d983eba2b0..b35ddd6c6a 100644
--- a/rag/utils/serenedb_conn.py
+++ b/rag/utils/serenedb_conn.py
@@ -309,6 +309,12 @@ class SereneDBConnection(DocStoreConnection):
def _get_filters(self, condition: dict) -> list[str]:
filters = []
for k, v in condition.items():
+ if k == "available_int":
+ # Handled before the falsy skip below: 0 is the "disabled only" filter, and
+ # skipping it drops the predicate entirely rather than narrowing the result.
+ # NULL counts as available, matching DEFAULTS and the other backends.
+ filters.append(f"COALESCE(available_int, 1) {'< 1' if v == 0 else '>= 1'}")
+ continue
if not v:
continue
if k == "exists":
diff --git a/test/unit_test/rag/utils/test_serenedb_conn.py b/test/unit_test/rag/utils/test_serenedb_conn.py
index b925512dc7..97537bae96 100644
--- a/test/unit_test/rag/utils/test_serenedb_conn.py
+++ b/test/unit_test/rag/utils/test_serenedb_conn.py
@@ -94,3 +94,9 @@ class TestGetFilters:
def test_unknown_and_empty_are_skipped(self):
assert self.filters({"not_a_column": "x", "doc_id": ""}) == []
+
+ def test_available_int_keeps_the_zero_predicate(self):
+ # 0 is the "disabled only" filter and is falsy, so the generic empty-value skip in
+ # _get_filters would drop the predicate and widen the result instead of narrowing it.
+ assert self.filters({"available_int": 0}) == ["COALESCE(available_int, 1) < 1"]
+ assert self.filters({"available_int": 1}) == ["COALESCE(available_int, 1) >= 1"]