Tony20100/langchain_full huggingface dataset:
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 (Union[HumanMessage, str]) – The human message to add
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]
clear() → None[source]¶
Clear session memory from this memory and Firestore.
Return type
None
load_messages() → None[source]¶
Retrieve the messages from Firestore
Return type
None
prepare_firestore() → None[source]¶
Prepare the Firestore client.
Use this function to make sure your database is ready.
Return type
None
upsert_messages(new_message: Optional[BaseMessage] = None) → None[source]¶
Update the Firestore document.
Parameters
new_message (Optional[BaseMessage]) – 
Return type
None
langchain_community.chat_message_histories.upstash_redis.UpstashRedisChatMessageHistory¶
class langchain_community.chat_message_histories.upstash_redis.UpstashRedisChatMessageHistory(session_id: str, url: str = '', token: str = '', key_prefix: str = 'message_store:', ttl: Optional[int] = None)[source]¶
Chat message history stored in an Upstash Redis database.
Attributes
key
Construct the record key to use
messages
Retrieve the messages from Upstash Redis
Methods
__init__(session_id[, url, token, ...])
aadd_messages(messages)
Add a list of messages.
aclear()
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 Upstash Redis
add_messages(messages)
Add a list of messages.
add_user_message(message)
Convenience method for adding a human message string to the store.
aget_messages()
Async version of getting messages.
clear()
Clear session memory from Upstash Redis
Parameters
session_id (str) – 
url (str) – 
token (str) – 
key_prefix (str) – 
ttl (Optional[int]) – 
__init__(session_id: str, url: str = '', token: str = '', key_prefix: str = 'message_store:', ttl: Optional[int] = None)[source]¶
Parameters
session_id (str) – 
url (str) – 
token (str) – 
key_prefix (str) – 
ttl (Optional[int]) – 
async aadd_messages(messages: Sequence[BaseMessage]) → None¶
Add a list of messages.
Parameters
messages (Sequence[BaseMessage]) – A list of BaseMessage objects to store.
Return type
Return type
None
async aclear() → None¶
Remove all messages from the store
Return type
None
add_ai_message(message: Union[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 (Union[AIMessage, str]) – The AI message to add.
Return type
None
add_message(message: BaseMessage) → None[source]¶
Append the message to the record in Upstash Redis
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 list of BaseMessage objects to store.
Return type
None
add_user_message(message: Union[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 (Union[HumanMessage, str]) – The human message to add
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]
langchain_community.chat_message_histories.streamlit.StreamlitChatMessageHistory¶
class langchain_community.chat_message_histories.streamlit.StreamlitChatMessageHistory(key: str = 'langchain_messages')[source]¶
Chat message history that stores messages in Streamlit session state.
Parameters
key (str) – The key to use in Streamlit session state for storing messages.
Attributes
messages
Retrieve the current list of messages
Methods
__init__([key])
aadd_messages(messages)
Add a list of messages.
aclear()
Remove all messages from the store
add_ai_message(message)
Convenience method for adding an AI message string to the store.
add_message(message)
Add a message to the session memory
add_messages(messages)
Add a list of messages.
add_user_message(message)
Convenience method for adding a human message string to the store.
aget_messages()
Async version of getting messages.
clear()
Clear session memory
__init__(key: str = 'langchain_messages')[source]¶
Parameters
key (str) – 
async aadd_messages(messages: Sequence[BaseMessage]) → None¶
Add a list of messages.
Parameters
messages (Sequence[BaseMessage]) – A list of BaseMessage objects to store.
Return type
None
async aclear() → None¶
Remove all messages from the store
Return type
None
add_ai_message(message: Union[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 (Union[AIMessage, str]) – The AI message to add.
Return type
None
Return type
None
add_message(message: BaseMessage) → None[source]¶
Add a message to the session memory
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 list of BaseMessage objects to store.
Return type
None
add_user_message(message: Union[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 (Union[HumanMessage, str]) – The human message to add
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]
clear() → None[source]¶
Clear session memory
Return type
None
Examples using StreamlitChatMessageHistory¶
Streamlit
langchain_community.chat_message_histories.sql.SQLChatMessageHistory¶
class langchain_community.chat_message_histories.sql.SQLChatMessageHistory(session_id: str, connection_string: Optional[str] = None, table_name: str = 'message_store', session_id_field_name: str = 'session_id', custom_message_converter: Optional[BaseMessageConverter] = None, connection: Union[None, AsyncEngine, Engine, str] = None, engine_args: Optional[Dict[str, Any]] = None, async_mode: Optional[bool] = None)[source]¶
Chat message history stored in an SQL database.
Attributes
Session
[Deprecated]
messages
Retrieve all messages from db
Methods
__init__(session_id[, connection_string, ...])
aadd_message(message)
Add a Message object to the store.
aadd_messages(messages)
Add a list of messages.
aclear()
Clear session memory from db
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_messages(messages)
Add a list of messages.
add_user_message(message)
Convenience method for adding a human message string to the store.
aget_messages()
Retrieve all messages from db
clear()
Clear session memory from db
get_messages()
Parameters
session_id (str) – 
connection_string (Optional[str]) – 
table_name (str) – 
session_id_field_name (str) – 
custom_message_converter (Optional[BaseMessageConverter]) – 
connection (Union[None, AsyncEngine, Engine, str]) – 
engine_args (Optional[Dict[str, Any]]) – 
async_mode (Optional[bool]) –
async_mode (Optional[bool]) – 
__init__(session_id: str, connection_string: Optional[str] = None, table_name: str = 'message_store', session_id_field_name: str = 'session_id', custom_message_converter: Optional[BaseMessageConverter] = None, connection: Union[None, AsyncEngine, Engine, str] = None, engine_args: Optional[Dict[str, Any]] = None, async_mode: Optional[bool] = None)[source]¶
Parameters
session_id (str) – 
connection_string (Optional[str]) – 
table_name (str) – 
session_id_field_name (str) – 
custom_message_converter (Optional[BaseMessageConverter]) – 
connection (Union[None, AsyncEngine, Engine, str]) – 
engine_args (Optional[Dict[str, Any]]) – 
async_mode (Optional[bool]) – 
async aadd_message(message: BaseMessage) → None[source]¶
Add a Message object to the store.
Parameters
message (BaseMessage) – A BaseMessage object to store.
Return type
None
async aadd_messages(messages: Sequence[BaseMessage]) → None[source]¶
Add a list of messages.
Parameters
messages (Sequence[BaseMessage]) – A list of BaseMessage objects to store.
Return type
None
async aclear() → None[source]¶
Clear session memory from db
Return type
None
add_ai_message(message: Union[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
persistence layer.
This method may be deprecated in a future release.
Parameters
message (Union[AIMessage, str]) – The AI message to add.
Return type
None
add_message(message: BaseMessage) → None[source]¶
Append the message to the record in db
Parameters
message (BaseMessage) – 
Return type
None
add_messages(messages: Sequence[BaseMessage]) → None[source]¶
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 list of BaseMessage objects to store.
Return type
None
add_user_message(message: Union[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 (Union[HumanMessage, str]) – The human message to add
Return type
None
async aget_messages() → List[BaseMessage][source]¶
Retrieve all messages from db
Return type
List[BaseMessage]
clear() → None[source]¶
Clear session memory from db
Return type
None
get_messages() → List[BaseMessage][source]¶
Return type
List[BaseMessage]
Examples using SQLChatMessageHistory¶
How to add message history
SQL (SQLAlchemy)
SQLite
langchain_community.chat_message_histories.tidb.TiDBChatMessageHistory¶
class langchain_community.chat_message_histories.tidb.TiDBChatMessageHistory(session_id: str, connection_string: str, table_name: str = 'langchain_message_store', earliest_time: Optional[datetime] = None)[source]¶
Represents a chat message history stored in a TiDB database.
Initializes a new instance of the TiDBChatMessageHistory class.
Parameters
session_id (str) – The ID of the chat session.
connection_string (str) – The connection string for the TiDB database.
format: mysql+pymysql://<host>:<PASSWORD>@<host>:4000/<db>?ssl_ca=/etc/ssl/cert.pem&ssl_verify_cert=true&ssl_verify_identity=true
table_name (str, optional) – the table name to store the chat messages.
Defaults to “langchain_message_store”.
earliest_time (Optional[datetime], optional) – The earliest time to retrieve messages from.
Defaults to None.
Attributes
messages
returns all messages
Methods
__init__(session_id, connection_string[, ...])
Initializes a new instance of the TiDBChatMessageHistory class.
aadd_messages(messages)
Add a list of messages.
aclear()
Remove all messages from the store
add_ai_message(message)
Convenience method for adding an AI message string to the store.
add_message(message)
adds a message to the database and cache
add_messages(messages)
Add a list of messages.
add_user_message(message)
Convenience method for adding a human message string to the store.
aget_messages()
Async version of getting messages.
clear()
clears all messages
reload_cache()
reloads messages from database to cache
clear()
clears all messages
reload_cache()
reloads messages from database to cache
__init__(session_id: str, connection_string: str, table_name: str = 'langchain_message_store', earliest_time: Optional[datetime] = None)[source]¶
Initializes a new instance of the TiDBChatMessageHistory class.
Parameters
session_id (str) – The ID of the chat session.
connection_string (str) – The connection string for the TiDB database.
format: mysql+pymysql://<host>:<PASSWORD>@<host>:4000/<db>?ssl_ca=/etc/ssl/cert.pem&ssl_verify_cert=true&ssl_verify_identity=true
table_name (str, optional) – the table name to store the chat messages.
Defaults to “langchain_message_store”.
earliest_time (Optional[datetime], optional) – The earliest time to retrieve messages from.
Defaults to None.
async aadd_messages(messages: Sequence[BaseMessage]) → None¶
Add a list of messages.
Parameters
messages (Sequence[BaseMessage]) – A list of BaseMessage objects to store.
Return type
None
async aclear() → None¶
Remove all messages from the store
Return type
None
add_ai_message(message: Union[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 (Union[AIMessage, str]) – The AI message to add.
Return type
None
add_message(message: BaseMessage) → None[source]¶
adds a message to the database and cache
Parameters
message (BaseMessage) – 
Return type
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 list of BaseMessage objects to store.
Return type
None
add_user_message(message: Union[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 (Union[HumanMessage, str]) – The human message to add
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]
clear() → None[source]¶
clears all messages
Return type
None
reload_cache() → None[source]¶
reloads messages from database to cache
Return type
None
Examples using TiDBChatMessageHistory¶
TiDB
langchain_community.chat_message_histories.neo4j.Neo4jChatMessageHistory¶
class langchain_community.chat_message_histories.neo4j.Neo4jChatMessageHistory(session_id: Union[str, int], url: Optional[str] = None, username: Optional[str] = None, password: Optional[str] = None, database: str = 'neo4j', node_label: str = 'Session', window: int = 3, *, graph: Optional[Neo4jGraph] = None)[source]¶
Chat message history stored in a Neo4j database.
Attributes
messages
Retrieve the messages from Neo4j
Methods
__init__(session_id[, url, username, ...])
aadd_messages(messages)
Add a list of messages.
aclear()
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 Neo4j
add_messages(messages)
Add a list of messages.
add_user_message(message)
Convenience method for adding a human message string to the store.
aget_messages()
Async version of getting messages.
clear()
Clear session memory from Neo4j
Parameters
session_id (Union[str, int]) – 
url (Optional[str]) – 
username (Optional[str]) – 
password (Optional[str]) – 
database (str) – 
node_label (str) – 
window (int) – 
graph (Optional[Neo4jGraph]) –
window (int) – 
graph (Optional[Neo4jGraph]) – 
__init__(session_id: Union[str, int], url: Optional[str] = None, username: Optional[str] = None, password: Optional[str] = None, database: str = 'neo4j', node_label: str = 'Session', window: int = 3, *, graph: Optional[Neo4jGraph] = None)[source]¶
Parameters
session_id (Union[str, int]) – 
url (Optional[str]) – 
username (Optional[str]) – 
password (Optional[str]) – 
database (str) – 
node_label (str) – 
window (int) – 
graph (Optional[Neo4jGraph]) – 
async aadd_messages(messages: Sequence[BaseMessage]) → None¶
Add a list of messages.
Parameters
messages (Sequence[BaseMessage]) – A list of BaseMessage objects to store.
Return type
None
async aclear() → None¶
Remove all messages from the store
Return type
None
add_ai_message(message: Union[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 (Union[AIMessage, str]) – The AI message to add.
Return type
None
add_message(message: BaseMessage) → None[source]¶
Append the message to the record in Neo4j
Parameters
message (BaseMessage) – 
Return type
None
add_messages(messages: Sequence[BaseMessage]) → None¶
Add a list of messages.
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 list of BaseMessage objects to store.
Return type
None
add_user_message(message: Union[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 (Union[HumanMessage, str]) – The human message to add
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]
clear() → None[source]¶
Clear session memory from Neo4j
Return type
None
Examples using Neo4jChatMessageHistory¶
Neo4j
langchain_community.chat_message_histories.xata.XataChatMessageHistory¶
class langchain_community.chat_message_histories.xata.XataChatMessageHistory(session_id: str, db_url: str, api_key: str, branch_name: str = 'main', table_name: str = 'messages', create_table: bool = True)[source]¶
Chat message history stored in a Xata database.
Initialize with Xata client.
Attributes
messages
Methods
__init__(session_id, db_url, api_key[, ...])
Initialize with Xata client.
aadd_messages(messages)
Add a list of messages.
aclear()
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 Xata table
add_messages(messages)
Add a list of messages.
add_user_message(message)
Convenience method for adding a human message string to the store.
aget_messages()
Async version of getting messages.
clear()
Delete session from Xata table.
Parameters
session_id (str) – 
db_url (str) – 
api_key (str) – 
branch_name (str) – 
table_name (str) – 
create_table (bool) – 
__init__(session_id: str, db_url: str, api_key: str, branch_name: str = 'main', table_name: str = 'messages', create_table: bool = True) → None[source]¶
Initialize with Xata client.
Parameters
session_id (str) – 
db_url (str) – 
api_key (str) – 
branch_name (str) – 
table_name (str) – 
create_table (bool) – 
Return type
None
create_table (bool) – 
Return type
None
async aadd_messages(messages: Sequence[BaseMessage]) → None¶
Add a list of messages.
Parameters
messages (Sequence[BaseMessage]) – A list of BaseMessage objects to store.
Return type
None
async aclear() → None¶
Remove all messages from the store
Return type
None
add_ai_message(message: Union[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 (Union[AIMessage, str]) – The AI message to add.
Return type
None
add_message(message: BaseMessage) → None[source]¶
Append the message to the Xata table
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 list of BaseMessage objects to store.
Return type
None
add_user_message(message: Union[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 (Union[HumanMessage, str]) – The human message to add
Return type
None
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]
clear() → None[source]¶
Delete session from Xata table.
Return type
None
Examples using XataChatMessageHistory¶
Xata