Skip to content

SimpleVectorStoreFilterExpressionConverter incorrectly treats "in" substring inside metadata key as IN operator #4908

@diydriller

Description

@diydriller

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions