Feat: support operator in/not in for metadata filter. (#11503)

### What problem does this PR solve?

#11376 #11378

### Type of change

- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
Kevin Hu
2025-11-25 12:44:26 +08:00
committed by GitHub
parent af72e8dc33
commit f5faf0c94f
2 changed files with 12 additions and 6 deletions

View File

@ -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),

View File

@ -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",