Class Filter
java.lang.Object
org.springframework.ai.vectorstore.filter.Filter
Portable runtime generative for metadata filter expressions. This generic generative is
used to define store agnostic filter expressions than later can be converted into
vector-store specific, native, expressions.
The expression generative supports constant comparison
(e.g. ==, !=, <, <=, >, >=)
, IN/NON-IN checks and AND and OR to compose
multiple expressions.
For example:
// 1: country == "BG"
new Expression(EQ, new Key("country"), new Value("BG"));
// 2: genre == "drama" AND year >= 2020
new Expression(AND, new Expression(EQ, new Key("genre"), new Value("drama")),
new Expression(GTE, new Key("year"), new Value(2020)));
// 3: genre in ["comedy", "documentary", "drama"]
new Expression(IN, new Key("genre"), new Value(List.of("comedy", "documentary", "drama")));
// 4: year >= 2020 OR country == "BG" AND city != "Sofia"
new Expression(OR, new Expression(GTE, new Key("year"), new Value(2020)),
new Expression(AND, new Expression(EQ, new Key("country"), new Value("BG")),
new Expression(NE, new Key("city"), new Value("Sofia"))));
// 5: (year >= 2020 OR country == "BG") AND city NIN ["Sofia", "Plovdiv"]
new Expression(AND,
new Group(new Expression(OR, new Expression(EQ, new Key("country"), new Value("BG")),
new Expression(GTE, new Key("year"), new Value(2020)))),
new Expression(NIN, new Key("city"), new Value(List.of("Sofia", "Varna"))));
// 6: isOpen == true AND year >= 2020 AND country IN ["BG", "NL", "US"]
new Expression(AND, new Expression(EQ, new Key("isOpen"), new Value(true)),
new Expression(AND, new Expression(GTE, new Key("year"), new Value(2020)),
new Expression(IN, new Key("country"), new Value(List.of("BG", "NL", "US")))));
Usually you will not create expression manually but use either the
FilterExpressionBuilder
DSL or the FilterExpressionTextParser
for
parsing generic text expressions.- Author:
- Christian Tzolov
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final record
Triple that represents and filter boolean expression asleft type right
.static enum
Filter expression operations.static final record
Represents expression grouping (e.g.static final record
String identifier representing an expression key.static interface
Mark interface representing the supported expression types:Filter.Key
,Filter.Value
,Filter.Expression
andFilter.Group
.static final record
Represents expression value constant or constant array. -
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Filter
public Filter()
-