langchain.memory.chat_message_histories.firestore.FirestoreChatMessageHistory

class langchain.memory.chat_message_histories.firestore.FirestoreChatMessageHistory(collection_name: str, session_id: str, user_id: str, firestore_client: Optional[Client] = None)[source]

Chat message history backed by Google Firestore.

Initialize a new instance of the FirestoreChatMessageHistory class.

Parameters
  • collection_name – The name of the collection to use.

  • session_id – The session ID for the chat..

  • user_id – The user ID for the chat.

Attributes

messages

A list of Messages stored in-memory.

Methods

__init__(collection_name, session_id, user_id)

Initialize a new instance of the FirestoreChatMessageHistory class.

add_ai_message(message)

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

add_message(message)

Add a Message object to the store.

add_user_message(message)

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

clear()

Clear session memory from this memory and Firestore.

load_messages()

Retrieve the messages from Firestore

prepare_firestore()

Prepare the Firestore client.

upsert_messages([new_message])

Update the Firestore document.

__init__(collection_name: str, session_id: str, user_id: str, firestore_client: Optional[Client] = None)[source]

Initialize a new instance of the FirestoreChatMessageHistory class.

Parameters
  • collection_name – The name of the collection to use.

  • session_id – The session ID for the chat..

  • user_id – The user ID for the chat.

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]

Add a Message object to the store.

Parameters

message – A BaseMessage object to store.

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 this memory and Firestore.

load_messages() None[source]

Retrieve the messages from Firestore

prepare_firestore() None[source]

Prepare the Firestore client.

Use this function to make sure your database is ready.

upsert_messages(new_message: Optional[BaseMessage] = None) None[source]

Update the Firestore document.