Quellcode durchsuchen

feat: support metadata condition filter string array (#23111)

Signed-off-by: kenwoodjw <blackxin55+@gmail.com>
tags/1.7.2
kenwoodjw vor 3 Monaten
Ursprung
Commit
28478cdc41
Es ist kein Account mit der E-Mail-Adresse des Committers verbunden

+ 2
- 0
api/core/app/app_config/entities.py Datei anzeigen

@@ -148,6 +148,8 @@ SupportedComparisonOperator = Literal[
"is not",
"empty",
"not empty",
"in",
"not in",
# for number
"=",
"≠",

+ 2
- 0
api/core/rag/entities/metadata_entities.py Datei anzeigen

@@ -13,6 +13,8 @@ SupportedComparisonOperator = Literal[
"is not",
"empty",
"not empty",
"in",
"not in",
# for number
"=",
"≠",

+ 2
- 0
api/core/workflow/nodes/knowledge_retrieval/entities.py Datei anzeigen

@@ -74,6 +74,8 @@ SupportedComparisonOperator = Literal[
"is not",
"empty",
"not empty",
"in",
"not in",
# for number
"=",
"≠",

+ 22
- 0
api/core/workflow/nodes/knowledge_retrieval/knowledge_retrieval_node.py Datei anzeigen

@@ -602,6 +602,28 @@ class KnowledgeRetrievalNode(BaseNode):
**{key: metadata_name, key_value: f"%{value}"}
)
)
case "in":
if isinstance(value, str):
escaped_values = [v.strip().replace("'", "''") for v in str(value).split(",")]
escaped_value_str = ",".join(escaped_values)
else:
escaped_value_str = str(value)
filters.append(
(text(f"documents.doc_metadata ->> :{key} = any(string_to_array(:{key_value},','))")).params(
**{key: metadata_name, key_value: escaped_value_str}
)
)
case "not in":
if isinstance(value, str):
escaped_values = [v.strip().replace("'", "''") for v in str(value).split(",")]
escaped_value_str = ",".join(escaped_values)
else:
escaped_value_str = str(value)
filters.append(
(text(f"documents.doc_metadata ->> :{key} != all(string_to_array(:{key_value},','))")).params(
**{key: metadata_name, key_value: escaped_value_str}
)
)
case "=" | "is":
if isinstance(value, str):
filters.append(Document.doc_metadata[metadata_name] == f'"{value}"')

+ 2
- 0
web/app/components/workflow/nodes/knowledge-retrieval/components/metadata/condition-list/utils.ts Datei anzeigen

@@ -32,6 +32,8 @@ export const getOperators = (type?: MetadataFilteringVariableType) => {
ComparisonOperator.endWith,
ComparisonOperator.empty,
ComparisonOperator.notEmpty,
ComparisonOperator.in,
ComparisonOperator.notIn,
]
case MetadataFilteringVariableType.number:
return [

+ 2
- 2
web/i18n/zh-Hans/workflow.ts Datei anzeigen

@@ -591,8 +591,8 @@ const translation = {
'not empty': '不为空',
'null': '空',
'not null': '不为空',
'in': '',
'not in': '不',
'in': '',
'not in': '不',
'all of': '全部是',
'exists': '存在',
'not exists': '不存在',

Laden…
Abbrechen
Speichern