langchain_community.chat_message_histories.sql.SQLChatMessageHistory¶

class langchain_community.chat_message_histories.sql.SQLChatMessageHistory(session_id: str, connection_string: str, table_name: str = 'message_store', session_id_field_name: str = 'session_id', custom_message_converter: Optional[BaseMessageConverter] = None)[source]¶

Chat message history stored in an SQL database.

Attributes

messages

Retrieve all messages from db

Methods

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

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 db

add_user_message(message)

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

clear()

Clear session memory from db

__init__(session_id: str, connection_string: str, table_name: str = 'message_store', session_id_field_name: str = 'session_id', custom_message_converter: Optional[BaseMessageConverter] = None)[source]¶
add_ai_message(message: Union[AIMessage, str]) None¶

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

Parameters

message – The AI message to add.

add_message(message: BaseMessage) None[source]¶

Append the message to the record in db

add_user_message(message: Union[HumanMessage, str]) None¶

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

Parameters

message – The human message to add

clear() None[source]¶

Clear session memory from db

Examples using SQLChatMessageHistory¶