langchain.memory.chat_message_histories.mongodb.MongoDBChatMessageHistory

class langchain.memory.chat_message_histories.mongodb.MongoDBChatMessageHistory(connection_string: str, session_id: str, database_name: str = 'chat_history', collection_name: str = 'message_store')[source]

Chat message history that stores history in MongoDB.

Parameters
  • connection_string – connection string to connect to MongoDB

  • session_id – arbitrary key that is used to store the messages of a single chat session.

  • database_name – name of the database to use

  • collection_name – name of the collection to use

Attributes

messages

Retrieve the messages from MongoDB

Methods

__init__(connection_string, session_id[, ...])

add_ai_message(message)

Convenience method for adding an AI message string to the store.

add_message(message)

Append the message to the record in MongoDB

add_user_message(message)

Convenience method for adding a human message string to the store.

clear()

Clear session memory from MongoDB

__init__(connection_string: str, session_id: str, database_name: str = 'chat_history', collection_name: str = 'message_store')[source]
add_ai_message(message: str) None

Convenience method for adding an AI message string to the store.

Parameters

message – The string contents of an AI message.

add_message(message: BaseMessage) None[source]

Append the message to the record in MongoDB

add_user_message(message: str) None

Convenience method for adding a human message string to the store.

Parameters

message – The string contents of a human message.

clear() None[source]

Clear session memory from MongoDB

Examples using MongoDBChatMessageHistory