langchain.memory.chat_message_histories.singlestoredb.SingleStoreDBChatMessageHistory

class langchain.memory.chat_message_histories.singlestoredb.SingleStoreDBChatMessageHistory(session_id: str, *, table_name: str = 'message_store', id_field: str = 'id', session_id_field: str = 'session_id', message_field: str = 'message', pool_size: int = 5, max_overflow: int = 10, timeout: float = 30, **kwargs: Any)[source]

Chat message history stored in a SingleStoreDB database.

Initialize with necessary components.

Parameters
  • table_name (str, optional) – Specifies the name of the table in use. Defaults to “message_store”.

  • id_field (str, optional) – Specifies the name of the id field in the table. Defaults to “id”.

  • session_id_field (str, optional) – Specifies the name of the session_id field in the table. Defaults to “session_id”.

  • message_field (str, optional) – Specifies the name of the message field in the table. Defaults to “message”.

  • pool (Following arguments pertain to the connection) –

  • pool_size (int, optional) – Determines the number of active connections in the pool. Defaults to 5.

  • max_overflow (int, optional) – Determines the maximum number of connections allowed beyond the pool_size. Defaults to 10.

  • timeout (float, optional) – Specifies the maximum wait time in seconds for establishing a connection. Defaults to 30.

  • connection (database) –

  • host (str, optional) – Specifies the hostname, IP address, or URL for the database connection. The default scheme is “mysql”.

  • user (str, optional) – Database username.

  • password (str, optional) – Database password.

  • port (int, optional) – Database port. Defaults to 3306 for non-HTTP connections, 80 for HTTP connections, and 443 for HTTPS connections.

  • database (str, optional) – Database name.

  • the (Additional optional arguments provide further customization over) –

  • connection

  • pure_python (bool, optional) – Toggles the connector mode. If True, operates in pure Python mode.

  • local_infile (bool, optional) – Allows local file uploads.

  • charset (str, optional) – Specifies the character set for string values.

  • ssl_key (str, optional) – Specifies the path of the file containing the SSL key.

  • ssl_cert (str, optional) – Specifies the path of the file containing the SSL certificate.

  • ssl_ca (str, optional) – Specifies the path of the file containing the SSL certificate authority.

  • ssl_cipher (str, optional) – Sets the SSL cipher list.

  • ssl_disabled (bool, optional) – Disables SSL usage.

  • ssl_verify_cert (bool, optional) – Verifies the server’s certificate. Automatically enabled if ssl_ca is specified.

  • ssl_verify_identity (bool, optional) – Verifies the server’s identity.

  • conv (dict[int, Callable], optional) – A dictionary of data conversion functions.

  • credential_type (str, optional) – Specifies the type of authentication to use: auth.PASSWORD, auth.JWT, or auth.BROWSER_SSO.

  • autocommit (bool, optional) – Enables autocommits.

  • results_type (str, optional) – Determines the structure of the query results: tuples, namedtuples, dicts.

  • results_format (str, optional) – Deprecated. This option has been renamed to results_type.

Examples

Basic Usage:

from langchain.memory.chat_message_histories import (
    SingleStoreDBChatMessageHistory
)

message_history = SingleStoreDBChatMessageHistory(
    session_id="my-session",
    host="https://user:password@127.0.0.1:3306/database"
)

Advanced Usage:

from langchain.memory.chat_message_histories import (
    SingleStoreDBChatMessageHistory
)

message_history = SingleStoreDBChatMessageHistory(
    session_id="my-session",
    host="127.0.0.1",
    port=3306,
    user="user",
    password="password",
    database="db",
    table_name="my_custom_table",
    pool_size=10,
    timeout=60,
)

Using environment variables:

from langchain.memory.chat_message_histories import (
    SingleStoreDBChatMessageHistory
)

os.environ['SINGLESTOREDB_URL'] = 'me:p455w0rd@s2-host.com/my_db'
message_history = SingleStoreDBChatMessageHistory("my-session")

Attributes

messages

Retrieve the messages from SingleStoreDB

Methods

__init__(session_id, *[, table_name, ...])

Initialize with necessary components.

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 SingleStoreDB

add_user_message(message)

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

clear()

Clear session memory from SingleStoreDB

__init__(session_id: str, *, table_name: str = 'message_store', id_field: str = 'id', session_id_field: str = 'session_id', message_field: str = 'message', pool_size: int = 5, max_overflow: int = 10, timeout: float = 30, **kwargs: Any)[source]

Initialize with necessary components.

Parameters
  • table_name (str, optional) – Specifies the name of the table in use. Defaults to “message_store”.

  • id_field (str, optional) – Specifies the name of the id field in the table. Defaults to “id”.

  • session_id_field (str, optional) – Specifies the name of the session_id field in the table. Defaults to “session_id”.

  • message_field (str, optional) – Specifies the name of the message field in the table. Defaults to “message”.

  • pool (Following arguments pertain to the connection) –

  • pool_size (int, optional) – Determines the number of active connections in the pool. Defaults to 5.

  • max_overflow (int, optional) – Determines the maximum number of connections allowed beyond the pool_size. Defaults to 10.

  • timeout (float, optional) – Specifies the maximum wait time in seconds for establishing a connection. Defaults to 30.

  • connection (database) –

  • host (str, optional) – Specifies the hostname, IP address, or URL for the database connection. The default scheme is “mysql”.

  • user (str, optional) – Database username.

  • password (str, optional) – Database password.

  • port (int, optional) – Database port. Defaults to 3306 for non-HTTP connections, 80 for HTTP connections, and 443 for HTTPS connections.

  • database (str, optional) – Database name.

  • the (Additional optional arguments provide further customization over) –

  • connection

  • pure_python (bool, optional) – Toggles the connector mode. If True, operates in pure Python mode.

  • local_infile (bool, optional) – Allows local file uploads.

  • charset (str, optional) – Specifies the character set for string values.

  • ssl_key (str, optional) – Specifies the path of the file containing the SSL key.

  • ssl_cert (str, optional) – Specifies the path of the file containing the SSL certificate.

  • ssl_ca (str, optional) – Specifies the path of the file containing the SSL certificate authority.

  • ssl_cipher (str, optional) – Sets the SSL cipher list.

  • ssl_disabled (bool, optional) – Disables SSL usage.

  • ssl_verify_cert (bool, optional) – Verifies the server’s certificate. Automatically enabled if ssl_ca is specified.

  • ssl_verify_identity (bool, optional) – Verifies the server’s identity.

  • conv (dict[int, Callable], optional) – A dictionary of data conversion functions.

  • credential_type (str, optional) – Specifies the type of authentication to use: auth.PASSWORD, auth.JWT, or auth.BROWSER_SSO.

  • autocommit (bool, optional) – Enables autocommits.

  • results_type (str, optional) – Determines the structure of the query results: tuples, namedtuples, dicts.

  • results_format (str, optional) – Deprecated. This option has been renamed to results_type.

Examples

Basic Usage:

from langchain.memory.chat_message_histories import (
    SingleStoreDBChatMessageHistory
)

message_history = SingleStoreDBChatMessageHistory(
    session_id="my-session",
    host="https://user:password@127.0.0.1:3306/database"
)

Advanced Usage:

from langchain.memory.chat_message_histories import (
    SingleStoreDBChatMessageHistory
)

message_history = SingleStoreDBChatMessageHistory(
    session_id="my-session",
    host="127.0.0.1",
    port=3306,
    user="user",
    password="password",
    database="db",
    table_name="my_custom_table",
    pool_size=10,
    timeout=60,
)

Using environment variables:

from langchain.memory.chat_message_histories import (
    SingleStoreDBChatMessageHistory
)

os.environ['SINGLESTOREDB_URL'] = 'me:p455w0rd@s2-host.com/my_db'
message_history = SingleStoreDBChatMessageHistory("my-session")
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 SingleStoreDB

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 SingleStoreDB