feat (metadata postgres): added logic for IN clauses on operands

This commit is contained in:
GGrassia 2025-10-10 11:05:17 +02:00
parent bb4d8181d5
commit bdb1ae0786

View file

@ -2150,12 +2150,18 @@ class PGVectorStorage(BaseVectorStorage):
return "" return ""
def build_single_condition(key, value): def build_single_condition(key, value):
if isinstance(value, (list, dict)): #Check and build "IN" conditions for the operand
# Use GIN-optimized containment operator if isinstance(value, list):
json_value = json.dumps(value) if not value:
return f"metadata @> '{{\"{ key}\" : {json_value}}}'" return "1=0"
in_conditions = [
f"metadata @> '{{\"{key}\": {json.dumps(v)}}}'" for v in value
]
return f"({ ' OR '.join(in_conditions) })"
else: else:
# Use containment for scalars too - faster with GIN index # Use for scalars and dictionaries
json_value = json.dumps(value) json_value = json.dumps(value)
return f"metadata @> '{{\"{ key}\" : {json_value}}}'" return f"metadata @> '{{\"{ key}\" : {json_value}}}'"