Skip to content

The agent engineering platform.

docs: add page for Firestore Chat Message History integration (#15554)

Averi Kitschee378a0f40c2
diff --git a/docs/docs/integrations/memory/firestore_chat_message_history.ipynb b/docs/docs/integrations/memory/firestore_chat_message_history.ipynb
new file mode 100644
index 0000000000..8bdd586cd4
--- /dev/null
+++ b/docs/docs/integrations/memory/firestore_chat_message_history.ipynb
@@ -0,0 +1,147 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "id": "91c6a7ef",
+ "metadata": {},
+ "source": [
+ "# Google Cloud Firestore\n",
+ "\n",
+ "> [`Cloud Firestore`](https://cloud.google.com/firestore) is a NoSQL document database built for automatic scaling, high performance, and ease of application development.\n",
+ "\n",
+ "This notebook goes over how to use Firestore to store chat message history."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "2d6ed3c8-b70a-498c-bc9e-41b91797d3b7",
+ "metadata": {},
+ "source": [
+ "## Setting up"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "b8eca282",
+ "metadata": {},
+ "source": [
+ "To run this notebook, you will need a Google Cloud Project, a Firestore database instance in Native Mode, and Google credentials, see [Firestore Quickstarts](https://cloud.google.com/firestore/docs/quickstarts)."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "5a7f3b3f-d9b8-4577-a7ef-bdd8ecaedb70",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "!pip install firebase-admin"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "a8e63850-3e14-46fe-a59e-be6d6bf8fe61",
+ "metadata": {},
+ "source": [
+ "## Basic Usage"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "id": "d15e3302",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from langchain_community.chat_message_histories.firestore import (\n",
+ " FirestoreChatMessageHistory,\n",
+ ")\n",
+ "\n",
+ "message_history = FirestoreChatMessageHistory(\n",
+ " collection_name=\"langchain-chat-history\",\n",
+ " session_id=\"user-session-id\",\n",
+ " user_id=\"user-id\",\n",
+ ")\n",
+ "\n",
+ "message_history.add_user_message(\"hi!\")\n",
+ "message_history.add_ai_message(\"whats up?\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "id": "64fc465e",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "[HumanMessage(content='hi!'),\n",
+ " HumanMessage(content='hi!'),\n",
+ " AIMessage(content='whats up?')]"
+ ]
+ },
+ "execution_count": 6,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "message_history.messages"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "4be8576e",
+ "metadata": {},
+ "source": [
+ "## Custom Firestore Client"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "12999273",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import firebase_admin\n",
+ "from firebase_admin import credentials, firestore\n",
+ "\n",
+ "# Use a service account.\n",
+ "cred = credentials.Certificate(\"path/to/serviceAccount.json\")\n",
+ "\n",
+ "app = firebase_admin.initialize_app(cred)\n",
+ "client = firestore.client(app=app)\n",
+ "\n",
+ "message_history = FirestoreChatMessageHistory(\n",
+ " collection_name=\"langchain-chat-history\",\n",
+ " session_id=\"user-session-id\",\n",
+ " user_id=\"user-id\",\n",
+ " firestore_client=client,\n",
+ ")"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3 (ipykernel)",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.11.5"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 5
+}
diff --git a/docs/docs/integrations/platforms/google.mdx b/docs/docs/integrations/platforms/google.mdx
index 040ace8aac..ddafdb318f 100644
--- a/docs/docs/integrations/platforms/google.mdx
+++ b/docs/docs/integrations/platforms/google.mdx
@@ -186,7 +186,7 @@ from langchain_community.document_loaders import GoogleSpeechToTextLoader
### Google Vertex AI Vector Search
> [Google Vertex AI Vector Search](https://cloud.google.com/vertex-ai/docs/matching-engine/overview),
-> formerly known as `Vertex AI Matching Engine`, provides the industry's leading high-scale
+> formerly known as `Vertex AI Matching Engine`, provides the industry's leading high-scale
> low latency vector database. These vector databases are commonly
> referred to as vector similarity-matching or an approximate nearest neighbor (ANN) service.
@@ -207,7 +207,7 @@ from langchain_community.vectorstores import MatchingEngine
> [Google BigQuery](https://cloud.google.com/bigquery),
> BigQuery is a serverless and cost-effective enterprise data warehouse in Google Cloud.
>
-> Google BigQuery Vector Search
+> Google BigQuery Vector Search
> BigQuery vector search lets you use GoogleSQL to do semantic search, using vector indexes for fast but approximate results, or using brute force for exact results.
> It can calculate Euclidean or Cosine distance. With LangChain, we default to use Euclidean distance.
@@ -228,7 +228,7 @@ from langchain.vectorstores import BigQueryVectorSearch
>[Google ScaNN](https://github.com/google-research/google-research/tree/master/scann)
> (Scalable Nearest Neighbors) is a python package.
->
+>
>`ScaNN` is a method for efficient vector similarity search at scale.
>`ScaNN` includes search space pruning and quantization for Maximum Inner
@@ -285,9 +285,9 @@ from langchain.retrievers import GoogleVertexAISearchRetriever
### Document AI Warehouse
> [Google Cloud Document AI Warehouse](https://cloud.google.com/document-ai-warehouse)
-> allows enterprises to search, store, govern, and manage documents and their AI-extracted
+> allows enterprises to search, store, govern, and manage documents and their AI-extracted
> data and metadata in a single platform.
->
+>
```python
from langchain.retrievers import GoogleDocumentAIWarehouseRetriever
@@ -304,9 +304,9 @@ documents = docai_wh_retriever.get_relevant_documents(
### Google Cloud Text-to-Speech
->[Google Cloud Text-to-Speech](https://cloud.google.com/text-to-speech) enables developers to
-> synthesize natural-sounding speech with 100+ voices, available in multiple languages and variants.
-> It applies DeepMind’s groundbreaking research in WaveNet and Google’s powerful neural networks
+>[Google Cloud Text-to-Speech](https://cloud.google.com/text-to-speech) enables developers to
+> synthesize natural-sounding speech with 100+ voices, available in multiple languages and variants.
+> It applies DeepMind’s groundbreaking research in WaveNet and Google’s powerful neural networks
> to deliver the highest fidelity possible.
We need to install a python package.
@@ -354,7 +354,7 @@ from langchain.tools import GooglePlacesTool
### Google Search
- Set up a Custom Search Engine, following [these instructions](https://stackoverflow.com/questions/37083058/programmatically-searching-google-in-python-using-custom-search)
-- Get an API Key and Custom Search Engine ID from the previous step, and set them as environment variables
+- Get an API Key and Custom Search Engine ID from the previous step, and set them as environment variables
`GOOGLE_API_KEY` and `GOOGLE_CSE_ID` respectively.
```python
@@ -444,12 +444,12 @@ from langchain_community.utilities.google_trends import GoogleTrendsAPIWrapper
### Google Document AI
->[Document AI](https://cloud.google.com/document-ai/docs/overview) is a `Google Cloud Platform`
-> service that transforms unstructured data from documents into structured data, making it easier
+>[Document AI](https://cloud.google.com/document-ai/docs/overview) is a `Google Cloud Platform`
+> service that transforms unstructured data from documents into structured data, making it easier
> to understand, analyze, and consume.
-We need to set up a [`GCS` bucket and create your own OCR processor](https://cloud.google.com/document-ai/docs/create-processor)
-The `GCS_OUTPUT_PATH` should be a path to a folder on GCS (starting with `gs://`)
+We need to set up a [`GCS` bucket and create your own OCR processor](https://cloud.google.com/document-ai/docs/create-processor)
+The `GCS_OUTPUT_PATH` should be a path to a folder on GCS (starting with `gs://`)
and a processor name should look like `projects/PROJECT_NUMBER/locations/LOCATION/processors/PROCESSOR_ID`.
We can get it either programmatically or copy from the `Prediction endpoint` section of the `Processor details`
tab in the Google Cloud Console.
@@ -507,6 +507,23 @@ See a [usage example and authorization instructions](/docs/integrations/toolkits
from langchain_community.agent_toolkits import GmailToolkit
```
+## Memory
+
+### Cloud Firestore
+
+> [`Cloud Firestore`](https://cloud.google.com/firestore) is a NoSQL document database built for automatic scaling, high performance, and ease of application development.
+
+First, we need to install the python package.
+
+```bash
+pip install firebase-admin
+```
+
+See a [usage example and authorization instructions](/docs/integrations/memory/firestore_chat_message_history).
+
+```python
+from langchain_community.chat_message_histories.firestore import FirestoreChatMessageHistory
+```
## Chat Loaders
@@ -560,7 +577,7 @@ from langchain_community.utilities import GoogleSerperAPIWrapper
### YouTube
>[YouTube Search](https://github.com/joetats/youtube_search) package searches `YouTube` videos avoiding using their heavily rate-limited API.
->
+>
>It uses the form on the YouTube homepage and scrapes the resulting page.
We need to install a python package.