Interface ChatMemory

All Known Implementing Classes:
MessageWindowChatMemory, TokenWindowChatMemory

public interface ChatMemory
Represents the memory (history) of a chat conversation. Since language models do not keep the state of the conversation, it is necessary to provide all previous messages on every interaction with the language model. ChatMemory helps with keeping track of the conversation and ensuring that messages fit within language model's context window.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(ChatMessage message)
    Adds a message to the chat memory.
    default void
    add(ChatMessage... messages)
    Adds messages to the chat memory
    default void
    Adds messages to the chat memory
    void
    Clears the chat memory.
    id()
    The ID of the ChatMemory.
    Retrieves messages from the chat memory.
  • Method Details

    • id

      Object id()
      The ID of the ChatMemory.
      Returns:
      The ID of the ChatMemory.
    • add

      void add(ChatMessage message)
      Adds a message to the chat memory.
      Parameters:
      message - The ChatMessage to add.
    • add

      default void add(ChatMessage... messages)
      Adds messages to the chat memory
      Parameters:
      messages - The ChatMessages to add
    • add

      default void add(Iterable<ChatMessage> messages)
      Adds messages to the chat memory
      Parameters:
      messages - The ChatMessages to add
    • messages

      List<ChatMessage> messages()
      Retrieves messages from the chat memory. Depending on the implementation, it may not return all previously added messages, but rather a subset, a summary, or a combination thereof.
      Returns:
      A list of ChatMessage objects that represent the current state of the chat memory.
    • clear

      void clear()
      Clears the chat memory.