Add in and not in filtering to the metadata of the knowledge-retrieval node

pull/20874/head
yuangui 8 months ago
parent 21a50e22d2
commit 0c79afd069

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

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

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

@ -509,6 +509,18 @@ class KnowledgeRetrievalNode(LLMNode):
**{key: metadata_name, key_value: f"%{value}"}
)
)
case "in":
filters.append(
(text(f"documents.doc_metadata ->> :{key} = any(string_to_array(:{key_value},',')")).params(
**{key: metadata_name, key_value: f"{value}"}
)
)
case "not in":
filters.append(
(text(f"documents.doc_metadata ->> :{key} != all(string_to_array(:{key_value},',')")).params(
**{key: metadata_name, key_value: f"{value}"}
)
)
case "=" | "is":
if isinstance(value, str):
filters.append(Document.doc_metadata[metadata_name] == f'"{value}"')

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

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

Loading…
Cancel
Save