RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
fix(#14389): normalize list metadata values for in filters (#14410)
Shiyao Huang406b36a4529d
diff --git a/common/metadata_utils.py b/common/metadata_utils.pyindex f767b3bd58..79db193ebe 100644--- a/common/metadata_utils.py+++ b/common/metadata_utils.py@@ -42,6 +42,13 @@ def convert_conditions(metadata_condition):def meta_filter(metas: dict, filters: list[dict], logic: str = "and"):doc_ids = set([])+ def normalize_string_values(value):+ if isinstance(value, str):+ return value.lower()+ if isinstance(value, list):+ return [item.lower() if isinstance(item, str) else item for item in value]+ return value+def filter_out(v2docs, operator, value):ids = []for input, docids in v2docs.items():@@ -96,14 +103,8 @@ def meta_filter(metas: dict, filters: list[dict], logic: str = "and"):value = value.lower()else:# Non-comparison operators: maintain original logic- if isinstance(input, str):- input = input.lower()- elif operator in ("in", "not in") and isinstance(input, list):- input = [x.lower() if isinstance(x, str) else x for x in input]- if isinstance(value, str):- value = value.lower()- elif operator in ("in", "not in") and isinstance(value, list):- value = [x.lower() if isinstance(x, str) else x for x in value]+ input = normalize_string_values(input)+ value = normalize_string_values(value)matched = Falsetry:diff --git a/test/unit_test/common/test_metadata_filter_operators.py b/test/unit_test/common/test_metadata_filter_operators.pyindex 90ee64e311..23f4c2b643 100644--- a/test/unit_test/common/test_metadata_filter_operators.py+++ b/test/unit_test/common/test_metadata_filter_operators.py@@ -33,6 +33,20 @@ def test_not_in_operator():assert meta_filter(metas, filters) == ["doc3"]+def test_in_operator_with_list_value_is_case_insensitive():+ metas = {"product": {"F2": ["doc1"], "F11": ["doc2"], "G1": ["doc3"]}}+ filters = [{"key": "product", "op": "in", "value": ["F2", "F11"]}]++ assert set(meta_filter(metas, filters)) == {"doc1", "doc2"}+++def test_not_in_operator_with_list_value_is_case_insensitive():+ metas = {"product": {"F2": ["doc1"], "F11": ["doc2"], "G1": ["doc3"]}}+ filters = [{"key": "product", "op": "not in", "value": ["F2", "F11"]}]++ assert meta_filter(metas, filters) == ["doc3"]++def test_start_with():# returns chunk where the metadata starts with the valuemetas = {"name": {"prefix_value": ["doc1"], "other": ["doc2"]}}