Class TokenWindowChatMemory.Builder
java.lang.Object
dev.langchain4j.memory.chat.TokenWindowChatMemory.Builder
- Enclosing class:
TokenWindowChatMemory
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()chatMemoryStore(ChatMemoryStore store) dynamicMaxTokens(Function<Object, Integer> maxTokensProvider, TokenCountEstimator tokenCountEstimator) maxTokens(Integer maxTokens, TokenCountEstimator tokenCountEstimator)
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
id
- Parameters:
id- The ID of theChatMemory. 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 intomaxTokens. Messages are indivisible. If an old message doesn't fit, it is evicted completely.tokenCountEstimator- ATokenCountEstimatorresponsible 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- ATokenCountEstimatorresponsible for counting tokens in the messages.- Returns:
- builder
-
chatMemoryStore
- Parameters:
store- The chat memory store responsible for storing the chat memory state. If not provided, anSingleSlotChatMemoryStorewill be used.- Returns:
- builder
-
build
-