Record Class CompactionBoundary
java.lang.Object
java.lang.Record
org.springframework.ai.session.compaction.CompactionBoundary
- Record Components:
id- the id of the boundary eventpinnedEventIds- the ids of the events kept at the front of the view, in view ordersummaryEventIds- the ids of the summary events appended after the boundary, in orderpreservedEventIds- the ids of the events kept verbatim, in log ordercoveredEventCount- how many events left the viewtokensEstimatedSaved- the estimated tokens removed from the prompt, net of the summarystrategy- the name of the strategy that compacted
public record CompactionBoundary(String id, List<String> pinnedEventIds, List<String> summaryEventIds, List<String> preservedEventIds, int coveredEventCount, int tokensEstimatedSaved, String strategy)
extends Record
The record of one compaction: the payload of a
EventType.COMPACTION event,
typed. A compaction never changes the events already in the log; it appends one
boundary event and, right after it, the synthetic summary events. The boundary names,
by id, the events that make up the active view from then on: the
pinned events kept out of order at the front, such as the
latest stored system message; the summary events appended
after the boundary, or none for a plain window; the preserved recent conversation, in log order. Every other event that was in the view is
covered: it stays in the log, readable through EventFilter.all(), and is no
longer part of the prompt.
project(List) builds the view from a log: pinned, then summary, then
preserved, then everything appended after the summary. The newest boundary wins, so a
later compaction covers the previous summary and starts a new view, and the id lists
make a boundary self-contained: a view is rebuilt from the log alone, whatever earlier
compactions did, and an older boundary still shows what the model was told at the time.
- Since:
- 2.1.0
- Author:
- Christian Tzolov
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringPayload key:coveredEventCount().static final StringPayload key:pinnedEventIds().static final StringPayload key:preservedEventIds().static final StringPayload key:strategy().static final StringPayload key:summaryEventIds().static final StringPayload key:tokensEstimatedSaved(). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintReturns the value of thecoveredEventCountrecord component.final booleanIndicates whether some other object is "equal to" this one.static CompactionBoundaryfrom(SessionEvent event) Reads the boundary recorded by aEventType.COMPACTIONevent.final inthashCode()Returns a hash code value for this object.id()Returns the value of theidrecord component.static @Nullable CompactionBoundarynewest(List<SessionEvent> log) The newest boundary of a log, ornullwhen the log was never compacted.Returns the value of thepinnedEventIdsrecord component.Returns the value of thepreservedEventIdsrecord component.static List<SessionEvent>project(List<SessionEvent> log) The active view of a log, from its newest boundary: the pinned events, then the summary events, then the preserved events, then every event appended after the summary; a log without a boundary is its own view, and the boundary event is never in it.strategy()Returns the value of thestrategyrecord component.Returns the value of thesummaryEventIdsrecord component.intReturns the value of thetokensEstimatedSavedrecord component.The payload of the boundary event, as stored.final StringtoString()Returns a string representation of this record class.
-
Field Details
-
PAYLOAD_PINNED
Payload key:pinnedEventIds().- See Also:
-
PAYLOAD_SUMMARY
Payload key:summaryEventIds().- See Also:
-
PAYLOAD_PRESERVED
Payload key:preservedEventIds().- See Also:
-
PAYLOAD_COVERED_COUNT
Payload key:coveredEventCount().- See Also:
-
PAYLOAD_TOKENS_SAVED
Payload key:tokensEstimatedSaved().- See Also:
-
PAYLOAD_STRATEGY
Payload key:strategy().- See Also:
-
-
Constructor Details
-
CompactionBoundary
public CompactionBoundary(String id, List<String> pinnedEventIds, List<String> summaryEventIds, List<String> preservedEventIds, int coveredEventCount, int tokensEstimatedSaved, String strategy) Creates an instance of aCompactionBoundaryrecord class.- Parameters:
id- the value for theidrecord componentpinnedEventIds- the value for thepinnedEventIdsrecord componentsummaryEventIds- the value for thesummaryEventIdsrecord componentpreservedEventIds- the value for thepreservedEventIdsrecord componentcoveredEventCount- the value for thecoveredEventCountrecord componenttokensEstimatedSaved- the value for thetokensEstimatedSavedrecord componentstrategy- the value for thestrategyrecord component
-
-
Method Details
-
toPayload
The payload of the boundary event, as stored. -
from
Reads the boundary recorded by aEventType.COMPACTIONevent.- Parameters:
event- a compaction event- Returns:
- its boundary
- Throws:
IllegalArgumentException- if the event is not a compaction event
-
newest
The newest boundary of a log, ornullwhen the log was never compacted.- Parameters:
log- the events of one session, oldest first
-
project
The active view of a log, from its newest boundary: the pinned events, then the summary events, then the preserved events, then every event appended after the summary; a log without a boundary is its own view, and the boundary event is never in it. The reference implementation of the view everySessionRepositoryreturns forEventFilter.active(); a store may compute the same thing in a query.- Parameters:
log- the events of one session, oldest first: the whole log, or any superset of the view that includes the newest boundary- Returns:
- the view, never the input list itself
-
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 '=='. -
id
Returns the value of theidrecord component.- Returns:
- the value of the
idrecord component
-
pinnedEventIds
Returns the value of thepinnedEventIdsrecord component.- Returns:
- the value of the
pinnedEventIdsrecord component
-
summaryEventIds
Returns the value of thesummaryEventIdsrecord component.- Returns:
- the value of the
summaryEventIdsrecord component
-
preservedEventIds
Returns the value of thepreservedEventIdsrecord component.- Returns:
- the value of the
preservedEventIdsrecord component
-
coveredEventCount
public int coveredEventCount()Returns the value of thecoveredEventCountrecord component.- Returns:
- the value of the
coveredEventCountrecord component
-
tokensEstimatedSaved
public int tokensEstimatedSaved()Returns the value of thetokensEstimatedSavedrecord component.- Returns:
- the value of the
tokensEstimatedSavedrecord component
-
strategy
Returns the value of thestrategyrecord component.- Returns:
- the value of the
strategyrecord component
-