-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
Bug description
SimpleVectorStoreFilterExpressionConverter has a bug when converting filter expressions.
When a metadata key contains the substring "in", the converter mistakenly interprets it as an IN operator because it checks:
Expected Behavior
When converting a filter expression where:
- the operator is EQ
- the metadata key contains "in" as a substring
- the value is a List
the converter should output a standard SpEL equality expression.
Filter.Expression expr = new Filter.Expression(
ExpressionType.EQ,
new Filter.Key("pin code"),
new Filter.Value(List.of("1234", "5678"))
);The expected SpEL output is:
#metadata['pin code'] == {'1234','5678'}Current Behavior
The current SimpleVectorStoreFilterExpressionConverter incorrectly interprets the key substring "in" as the IN operator because it checks:
context.lastIndexOf("in")As a result, the converter generates an unintended contains() expression
{'1234','5678'}.contains(#metadata['pin)This is invalid and breaks metadata filtering in SimpleVectorStore.
Proposed Fix
Modify the doValue() implementation to distinguish real IN operators from accidental key substrings
String ctx = context.toString().trim();
boolean isInClause = ctx.endsWith(" in");
boolean isNotInClause = ctx.endsWith(" not in");
if (!isInClause && !isNotInClause) {
context.append(formattedList);
} else {
appendSpELContains(formattedList, context);
}This ensures substring "in" inside a metadata key is not mistaken for the IN operator.