Memories

By default, Chains and Agents are stateless, handling each query independently. The memory component, when incorporated into chat-based applications, enables the system to retain knowledge of prior interactions. This functionality aids in preserving the context of the conversation and empowers the system to interpret new messages in the context of previous ones.

ConversationBufferMemory

The ConversationBufferMemory component is a type of memory system that stores the last few inputs and outputs of a conversation.

Parameters:

  • input_key: Used to specify the key under which the user input will be stored in the conversation memory. It allows you to provide the user's input to the chain for processing and generating a response.

  • memory_key: It specifies the prompt variable name where the memory will store and retrieve the chat messages, with the default name being 'chat_history.

  • output_key: Used to specify the key under which the generated response will be stored in the conversation memory. It allows you to retrieve the response using the specified key.

  • return_messages: Determines whether the history should be returned as a string or as a list of messages. If return_messages is set to True, the history will be returned as a list of messages. If return_messages is set to False or not specified, the history will be returned as a string. The default is False.

ConversationBufferWindowMemory

It is a variation of the ConversationBufferMemory. It only keeps the last K interactions in memory, which can be useful for maintaining a sliding window of the most recent interactions without letting the buffer get too large.

Parameters:

  • input_key: Used to specify the key under which the user input will be stored in the conversation memory. It allows you to provide the user's input to the chain for processing and generating a response.

  • memory_key: Specifies the prompt variable name where the memory will store and retrieve the chat messages – defaults to chat_history.

  • k: It determines the size of the sliding window that keeps track of the most recent interactions.

  • output_key: Used to specify the key under which the generated response will be stored in the conversation memory. It allows you to retrieve the response using the specified key.

  • return_messages: Determines whether the history should be returned as a string or as a list of messages. If return_messages is set to True, the history will be returned as a list of messages. If return_messages is set to False or not specified, the history will be returned as a string. The default is False.

ConversationEntityMemory

The ConversationEntityMemory component remembers given facts about specific entities in a conversation. It extracts information on entities (using an LLM) and builds up its knowledge about that entity over time (also using an LLM).

Parameters:

  • LLM: Language Model to use in the ConversationEntityMemory.

  • chat_history_key: Specify a unique identifier for the chat history data associated with a particular entity. This allows for organizing and accessing the chat history data for each entity within the conversation entity memory. Defaults to history.

  • input_key: Used to specify the keys in the memory object where the input messages should be stored. It allows for the retrieval and manipulation of input messages.

  • k: Refers to the number of entities that can be stored in the memory. It determines the maximum number of entities that can be stored and retrieved from the memory object. Defaults to 10.

  • output_key: Used to specify the key under which the generated response will be stored in the conversation memory. It allows you to retrieve the response using the specified key.

  • return_messages: Determines whether the history should be returned as a string or as a list of messages. If return_messages is set to True, the history will be returned as a list of messages. If return_messages is set to False or not specified, the history will be returned as a string. The default is False.

ConversationSummaryMemory

The ConversationSummaryMemory is a memory component that creates a summary of the conversation over time. It is particularly useful for longer conversations where keeping the entire message history in the prompt would take up too many tokens.

Parameters:

  • LLM: Language Model to be used.

  • input_key: Used to specify the keys in the memory object where the input messages should be stored. It allows for the retrieval and manipulation of input messages.

  • memory_key: Specifies the prompt variable name where the memory will store and retrieve the chat messages. It allows for the preservation of the conversation history throughout the interaction with the language model. Defaults to chat_history.

  • output_key: Used to specify the key under which the generated response will be stored in the conversation memory. It allows you to retrieve the response using the specified key.

  • return_messages: Determines whether the history should be returned as a string or as a list of messages. If return_messages is set to True, the history will be returned as a list of messages. If return_messages is set to False or not specified, the history will be returned as a string. The default is False.

ConversationKGMemory

ConversationKGMemory is a type of memory that uses a knowledge graph to recreate memory. It allows the extraction of entities and knowledge triplets from a new message, using previous messages as context.

Parameters

  • LLM: Language Model to use.

  • input_key: Used to specify the keys in the memory object where the input messages should be stored. It allows for the retrieval and manipulation of input messages.

  • k: Represents the number of previous conversation turns that will be stored in the memory. The default is set to 10.

  • memory_key: Specifies the prompt variable name where the memory will store and retrieve the chat messages. It allows for the preservation of the conversation history throughout the interaction with the language model. Defaults to chat_history.

  • output_key: Used to specify the key under which the generated response will be stored in the conversation memory. It allows you to retrieve the response using the specified key.

  • return_messages: Determines whether the history should be returned as a string or as a list of messages. If return_messages is set to True, the history will be returned as a list of messages. If return_messages is set to False or not specified, the history will be returned as a string. The default is False.

Last updated