Memory
Redis-Backed Chat Memory
The Redis-Backed Chat Memory node is a component that provides long-term memory storage for chat conversations using Redis as the backend. It summarizes and stores conversation history, allowing for persistent and scalable chat memory across sessions.
Node Details
- Name: RedisBackedChatMemory
- Type: RedisBackedChatMemory
- Version: 2.0
- Category: Memory
Base Classes
- RedisBackedChatMemory
- BufferMemory (and its base classes)
Parameters
Credential
- Type: credential
- Credential Names: redisCacheApi, redisCacheUrlApi
- Description: Redis connection credentials
Credential
- Type: credential
- Credential Names: redisCacheApi, redisCacheUrlApi
- Description: Redis connection credentials
Inputs
-
Session Id (optional)
-
Session Id (optional)
- Type: string
- Default: Empty string
- Description: Unique identifier for the chat session. If not specified, a random id will be used
- Description: Unique identifier for the chat session. If not specified, a random id will be used
-
Session Timeouts (optional)
-
Session Timeouts (optional)
- Type: number
- Description: Time-to-live (TTL) for the session in seconds. Omit this parameter to make sessions never expire
- Description: Time-to-live (TTL) for the session in seconds. Omit this parameter to make sessions never expire
-
Memory Key
- Type: string
- Default: “chat_history”
- Description: Key used to store and retrieve the chat history in Redis
- Description: Key used to store and retrieve the chat history in Redis
-
Window Size (optional)
-
Window Size (optional)
- Type: number
- Description: Number of recent back-and-forth interactions to use as memory context
- Description: Number of recent back-and-forth interactions to use as memory context
Functionality
-
Initialization:
- Connects to Redis using provided credentials (either URL or individual connection parameters).
- Sets up a RedisChatMessageHistory instance for managing chat history.
- Creates a BufferMemoryExtended instance for handling memory operations.
-
Memory Operations:
- getChatMessages: Retrieves chat messages from Redis, with options for windowing and prepending messages.
- addChatMessages: Adds new messages (both user and AI) to the Redis store.
- clearChatMessages: Deletes all messages for a given session from Redis.
-
Session Management:
- Supports session-based storage using session IDs.
- Optional session timeout (TTL) for automatic expiration of old sessions.
Use Cases
- Long-running chatbots that need to maintain context across multiple interactions.
- Multi-user chat systems where each user’s history needs to be stored separately.
- Applications requiring scalable and persistent chat memory storage.
Integration
This node can be used in a AI solution to provide long-term memory capabilities to language models or other AI components that benefit from conversation history.
Notes
- Ensure that a Redis server is properly set up and accessible for this node to function correctly.
- When using in production, consider security implications and ensure proper authentication and encryption for Redis connections.
- The window size parameter can be used to limit the amount of history provided to AI models, which can be useful for managing token limits or focusing on recent context.
Was this page helpful?