ConversationBufferWindowMemory class final
ConversationBufferWindowMemory is a type of memory that stores a conversation in chatHistory and then retrieves the last k interactions with the model (i.e. the last k input messages and the last k output messages).
It uses ChatMessageHistory as in-memory storage by default.
Example:
final memory = ConversationBufferWindowMemory(k: 10);
await memory.saveContext({'input': 'bar'}, {'output': 'foo'});
final res = await memory.loadMemoryVariables();
// {'history': 'Human: bar\nAI: foo'}
- Inheritance
-
- Object
- BaseChatMemory
- ConversationBufferWindowMemory
Constructors
- ConversationBufferWindowMemory.new({BaseChatMessageHistory? chatHistory, String? inputKey, String? outputKey, bool returnMessages = false, int k = 5, String memoryKey = BaseMemory.defaultMemoryKey, String systemPrefix = SystemChatMessage.defaultPrefix, String humanPrefix = HumanChatMessage.defaultPrefix, String aiPrefix = AIChatMessage.defaultPrefix, String toolPrefix = ToolChatMessage.defaultPrefix})
-
ConversationBufferWindowMemory is a type of memory that stores a
conversation in
chatHistory
and then retrieves the last k interactions with the model (i.e. the last k input messages and the last k output messages).
Properties
- aiPrefix → String
-
The prefix to use for AI messages if returnMessages is false.
final
- chatHistory → BaseChatMessageHistory
-
The chat history.
finalinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- humanPrefix → String
-
The prefix to use for human messages if returnMessages is false.
final
- inputKey → String?
-
The input key to use for the chat history.
finalinherited
- k → int
-
Number of interactions to store in the buffer.
final
- memoryKey → String
-
The memory key to use for the chat history.
This will be passed as input variable to the prompt.
final
-
memoryKeys
→ Set<
String> -
Input keys this memory class will load dynamically to the prompt.
no setteroverride
- outputKey → String?
-
The output key to use for the chat history.
finalinherited
- returnMessages → bool
-
If true, when loadMemoryVariables is called, it will return
ChatMessage objects. If false, it will return a String representation
of the messages.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- systemPrefix → String
-
The prefix to use for system messages if returnMessages is false.
final
- toolPrefix → String
-
The prefix to use for tool messages if returnMessages is false.
final
Methods
-
clear(
) → Future< void> -
Clear memory contents.
inherited
-
loadMemoryVariables(
[MemoryInputValues values = const {}]) → Future< MemoryVariables> -
Returns key-value pairs given the MemoryInputValues.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
saveContext(
{required MemoryInputValues inputValues, required MemoryOutputValues outputValues}) → Future< void> -
Save the context of this model run to memory.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited