Package dev.langchain4j.memory
Interface ChatMemory
-
- All Implemented Interfaces:
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 abstract Object
id()
The ID of the ChatMemory. abstract void
add(ChatMessage message)
Adds a message to the chat memory. abstract List<ChatMessage>
messages()
Retrieves messages from the chat memory. abstract void
clear()
Clears the chat memory. -
-
Method Detail
-
id
abstract Object id()
The ID of the ChatMemory.
- Returns:
The ID of the ChatMemory.
-
add
abstract void add(ChatMessage message)
Adds a message to the chat memory.
- Parameters:
message
- The ChatMessage to add.
-
messages
abstract 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
abstract void clear()
Clears the chat memory.
-
-
-
-