Google Cloud Memorystore for Redis is a fully-managed service that is powered by the Redis in-memory data store to build application caches that provide sub-millisecond data access. Extend your database application to build AI-powered experiences leveraging Memorystore for Redisโs LangChain integrations.This notebook goes over how to use Google Cloud Memorystore for Redis to store chat message history with the
MemorystoreChatMessageHistory
class.
Learn more about the package on GitHub.
Before You Begin
To run this notebook, you will need to do the following:- Create a Google Cloud Project
- Enable the Memorystore for Redis API
- Create a Memorystore for Redis instance. Ensure that the version is greater than or equal to 5.0.
๐ฆ๐ Library Installation
The integration lives in its ownlangchain-google-memorystore-redis
package, so we need to install it.
โ Set Your Google Cloud Project
Set your Google Cloud project so that you can leverage Google Cloud resources within this notebook. If you donโt know your project ID, try the following:- Run
gcloud config list
. - Run
gcloud projects list
. - See the support page: Locate the project ID.
๐ Authentication
Authenticate to Google Cloud as the IAM user logged into this notebook in order to access your Google Cloud Project.- If you are using Colab to run this notebook, use the cell below and continue.
- If you are using Vertex AI Workbench, check out the setup instructions here.
Basic Usage
MemorystoreChatMessageHistory
To initialize theMemorystoreMessageHistory
class you need to provide only 2 things:
redis_client
- An instance of a Memorystore Redis.session_id
- Each chat message history object must have a unique session ID. If the session ID already has messages stored in Redis, they will can be retrieved.