Record Class CompactionBoundary

java.lang.Object
java.lang.Record
org.springframework.ai.session.compaction.CompactionBoundary
Record Components:
id - the id of the boundary event
pinnedEventIds - the ids of the events kept at the front of the view, in view order
summaryEventIds - the ids of the summary events appended after the boundary, in order
preservedEventIds - the ids of the events kept verbatim, in log order
coveredEventCount - how many events left the view
tokensEstimatedSaved - the estimated tokens removed from the prompt, net of the summary
strategy - 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 Details

  • 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 a CompactionBoundary record class.
      Parameters:
      id - the value for the id record component
      pinnedEventIds - the value for the pinnedEventIds record component
      summaryEventIds - the value for the summaryEventIds record component
      preservedEventIds - the value for the preservedEventIds record component
      coveredEventCount - the value for the coveredEventCount record component
      tokensEstimatedSaved - the value for the tokensEstimatedSaved record component
      strategy - the value for the strategy record component
  • Method Details

    • toPayload

      public Map<String,Object> toPayload()
      The payload of the boundary event, as stored.
    • from

      public static CompactionBoundary from(SessionEvent event)
      Reads the boundary recorded by a EventType.COMPACTION event.
      Parameters:
      event - a compaction event
      Returns:
      its boundary
      Throws:
      IllegalArgumentException - if the event is not a compaction event
    • newest

      public static @Nullable CompactionBoundary newest(List<SessionEvent> log)
      The newest boundary of a log, or null when the log was never compacted.
      Parameters:
      log - the events of one session, oldest first
    • project

      public 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. The reference implementation of the view every SessionRepository returns for EventFilter.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

      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.
    • id

      public String id()
      Returns the value of the id record component.
      Returns:
      the value of the id record component
    • pinnedEventIds

      public List<String> pinnedEventIds()
      Returns the value of the pinnedEventIds record component.
      Returns:
      the value of the pinnedEventIds record component
    • summaryEventIds

      public List<String> summaryEventIds()
      Returns the value of the summaryEventIds record component.
      Returns:
      the value of the summaryEventIds record component
    • preservedEventIds

      public List<String> preservedEventIds()
      Returns the value of the preservedEventIds record component.
      Returns:
      the value of the preservedEventIds record component
    • coveredEventCount

      public int coveredEventCount()
      Returns the value of the coveredEventCount record component.
      Returns:
      the value of the coveredEventCount 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