diff --git a/api/db/services/dialog_service.py b/api/db/services/dialog_service.py index 0a09ea532..558ba1b0f 100644 --- a/api/db/services/dialog_service.py +++ b/api/db/services/dialog_service.py @@ -304,6 +304,8 @@ def meta_filter(metas: dict, filters: list[dict], logic: str = "and"): for conds in [ (operator == "contains", str(value).lower() in str(input).lower()), (operator == "not contains", str(value).lower() not in str(input).lower()), + (operator == "in", str(input).lower() in str(value).lower()), + (operator == "not in", str(input).lower() not in str(value).lower()), (operator == "start with", str(input).lower().startswith(str(value).lower())), (operator == "end with", str(input).lower().endswith(str(value).lower())), (operator == "empty", not input), diff --git a/rag/prompts/meta_filter.md b/rag/prompts/meta_filter.md index 7df3c4885..203291071 100644 --- a/rag/prompts/meta_filter.md +++ b/rag/prompts/meta_filter.md @@ -35,7 +35,7 @@ You are a metadata filtering condition generator. Analyze the user's question an - Value has no match in metadata 5. **Example A**: - - User query: "上市日期七月份的有哪些商品,不要蓝色的" + - User query: "上市日期七月份的有哪些新品,不要蓝色的,只看鞋子和帽子" - Metadata: { "color": {...}, "listing_date": {...} } - Output: { @@ -43,19 +43,21 @@ You are a metadata filtering condition generator. Analyze the user's question an "conditions": [ {"key": "listing_date", "value": "2025-07-01", "op": "≥"}, {"key": "listing_date", "value": "2025-08-01", "op": "<"}, - {"key": "color", "value": "blue", "op": "≠"} + {"key": "color", "value": "blue", "op": "≠"}, + {"key": "category", "value": "shoes, hat", "op": "in"} ] } 6. **Example B**: - - User query: "Both blue and red are acceptable." - - Metadata: { "color": {...}, "listing_date": {...} } + - User query: "It must be from China or India. Otherwise, it must not be blue or red." + - Metadata: { "color": {...}, "country": {...} } + - - Output: { "logic": "or", "conditions": [ - {"key": "color", "value": "blue", "op": "="}, - {"key": "color", "value": "red", "op": "="} + {"key": "color", "value": "blue, red", "op": "not in"}, + {"key": "country", "value": "china, india", "op": "in"}, ] } @@ -94,6 +96,8 @@ You are a metadata filtering condition generator. Analyze the user's question an "enum": [ "contains", "not contains", + "in", + "not in", "start with", "end with", "empty",