githubEdit

Chat Message History

MariaDBChatMessageHistory persists LangChain conversation history to a MariaDB database table, providing methods to add, retrieve, and clear messages per session.

Version: langchain-mariadb v0.0.21

Client for persisting chat message history in a MariaDB database.

MariaDBChatMessageHistory

Chat message history that persists to a MariaDB database.

Constructor

__init__(
    table_name: str,
    session_id: str,
    datasource: Union[Engine | str],
    engine_args: Optional[dict[str, Any]] = None
) -> None

Initialize a chat message history that persists to a MariaDB database.

Parameters:

  • table_name (str): Name of the database table to use (must be alphanum + '_')

  • session_id (str): UUID string to identify the chat session

  • datasource (Union[Engine | str]): datasource (connection string or a sqlalchemy engine)

Raises:

  • ValueError: If pool is not provided, session_id is not a valid UUID, or table_name contains invalid characters

Methods

create_tables

Create the table schema in the database and create relevant indexes.

Parameters:

  • datasource (Union[Engine | str]): datasource (connection string or sqlalchemy engine)

  • table_name (str): Name of the table to create

drop_table

Delete the table schema from the database.

Parameters:

  • datasource (Union[Engine | str]): datasource (connection string or sqlalchemy engine)

  • table_name (str): Name of the table to drop

add_messages

Add messages to the chat history.

Parameters:

  • messages (Sequence[BaseMessage]): Sequence of messages to add

get_messages

Retrieve messages from the chat history.

Returns:

List[BaseMessage] - List of messages in chronological order

clear

Clear all messages for the current session.

Attributes

  • messages (List[BaseMessage]): Get all messages in the chat history.


Last updated

Was this helpful?