SingleStoreDBChatMessageHistory#
- class langchain_community.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.
session_id (str) β
kwargs (Any) β
Examples
Basic Usage:
from langchain_community.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_community.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_community.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.
aadd_messages
(messages)Async add a list of messages.
aclear
()Async remove all messages from the store
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_messages
(messages)Add a list of messages.
add_user_message
(message)Convenience method for adding a human message string to the store.
Async version of getting messages.
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.
session_id (str) β
kwargs (Any) β
Examples
Basic Usage:
from langchain_community.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_community.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_community.chat_message_histories import ( SingleStoreDBChatMessageHistory ) os.environ['SINGLESTOREDB_URL'] = 'me:p455w0rd@s2-host.com/my_db' message_history = SingleStoreDBChatMessageHistory("my-session")
- async aadd_messages(messages: Sequence[BaseMessage]) None #
Async add a list of messages.
- Parameters:
messages (Sequence[BaseMessage]) β A sequence of BaseMessage objects to store.
- Return type:
None
- async aclear() None #
Async remove all messages from the store
- Return type:
None
- add_ai_message(message: AIMessage | str) None #
Convenience method for adding an AI message string to the store.
Please note that this is a convenience method. Code should favor the bulk add_messages interface instead to save on round-trips to the underlying persistence layer.
This method may be deprecated in a future release.
- Parameters:
message (AIMessage | str) β The AI message to add.
- Return type:
None
- add_message(message: BaseMessage) None [source]#
Append the message to the record in SingleStoreDB
- Parameters:
message (BaseMessage) β
- Return type:
None
- add_messages(messages: Sequence[BaseMessage]) None #
Add a list of messages.
Implementations should over-ride this method to handle bulk addition of messages in an efficient manner to avoid unnecessary round-trips to the underlying store.
- Parameters:
messages (Sequence[BaseMessage]) β A sequence of BaseMessage objects to store.
- Return type:
None
- add_user_message(message: HumanMessage | str) None #
Convenience method for adding a human message string to the store.
Please note that this is a convenience method. Code should favor the bulk add_messages interface instead to save on round-trips to the underlying persistence layer.
This method may be deprecated in a future release.
- Parameters:
message (HumanMessage | str) β The human message to add to the store.
- Return type:
None
- async aget_messages() List[BaseMessage] #
Async version of getting messages.
Can over-ride this method to provide an efficient async implementation.
In general, fetching messages may involve IO to the underlying persistence layer.
- Return type:
List[BaseMessage]
Examples using SingleStoreDBChatMessageHistory