Class InMemoryChatMemoryStore
- All Implemented Interfaces:
ChatMemoryStore
ChatMemoryStore that stores state of ChatMemory (chat messages) in-memory.
This storage mechanism is transient and does not persist data across application restarts.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddeleteMessages(Object memoryId) Deletes all messages for a specified chat memory.deleteMessagesAsync(Object memoryId) Non-blocking counterpart ofChatMemoryStore.deleteMessages(Object), used by the asynchronous (CompletableFuture/CompletionStage) and reactive (Flow.Publisher) AI Service APIs.getMessages(Object memoryId) Retrieves messages for a specified chat memory.getMessagesAsync(Object memoryId) Non-blocking counterpart ofChatMemoryStore.getMessages(Object), used by the asynchronous (CompletableFuture/CompletionStage) and reactive (Flow.Publisher) AI Service APIs.voidupdateMessages(Object memoryId, List<ChatMessage> messages) Updates messages for a specified chat memory.updateMessagesAsync(Object memoryId, List<ChatMessage> messages) Non-blocking counterpart ofChatMemoryStore.updateMessages(Object, List), used by the asynchronous (CompletableFuture/CompletionStage) and reactive (Flow.Publisher) AI Service APIs.
-
Constructor Details
-
InMemoryChatMemoryStore
public InMemoryChatMemoryStore()Constructs a newInMemoryChatMemoryStore.
-
-
Method Details
-
getMessages
Description copied from interface:ChatMemoryStoreRetrieves messages for a specified chat memory.- Specified by:
getMessagesin interfaceChatMemoryStore- Parameters:
memoryId- The ID of the chat memory.- Returns:
- List of messages for the specified chat memory. Must not be null. Can be deserialized from JSON using
ChatMessageDeserializer.
-
updateMessages
Description copied from interface:ChatMemoryStoreUpdates messages for a specified chat memory.- Specified by:
updateMessagesin interfaceChatMemoryStore- Parameters:
memoryId- The ID of the chat memory.messages- List of messages for the specified chat memory, that represent the current state of theChatMemory. Can be serialized to JSON usingChatMessageSerializer.
-
deleteMessages
Description copied from interface:ChatMemoryStoreDeletes all messages for a specified chat memory.- Specified by:
deleteMessagesin interfaceChatMemoryStore- Parameters:
memoryId- The ID of the chat memory.
-
getMessagesAsync
Description copied from interface:ChatMemoryStoreNon-blocking counterpart ofChatMemoryStore.getMessages(Object), used by the asynchronous (CompletableFuture/CompletionStage) and reactive (Flow.Publisher) AI Service APIs.The default implementation returns a failed future carrying
AsyncNotSupportedException: a store backed by blocking I/O is not silently offloaded to a worker thread, because that would hide the fact that it is not truly non-blocking. Implement this method to return the messages without blocking the calling thread (e.g. using a reactive client), or, if the underlying client is blocking, offload it to an executor explicitly.- Specified by:
getMessagesAsyncin interfaceChatMemoryStore- Parameters:
memoryId- The ID of the chat memory.- Returns:
- A future that completes with the list of messages for the specified chat memory. Must not be null.
-
updateMessagesAsync
Description copied from interface:ChatMemoryStoreNon-blocking counterpart ofChatMemoryStore.updateMessages(Object, List), used by the asynchronous (CompletableFuture/CompletionStage) and reactive (Flow.Publisher) AI Service APIs.The default implementation returns a failed future carrying
AsyncNotSupportedException; seeChatMemoryStore.getMessagesAsync(Object)for the rationale.- Specified by:
updateMessagesAsyncin interfaceChatMemoryStore- Parameters:
memoryId- The ID of the chat memory.messages- List of messages for the specified chat memory, that represent the current state of theChatMemory.- Returns:
- A future that completes when the messages have been stored.
-
deleteMessagesAsync
Description copied from interface:ChatMemoryStoreNon-blocking counterpart ofChatMemoryStore.deleteMessages(Object), used by the asynchronous (CompletableFuture/CompletionStage) and reactive (Flow.Publisher) AI Service APIs.The default implementation returns a failed future carrying
AsyncNotSupportedException; seeChatMemoryStore.getMessagesAsync(Object)for the rationale.- Specified by:
deleteMessagesAsyncin interfaceChatMemoryStore- Parameters:
memoryId- The ID of the chat memory.- Returns:
- A future that completes when the messages have been deleted.
-