Record Class CompactionWindow

java.lang.Object
java.lang.Record
org.springframework.ai.session.compaction.CompactionWindow
Record Components:
rule - what the size counts
size - the number of events or turns kept, or the token budget of the view

public record CompactionWindow(CompactionWindow.Rule rule, int size) extends Record
The rule a WindowCompactionStrategy cuts by: how much of the recent conversation stays in the view, measured in events, in turns or in estimated tokens. The cut it produces always falls on a turn start, so a turn is never split, and the newest turn stays whatever its size.
Since:
2.1.0
Author:
Christian Tzolov
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    What the size of a window counts.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an instance of a CompactionWindow record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    lastEvents(int n)
    Keeps the last n conversation events.
    lastTurns(int n)
    Keeps the last n turns: a user message and everything up to the next one.
    Returns the value of the rule record component.
    int
    Returns the value of the size record component.
    tokenBudget(int maxTokens)
    Keeps what fits in maxTokens, counted from the newest event back: the pinned events come off the budget first, and the kept window is a contiguous suffix.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • CompactionWindow

      public CompactionWindow(CompactionWindow.Rule rule, int size)
      Creates an instance of a CompactionWindow record class.
      Parameters:
      rule - the value for the rule record component
      size - the value for the size record component
  • Method Details

    • lastEvents

      public static CompactionWindow lastEvents(int n)
      Keeps the last n conversation events.
    • lastTurns

      public static CompactionWindow lastTurns(int n)
      Keeps the last n turns: a user message and everything up to the next one.
    • tokenBudget

      public static CompactionWindow tokenBudget(int maxTokens)
      Keeps what fits in maxTokens, counted from the newest event back: the pinned events come off the budget first, and the kept window is a contiguous suffix.
    • 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.
    • rule

      public CompactionWindow.Rule rule()
      Returns the value of the rule record component.
      Returns:
      the value of the rule record component
    • size

      public int size()
      Returns the value of the size record component.
      Returns:
      the value of the size record component