Memory
MongoDB Atlas Chat Memory
The MongoDB Atlas Chat Memory node is a component designed to store conversation history in MongoDB Atlas. It extends the functionality of BufferMemory to provide persistent storage of chat messages using MongoDB as the backend.
Node Details
- Name: MongoDBAtlasChatMemory
- Type: MongoDBAtlasChatMemory
- Version: 1.0
- Category: Memory
Base Classes
- BufferMemory
- BufferMemoryExtended
Parameters
Credential
- Label: Connect Credential
- Name: credential
- Type: credential
- Credential Names: mongoDBUrlApi
- Description: MongoDB Atlas connection credentials
- Description: MongoDB Atlas connection credentials
Inputs
-
Database
- Label: Database
- Name: databaseName
- Type: string
- Placeholder: “mongodb+srv://username:password@cluster.mongodb.net/
DB_NAME
” - Description: MongoDB Atlas database name
- Description: MongoDB Atlas database name
-
Collection Name
- Label: Collection Name
- Name: collectionName
- Type: string
- Placeholder:
<COLLECTION_NAME>
- Description: Name of the collection to store chat messages
- Description: Name of the collection to store chat messages
-
Session Id (Optional)
- Label: Session Id
- Name: sessionId
- 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
-
Memory Key (Additional Parameter)
- Label: Memory Key
- Name: memoryKey
- Type: string
- Default: ‘chat_history’
- Description: Key used to store the chat history in memory
- Description: Key used to store the chat history in memory
Functionality
-
Initialization:
- Connects to MongoDB Atlas using the provided credential.
- Creates a MongoDBChatMessageHistory instance.
- Initializes a BufferMemoryExtended instance.
-
Message Storage:
- Stores messages as documents in the specified MongoDB collection.
- Each document represents a chat session, identified by a sessionId.
-
Message Retrieval:
- Retrieves messages for a specific session from MongoDB.
- Converts stored messages to BaseMessage objects.
-
Memory Management:
- Supports adding new messages to the chat history.
- Allows clearing of chat history for a specific session.
-
Extended Functionality:
- Implements MemoryMethods interface for advanced memory operations.
- Supports overriding sessionId for flexible message management.
Use Cases
- Long-term storage of conversation history.
- Maintaining separate chat histories for different users or contexts.
- Integrating persistent memory in chatbots or conversational AI systems.
Notes
- This node uses a singleton pattern for MongoDB client management to optimize connections.
- It extends the base BufferMemory class to provide MongoDB-specific functionality.
- The node supports both adding individual messages and bulk message operations.
Was this page helpful?