Class MessageWindowChatMemory
java.lang.Object
org.springframework.ai.chat.memory.MessageWindowChatMemory
- All Implemented Interfaces:
ChatMemory
A chat memory implementation that maintains a message window of a specified size,
ensuring that the total number of messages does not exceed the specified limit. When
the number of messages exceeds the maximum size, older messages are evicted.
Messages of type SystemMessage
are treated specially: if a new
SystemMessage
is added, all previous SystemMessage
instances are
removed from the memory. Also, if the total number of messages exceeds the limit, the
SystemMessage
messages are preserved while evicting other types of messages.
- Since:
- 1.0.0
- Author:
- Thomas Vitale
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from interface org.springframework.ai.chat.memory.ChatMemory
DEFAULT_CONVERSATION_ID
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Save the specified messages in the chat memory for the specified conversation.builder()
void
Clear the chat memory for the specified conversation.Get the messages in the chat memory for the specified conversation.Deprecated.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.ai.chat.memory.ChatMemory
add
-
Method Details
-
add
Description copied from interface:ChatMemory
Save the specified messages in the chat memory for the specified conversation.- Specified by:
add
in interfaceChatMemory
-
get
Description copied from interface:ChatMemory
Get the messages in the chat memory for the specified conversation.- Specified by:
get
in interfaceChatMemory
-
get
Deprecated.- Specified by:
get
in interfaceChatMemory
-
clear
Description copied from interface:ChatMemory
Clear the chat memory for the specified conversation.- Specified by:
clear
in interfaceChatMemory
-
builder
-