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

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

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

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

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

@ -509,6 +509,18 @@ class KnowledgeRetrievalNode(LLMNode):
**{key: metadata_name, key_value: f"%{value}"} **{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": case "=" | "is":
if isinstance(value, str): if isinstance(value, str):
filters.append(Document.doc_metadata[metadata_name] == f'"{value}"') filters.append(Document.doc_metadata[metadata_name] == f'"{value}"')

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

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

Loading…
Cancel
Save