Record Class EventQuery
- Record Components:
keywords- the keywords to look for, at least one, none blankmatchMode- how several keywords combinemessageTypes- the message types to search, ornullfor every typesince- only events at or after this instant, to the microsecond, ornullfor no lower boundpage- the zero-based page of matches to return, within the firstMAX_MATCHESmatchespageSize- the number of matches on a page
SessionService.searchEvents(java.lang.String, org.springframework.ai.session.EventQuery) looks for. It is the read for recall, finding
something that was said, where EventFilter is the read for the prompt.
The search covers the whole log, the events a compaction covered included: they are no
longer sent to the model, and a search is how it finds them again. Only
EventType.MESSAGE events are searched, by the text of their message, and
synthetic events never: a summary repeats what the log still holds. A tool result
carries its data outside the message text, so it is not found.
A keyword matches when the text contains it, ignoring case. With several keywords,
EventQuery.MatchMode.ANY matches a text that contains one of them and
EventQuery.MatchMode.ALL a text that contains every one. The matches come oldest first, a
page at a time.
Letters are compared the same way everywhere for ASCII text. For other text the store decides: a database may ignore accents or fold case differently, by its collation.
A query is bounded, so that one search costs a bounded read: at most
MAX_KEYWORDS keywords of at most MAX_KEYWORD_LENGTH characters, and
pages only within the first MAX_MATCHES matches.
apply(List) is the reference implementation for a log held in memory; a store
that can push the search down to a query does so and agrees with it (see
SessionRepository.searchEvents(java.lang.String, org.springframework.ai.session.EventQuery)).
EventQuery first = EventQuery.keyword("invoice");
EventQuery both = EventQuery.builder().keywords("invoice", "refund").matchMode(MatchMode.ALL).build();
EventQuery recent = EventQuery.builder().keywords("invoice").since(lastWeek).page(1).build();
- Since:
- 2.1.0
- Author:
- Christian Tzolov
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilds anEventQuery.static enumHow several keywords combine. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe page size of a query that sets none.static final intThe longest keyword, in characters.static final intThe most keywords a query takes; each becomes a predicate of the store's query.static final intHow far a search pages: the page and the pages before it hold at most this many matches.static final intThe largest page size, so that one search cannot return a whole log. -
Constructor Summary
ConstructorsConstructorDescriptionEventQuery(List<String> keywords, EventQuery.MatchMode matchMode, @Nullable Set<MessageType> messageTypes, @Nullable Instant since, int page, int pageSize) Creates an instance of aEventQueryrecord class. -
Method Summary
Modifier and TypeMethodDescriptionapply(List<SessionEvent> events) Runs the query over the events of a log, given oldest first: the matching events, oldest first, cut to the page.static EventQuery.Builderbuilder()Returns a newEventQuery.Builder.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.static intindexOfIgnoreCase(String text, String keyword) The index of the first place the text holds the keyword, ignoring case, or-1.static EventQueryReturns a query for the first page of the events that contain the keyword.keywords()Returns the value of thekeywordsrecord component.intlimit()How many matches a store reads to return this page: the page and every page before it.booleanmatches(SessionEvent event) Whether the event is one this query finds: a message event that is not synthetic, of a searched type, not older thansince(), whose text contains the keywords.Returns the value of thematchModerecord component.@Nullable Set<MessageType>Returns the value of themessageTypesrecord component.intpage()Returns the value of thepagerecord component.pageOf(List<SessionEvent> matches) Keeps this query's page of the matches a store read from the first one on, up tolimit()of them.intpageSize()Returns the value of thepageSizerecord component.@Nullable Instantsince()Returns the value of thesincerecord component.final StringtoString()Returns a string representation of this record class.
-
Field Details
-
DEFAULT_PAGE_SIZE
public static final int DEFAULT_PAGE_SIZEThe page size of a query that sets none.- See Also:
-
MAX_PAGE_SIZE
public static final int MAX_PAGE_SIZEThe largest page size, so that one search cannot return a whole log.- See Also:
-
MAX_MATCHES
public static final int MAX_MATCHESHow far a search pages: the page and the pages before it hold at most this many matches. A store reads the matches from the first one on, so this bounds what one search reads.- See Also:
-
MAX_KEYWORDS
public static final int MAX_KEYWORDSThe most keywords a query takes; each becomes a predicate of the store's query.- See Also:
-
MAX_KEYWORD_LENGTH
public static final int MAX_KEYWORD_LENGTHThe longest keyword, in characters.- See Also:
-
-
Constructor Details
-
EventQuery
public EventQuery(List<String> keywords, EventQuery.MatchMode matchMode, @Nullable Set<MessageType> messageTypes, @Nullable Instant since, int page, int pageSize) Creates an instance of aEventQueryrecord class.- Parameters:
keywords- the value for thekeywordsrecord componentmatchMode- the value for thematchModerecord componentmessageTypes- the value for themessageTypesrecord componentsince- the value for thesincerecord componentpage- the value for thepagerecord componentpageSize- the value for thepageSizerecord component
-
-
Method Details
-
keyword
Returns a query for the first page of the events that contain the keyword. -
builder
Returns a newEventQuery.Builder. -
limit
public int limit()How many matches a store reads to return this page: the page and every page before it. A store that cannot skip rows in its query reads this many and keeps the page. -
matches
Whether the event is one this query finds: a message event that is not synthetic, of a searched type, not older thansince(), whose text contains the keywords. -
indexOfIgnoreCase
The index of the first place the text holds the keyword, ignoring case, or-1. The characters are compared one by one, so the index is one of the text as given, and a letter matches its other case wherever it stands in a word. -
apply
Runs the query over the events of a log, given oldest first: the matching events, oldest first, cut to the page. -
pageOf
Keeps this query's page of the matches a store read from the first one on, up tolimit()of them. -
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
keywords
Returns the value of thekeywordsrecord component.- Returns:
- the value of the
keywordsrecord component
-
matchMode
Returns the value of thematchModerecord component.- Returns:
- the value of the
matchModerecord component
-
messageTypes
Returns the value of themessageTypesrecord component.- Returns:
- the value of the
messageTypesrecord component
-
since
Returns the value of thesincerecord component.- Returns:
- the value of the
sincerecord component
-
page
public int page()Returns the value of thepagerecord component.- Returns:
- the value of the
pagerecord component
-
pageSize
public int pageSize()Returns the value of thepageSizerecord component.- Returns:
- the value of the
pageSizerecord component
-