spring-projects / spring-projects/spring-ai

`FilterExpressionTextParser` fails to parse expressions whose first key starts with the letters `where`

Open Beginner friendly
#6,909 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
9.5k
Forks
2.9k
Avg merge
1d 7h
Merged PRs (30d)
6

Description

Bug description

FilterExpressionTextParser prepends the compulsory WHERE keyword only when the expression does not already start with it, but the check is a plain string prefix test:

if (!textFilterExpression.toUpperCase(Locale.ROOT).startsWith(WHERE_PREFIX)) {

A metadata key that merely starts with the letters where — such as whereabouts or where_clause — satisfies the prefix check, so WHERE is never prepended. The lexer then tokenizes the identifier as IDENTIFIER rather than the WHERE token required by the grammar rule where : WHERE booleanExpression EOF, and parsing fails.

Environment

  • Spring AI 2.0.2-SNAPSHOT, main at 0933bd0
  • Module: spring-ai-vector-store
  • Class: org.springframework.ai.vectorstore.filter.FilterExpressionTextParser

Steps to reproduce

new FilterExpressionTextParser().parse("whereabouts == 'BG'");

fails with:

FilterExpressionTextParser$FilterExpressionParseException
Caused by: org.antlr.v4.runtime.InputMismatchException
	at org.springframework.ai.vectorstore.filter.antlr4.FiltersParser.where(FiltersParser.java:186)

while e.g. parse("country == 'BG'") works.

Expected behavior

whereabouts == 'BG' parses to EQ(Key("whereabouts"), Value("BG")) like any other key. The prefix check should only match the standalone WHERE keyword (e.g. ^\s*where\b, case-insensitive), not any identifier that happens to start with those letters.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in the spring-ai-vector-store module at org.springframework.ai.vectorstore.filter.FilterExpressionTextParser and reproduce the failure with whereabouts == 'BG'. Check the existing WHERE-prefix handling and its interaction with the FiltersParser grammar. Done means keys beginning with where parse successfully while the standalone WHERE keyword continues to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
86/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.