Interface Filter
- All Known Implementing Classes:
And, ContainsString, FullTextContains, FullTextContainsAll, FullTextContainsAny, IsEqualTo, IsGreaterThan, IsGreaterThanOrEqualTo, IsIn, IsLessThan, IsLessThanOrEqualTo, IsNotEqualTo, IsNotIn, IsTextMatch, IsTextMatchPhrase, Not, Or
EmbeddingStore.
Many
EmbeddingStores support a feature called metadata filtering. A Filter can be used for this.
A
Filter object can represent simple (e.g. type = 'documentation')
and composite (e.g. type = 'documentation' AND year > 2020) filter expressions in
an EmbeddingStore-agnostic way.
Each
EmbeddingStore implementation that supports metadata filtering is mapping Filter
into it's native filter expression.
The value that a comparison filter (IsEqualTo, IsNotEqualTo, IsGreaterThan,
IsGreaterThanOrEqualTo, IsLessThan, IsLessThanOrEqualTo, IsIn or
IsNotIn) compares with must be an instance of exactly one of these classes:
String, UUID, Boolean, Integer, Long, Float, Double,
Byte, Short, BigInteger, BigDecimal, LocalDate, LocalDateTime,
LocalTime, OffsetDateTime, OffsetTime, ZonedDateTime, Instant, Year,
YearMonth, MonthDay, java.util.Date, java.sql.Date, java.sql.Time or
java.sql.Timestamp, or it must be an enum.
Subclasses, for example of BigDecimal, are not accepted, and a Float or Double must be
a finite number (not NaN or infinite). For IsIn and IsNotIn, this applies to every
value in the collection. Any other value is rejected with an IllegalArgumentException when the filter
is created. Convert such a value first, for example a Character with String.valueOf().
Metadata itself can only store String, UUID, Integer, Long,
Float and Double values, so compare with the same type as the stored value,
for example an enum by its name().
The other types are meant for embedding stores that hold data written outside LangChain4j,
and are passed to the embedding store as they are.
Individual embedding stores may support only some of these types.
For IsGreaterThan, IsGreaterThanOrEqualTo, IsLessThan and IsLessThanOrEqualTo,
use numbers, Strings or dates and times: embedding stores order UUID, Boolean and enum
values differently.
Stored metadata values can be Float or Double, and those can be infinite or NaN.
Infinite values are compared as one would expect: -Infinity is smaller and +Infinity is
greater than any other number. NaN is not comparable to anything, not even to itself, so every
comparison with it is false: a NaN metadata value satisfies neither
IsEqualTo("key", 0.5) nor IsGreaterThan("key", 0), and only IsNotEqualTo and
IsNotIn match it.
- See Also:
-
Method Details
-
test
-
and
-
and
-
or
-
or
-
not
-