mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
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:
@ -304,6 +304,8 @@ def meta_filter(metas: dict, filters: list[dict], logic: str = "and"):
|
|||||||
for conds in [
|
for conds in [
|
||||||
(operator == "contains", str(value).lower() in str(input).lower()),
|
(operator == "contains", str(value).lower() in str(input).lower()),
|
||||||
(operator == "not contains", str(value).lower() not 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 == "start with", str(input).lower().startswith(str(value).lower())),
|
||||||
(operator == "end with", str(input).lower().endswith(str(value).lower())),
|
(operator == "end with", str(input).lower().endswith(str(value).lower())),
|
||||||
(operator == "empty", not input),
|
(operator == "empty", not input),
|
||||||
|
|||||||
@ -35,7 +35,7 @@ You are a metadata filtering condition generator. Analyze the user's question an
|
|||||||
- Value has no match in metadata
|
- Value has no match in metadata
|
||||||
|
|
||||||
5. **Example A**:
|
5. **Example A**:
|
||||||
- User query: "上市日期七月份的有哪些商品,不要蓝色的"
|
- User query: "上市日期七月份的有哪些新品,不要蓝色的,只看鞋子和帽子"
|
||||||
- Metadata: { "color": {...}, "listing_date": {...} }
|
- Metadata: { "color": {...}, "listing_date": {...} }
|
||||||
- Output:
|
- Output:
|
||||||
{
|
{
|
||||||
@ -43,19 +43,21 @@ You are a metadata filtering condition generator. Analyze the user's question an
|
|||||||
"conditions": [
|
"conditions": [
|
||||||
{"key": "listing_date", "value": "2025-07-01", "op": "≥"},
|
{"key": "listing_date", "value": "2025-07-01", "op": "≥"},
|
||||||
{"key": "listing_date", "value": "2025-08-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**:
|
6. **Example B**:
|
||||||
- User query: "Both blue and red are acceptable."
|
- User query: "It must be from China or India. Otherwise, it must not be blue or red."
|
||||||
- Metadata: { "color": {...}, "listing_date": {...} }
|
- Metadata: { "color": {...}, "country": {...} }
|
||||||
|
-
|
||||||
- Output:
|
- Output:
|
||||||
{
|
{
|
||||||
"logic": "or",
|
"logic": "or",
|
||||||
"conditions": [
|
"conditions": [
|
||||||
{"key": "color", "value": "blue", "op": "="},
|
{"key": "color", "value": "blue, red", "op": "not in"},
|
||||||
{"key": "color", "value": "red", "op": "="}
|
{"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": [
|
"enum": [
|
||||||
"contains",
|
"contains",
|
||||||
"not contains",
|
"not contains",
|
||||||
|
"in",
|
||||||
|
"not in",
|
||||||
"start with",
|
"start with",
|
||||||
"end with",
|
"end with",
|
||||||
"empty",
|
"empty",
|
||||||
|
|||||||
Reference in New Issue
Block a user