Record Class CompactionResult
java.lang.Object
java.lang.Record
org.springframework.ai.session.compaction.CompactionResult
- Record Components:
coveredEvents- the events that leave the view, in view order: summarized by the summary, or simply dropped by a window. Empty for an unchanged resultpinnedEvents- the events kept at the front of the view, out of log order: the latest stored system message, and for a plain window the prior summary it carries forwardpreservedEvents- the recent events kept verbatim, in log ordersummary- the messages that stand in for the covered events, in order (typically a synthetic shadow prompt and a summary); empty for a plain windowtokensEstimatedSaved- the estimated tokens removed from the prompt, net of the summarystrategy- the name of the strategy, recorded on the boundary and the summary events
public record CompactionResult(List<SessionEvent> coveredEvents, List<SessionEvent> pinnedEvents, List<SessionEvent> preservedEvents, List<Message> summary, int tokensEstimatedSaved, String strategy)
extends Record
What a
CompactionStrategy decided for the active view it was given: which
events leave the view, which are kept, and the summary that stands in for the ones that
leave.
The three event lists partition the view the strategy received: every event of the view
is covered, pinned or preserved, and none is in two lists. Nothing here changes the
log. SessionService.compact(java.lang.String, org.springframework.ai.session.compaction.CompactionTrigger, org.springframework.ai.session.compaction.CompactionStrategy) turns a result into
one appended CompactionBoundary event plus the summary events; the boundary
then defines the view (see CompactionBoundary.project(List)).
- Since:
- 2.1.0
- Author:
- Christian Tzolov
-
Constructor Summary
ConstructorsConstructorDescriptionCompactionResult(List<SessionEvent> coveredEvents, List<SessionEvent> pinnedEvents, List<SessionEvent> preservedEvents, List<Message> summary, int tokensEstimatedSaved, String strategy) Creates an instance of aCompactionResultrecord class. -
Method Summary
Modifier and TypeMethodDescriptionintThe number of events that leave the view.Returns the value of thecoveredEventsrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.booleanWhether no event leaves the view, so there is nothing to record.Returns the value of thepinnedEventsrecord component.Returns the value of thepreservedEventsrecord component.strategy()Returns the value of thestrategyrecord component.summary()Returns the value of thesummaryrecord component.The eventsSessionService.compact(java.lang.String, org.springframework.ai.session.compaction.CompactionTrigger, org.springframework.ai.session.compaction.CompactionStrategy)appends for this result: theEventType.COMPACTIONboundary, then one synthetic event per summary message, all with one timestamp.intReturns the value of thetokensEstimatedSavedrecord component.final StringtoString()Returns a string representation of this record class.static CompactionResultThe result of a pass that leaves the view as it is: nothing is written.
-
Constructor Details
-
CompactionResult
public CompactionResult(List<SessionEvent> coveredEvents, List<SessionEvent> pinnedEvents, List<SessionEvent> preservedEvents, List<Message> summary, int tokensEstimatedSaved, String strategy) Creates an instance of aCompactionResultrecord class.- Parameters:
coveredEvents- the value for thecoveredEventsrecord componentpinnedEvents- the value for thepinnedEventsrecord componentpreservedEvents- the value for thepreservedEventsrecord componentsummary- the value for thesummaryrecord componenttokensEstimatedSaved- the value for thetokensEstimatedSavedrecord componentstrategy- the value for thestrategyrecord component
-
-
Method Details
-
unchanged
The result of a pass that leaves the view as it is: nothing is written. -
isUnchanged
public boolean isUnchanged()Whether no event leaves the view, so there is nothing to record. -
coveredEventCount
public int coveredEventCount()The number of events that leave the view. -
toEvents
The eventsSessionService.compact(java.lang.String, org.springframework.ai.session.compaction.CompactionTrigger, org.springframework.ai.session.compaction.CompactionStrategy)appends for this result: theEventType.COMPACTIONboundary, then one synthetic event per summary message, all with one timestamp. The boundary names the pinned, summary and preserved events by id, so the view is rebuilt from the log alone; seeCompactionBoundary.project(List).- Parameters:
sessionId- the session the events belong to- Returns:
- the events to append, in order; empty for an unchanged result
-
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 '=='. -
coveredEvents
Returns the value of thecoveredEventsrecord component.- Returns:
- the value of the
coveredEventsrecord component
-
pinnedEvents
Returns the value of thepinnedEventsrecord component.- Returns:
- the value of the
pinnedEventsrecord component
-
preservedEvents
Returns the value of thepreservedEventsrecord component.- Returns:
- the value of the
preservedEventsrecord component
-
summary
Returns the value of thesummaryrecord component.- Returns:
- the value of the
summaryrecord 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
-