Class TokenWindowChatMemory.Builder

java.lang.Object
dev.langchain4j.memory.chat.TokenWindowChatMemory.Builder
Enclosing class:
TokenWindowChatMemory

public static class TokenWindowChatMemory.Builder extends Object
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • id

      Parameters:
      id - The ID of the ChatMemory. If not provided, a "default" will be used.
      Returns:
      builder
    • maxTokens

      public TokenWindowChatMemory.Builder maxTokens(Integer maxTokens, TokenCountEstimator tokenCountEstimator)
      Parameters:
      maxTokens - The maximum number of tokens to retain. Chat memory will retain as many of the most recent messages as can fit into maxTokens. Messages are indivisible. If an old message doesn't fit, it is evicted completely.
      tokenCountEstimator - A TokenCountEstimator responsible for counting tokens in the messages.
      Returns:
      builder
    • dynamicMaxTokens

      public TokenWindowChatMemory.Builder dynamicMaxTokens(Function<Object,Integer> maxTokensProvider, TokenCountEstimator tokenCountEstimator)
      Parameters:
      maxTokensProvider - A provider that returns the maximum number of tokens to retain. The value returned by this provider may change dynamically at runtime. Chat memory will always respect the latest value supplied by the provider. Messages are indivisible; if an old message doesn't fit under the current limit, it is evicted completely.
      tokenCountEstimator - A TokenCountEstimator responsible for counting tokens in the messages.
      Returns:
      builder
    • chatMemoryStore

      public TokenWindowChatMemory.Builder chatMemoryStore(ChatMemoryStore store)
      Parameters:
      store - The chat memory store responsible for storing the chat memory state. If not provided, an SingleSlotChatMemoryStore will be used.
      Returns:
      builder
    • build

      public TokenWindowChatMemory build()