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 result
pinnedEvents - 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 forward
preservedEvents - the recent events kept verbatim, in log order
summary - the messages that stand in for the covered events, in order (typically a synthetic shadow prompt and a summary); empty for a plain window
tokensEstimatedSaved - the estimated tokens removed from the prompt, net of the summary
strategy - 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 Details

  • Method Details

    • unchanged

      public static CompactionResult 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

      public List<SessionEvent> toEvents(String sessionId)
      The events SessionService.compact(java.lang.String, org.springframework.ai.session.compaction.CompactionTrigger, org.springframework.ai.session.compaction.CompactionStrategy) appends for this result: the EventType.COMPACTION boundary, 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; see CompactionBoundary.project(List).
      Parameters:
      sessionId - the session the events belong to
      Returns:
      the events to append, in order; empty for an unchanged result
    • toString

      public final String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • coveredEvents

      public List<SessionEvent> coveredEvents()
      Returns the value of the coveredEvents record component.
      Returns:
      the value of the coveredEvents record component
    • pinnedEvents

      public List<SessionEvent> pinnedEvents()
      Returns the value of the pinnedEvents record component.
      Returns:
      the value of the pinnedEvents record component
    • preservedEvents

      public List<SessionEvent> preservedEvents()
      Returns the value of the preservedEvents record component.
      Returns:
      the value of the preservedEvents record component
    • summary

      public List<Message> summary()
      Returns the value of the summary record component.
      Returns:
      the value of the summary record component
    • tokensEstimatedSaved

      public int tokensEstimatedSaved()
      Returns the value of the tokensEstimatedSaved record component.
      Returns:
      the value of the tokensEstimatedSaved record component
    • strategy

      public String strategy()
      Returns the value of the strategy record component.
      Returns:
      the value of the strategy record component