Skip to content

Commit

Permalink
fix(vectorstore): Incorporated review feedback (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
PingXie committed Feb 28, 2024
1 parent a1cd9e0 commit 95f7842
Showing 1 changed file with 32 additions and 31 deletions.
63 changes: 32 additions & 31 deletions samples/langchain_quick_start.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"---\n",
"\n",
"# **Introduction**\n",
"In this codelab, you'll learn how to create a powerful interactive generative AI application using Retrieval Augmented Generation with Cloud Memorystore for Redis and LangChain. You'll build an application grounded in a [Netflix Movie dataset](https://www.kaggle.com/datasets/shivamb/netflix-shows), allowing you to interact with movie data in exciting new ways."
"In this codelab, you'll learn how to create a powerful interactive generative AI application using Retrieval Augmented Generation with Memorystore for Redis and LangChain. You'll build an application grounded in a [Netflix Movie dataset](https://www.kaggle.com/datasets/shivamb/netflix-shows), allowing you to interact with movie data in exciting new ways."
]
},
{
Expand All @@ -56,10 +56,10 @@
"source": [
"## What You Will Learn\n",
"\n",
"* How to deploy a Cloud Memorystore for Redis instance\n",
"* How to use Cloud Memorystore for Redis as a VectorStore\n",
"* How to use Cloud Memorystore for Redis as a DocumentLoader\n",
"* How to use Cloud Memorystore for Redis as ChatHistory storage"
"* How to deploy a Memorystore for Redis instance\n",
"* How to use Memorystore for Redis as a VectorStore\n",
"* How to use Memorystore for Redis as a DocumentLoader\n",
"* How to use Memorystore for Redis as ChatHistory storage"
]
},
{
Expand All @@ -72,7 +72,7 @@
"In the following instructions you will learn to:\n",
"1. Install required dependencies for your application\n",
"2. Set up authentication for your project\n",
"3. Set up a Cloud Memorystore for Redis Instance\n",
"3. Set up a Memorystore for Redis Instance\n",
"4. Import the data used by your application"
]
},
Expand All @@ -89,6 +89,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Memorystore for Redis uses private, internal IP addresses for security. To access your Redis instance from the public internet, you'll need to set up a jump box and ssh into it from your Colab with port forwarding. Using a local Colab runtime makes this process easier.\n",
"\n",
"Download and run the latest Colab runtime docker image on your local machine:"
]
},
Expand Down Expand Up @@ -135,11 +137,9 @@
},
"outputs": [],
"source": [
"# TODO: Update this to install from Pypi\n",
"%pip install --quiet git+https://github.com/googleapis/langchain-google-memorystore-redis-python.git\n",
"# %pip install --quiet langchain-google-memorystore-redis\n",
"%pip install --quiet langchain-google-memorystore-redis\n",
"\n",
"%pip install --quiet langchain_core langchain langchain_google_vertexai redis"
"%pip install --quiet langchain langchain_google_vertexai redis"
]
},
{
Expand Down Expand Up @@ -251,25 +251,25 @@
"outputs": [],
"source": [
"# Enable GCP services\n",
"!gcloud services enable aiplatform.googleapis.com"
"!gcloud services enable aiplatform.googleapis.com redis.googleapis.com"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Set up Cloud Memorystore for Redis\n",
"You will need a Cloud Memorystore for Redis instance for the following stages of this notebook."
"## Set up Memorystore for Redis\n",
"You will need a Memorystore for Redis instance for the following stages of this notebook."
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Running the below cell will verify the existence of the Cloud Memorystore for Redis instance and or create a new instance if one does not exist.\n",
"> ⏳ - Creating a Cloud Memorystore for Redis instance may take a few minutes."
"Running the below cell will verify the existence of the Memorystore for Redis instance and or create a new instance if one does not exist.\n",
"> ⏳ - Creating a Memorystore for Redis instance may take a few minutes."
]
},
{
Expand All @@ -278,7 +278,7 @@
"metadata": {},
"outputs": [],
"source": [
"# @markdown Please fill in the both the Google Cloud region and name of your Cloud Memorystore for Redis instance. Once filled in, run the cell.\n",
"# @markdown Please fill in the both the Google Cloud region and name of your Memorystore for Redis instance. Once filled in, run the cell.\n",
"\n",
"# Please fill in these values.\n",
"instance_name = \"redis-langchain\" # @param {type:\"string\"}\n",
Expand All @@ -291,13 +291,13 @@
"assert instance_size_gb, \"⚠️ Please provide the size of your instance in GB\"\n",
"\n",
"\n",
"# Check if Cloud Memorystore for Redis instance exists in the provided region with the correct engine version\n",
"# Check if Memorystore for Redis instance exists in the provided region with the correct engine version\n",
"# TODO: Remove \"beta\" after GA\n",
"redis_version = !gcloud beta redis instances describe {instance_name} --region {region} --format=\"value(redisVersion)\"\n",
"if redis_version == [\"REDIS_7_2\"]:\n",
" print(\"Found an existing Cloud Memorystore for Redis Instance!\")\n",
" print(\"Found an existing Memorystore for Redis Instance!\")\n",
"else:\n",
" print(\"Creating a new Cloud Memorystore for Redis instance...\")\n",
" print(\"Creating a new Memorystore for Redis instance...\")\n",
" !gcloud beta redis instances create --region {region} {instance_name} --size {instance_size_gb} --zone {zone} --tier BASIC --redis-version=redis_7_2"
]
},
Expand All @@ -306,7 +306,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"**Important Note**: Memorystore for Redis uses private, internal IP addresses for security. This means you'll need to create a Google Cloud Engine VM within the same VPC as your Redis instance to connect."
"**Important Note**: Memorystore for Redis uses private, internal IP addresses for security. This means you'll need to create a Google Compute Engine (GCE) VM within the same VPC as your Redis instance to connect."
]
},
{
Expand Down Expand Up @@ -405,6 +405,7 @@
"source": [
"import redis\n",
"\n",
"# Since using SSH, \"localhost\" (127.0.0.1) is the address for the Redis instance\n",
"client = redis.from_url(f\"redis://127.0.0.1:6379\")"
]
},
Expand Down Expand Up @@ -488,7 +489,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Use case 1: Cloud Memorystore for Redis as a Document Loader"
"# Use case 1: Memorystore for Redis as a Document Loader"
]
},
{
Expand All @@ -498,7 +499,7 @@
"source": [
"Now that you have data in your Redis instance, you're ready to use it as a document loader. This means you'll pull data from the Redis instance and load it into memory as documents, ready to be added to your vector store.\n",
"\n",
"To use your Cloud Memorystore for Redis instance as a document loader, you'll utilize the MemorystoreDocumentLoader class.\n",
"To use your Memorystore for Redis instance as a document loader, you'll utilize the MemorystoreDocumentLoader class.\n",
"\n",
"The \"content_fields\" argument specifies which fields within your Redis HASH keys will become the \"content\" of your documents. Any other fields within those HASH keys will be treated as \"metadata\" attached to each document."
]
Expand All @@ -522,7 +523,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
" Run the `collect_async_items` function to pull documents from your Redis instance. Take a look at the first 5 documents below. Awesome, you've successfully used Cloud Memorystore for Redis as a document loader!"
" Run the `lazy_load` function to pull documents from your Redis instance. Take a look at the first 5 documents below. Awesome, you've successfully used Memorystore for Redis as a document loader!"
]
},
{
Expand All @@ -541,15 +542,15 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Use case 2: Cloud Memorystore for Redis as a Vector Store"
"# Use case 2: Memorystore for Redis as a Vector Store"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Now, you'll learn how to put all of the documents you just loaded into a vector store backed by Cloud Memorystore for Redis. This will allow you to use vector search to answer user questions!"
"Now, you'll learn how to put all of the documents you just loaded into a vector store backed by Memorystore for Redis. This will allow you to use vector search to answer user questions!"
]
},
{
Expand Down Expand Up @@ -612,7 +613,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Next, create a vector_store object linked to your Cloud Memorystore for Redis instance and then load your documents into the vector store. **Important**: for each document, the embedding service will compute embeddings for storage – please refer to pricing details [here](https://cloud.google.com/vertex-ai/pricing)."
"Next, create a vector_store object linked to your Memorystore for Redis instance and then load your documents into the vector store. **Important**: for each document, the embedding service will compute embeddings for storage – please refer to pricing details [here](https://cloud.google.com/vertex-ai/pricing)."
]
},
{
Expand Down Expand Up @@ -649,7 +650,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Now, you can add the loaded documents into the vector store backed by Cloud Memorystore for Redis.\n",
"Now, you can add the loaded documents into the vector store backed by Memorystore for Redis.\n",
"\n",
"> ⏳ - This process can take up to a minute. The vector store will call Vertex AI's embedding service to create embeddings for each document and store them in Redis."
]
Expand All @@ -669,15 +670,15 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Use case 3: Cloud Memorystore for Redis as Chat Memory"
"# Use case 3: Memorystore for Redis as Chat Memory"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"You'll now add chat history (or \"memory\") for more advanced LLM interactions. This allows the LLM to retain context from past conversations, leading to better responses. Cloud Memorystore for Redis will be your memory storage. To start, let's initialize Cloud Memorystore for Redis for this purpose."
"You'll now add chat history (or \"memory\") for more advanced LLM interactions. This allows the LLM to retain context from past conversations, leading to better responses. Memorystore for Redis will be your memory storage. To start, let's initialize Memorystore for Redis for this purpose."
]
},
{
Expand Down Expand Up @@ -719,7 +720,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Conversational RAG Chain Backed by Cloud Memorystore for Redis"
"# Conversational RAG Chain Backed by Memorystore for Redis"
]
},
{
Expand All @@ -729,7 +730,7 @@
"id": "j2OxF3JoNA7J"
},
"source": [
"You've already explored Cloud Memorystore for Redis in several roles – now it's time to integrate it into the ConversationalRetrievalChain! You'll build a movie chatbot that leverages vector search for insightful answers."
"You've already explored Memorystore for Redis in several roles – now it's time to integrate it into the ConversationalRetrievalChain! You'll build a movie chatbot that leverages vector search for insightful answers."
]
},
{
Expand Down

0 comments on commit 95f7842

Please sign in to comment.