You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# What are Vector Embeddings and Vector Search in Azure Cache for Redis?
14
14
15
15
Vector similarity search (VSS) has become a popular technology for AI-powered intelligent applications. Azure Cache for Redis can be used as a vector database when combined with models like [Azure OpenAI](/azure/ai-services/openai/overview) for Retrieval-Augmented Generative AI and other analysis scenarios. This article is a high-level introduction to the concept of vector embeddings, vector similarity search, and how Redis can be used as a vector database powering intelligent applications.
16
16
17
-
For tutorials and sample applications on how to use Azure Cache for Redis and Azure OpenAI to perform vector similarity search, see the following:
17
+
For tutorials and sample applications on how to use Enterprise tier or Azure Managed Redis with Azure OpenAI, see the following:
18
18
19
-
-[Tutorial: Conduct vector similarity search on Azure OpenAI embeddings using Azure Cache for Redis with LangChain](./cache-tutorial-vector-similarity.md)
20
-
-[Sample: Using Redis as vector database in a Chatbot application with .NET Semantic Kernel](https://github.com/CawaMS/chatappredis)
21
-
-[Sample: Using Redis as semantic cache in a Dall-E powered image gallery with Redis OM for .NET](https://github.com/CawaMS/OutputCacheOpenAI)
19
+
-[Tutorial: Conduct vector similarity Enterprise tier or Azure Managed Redis with ddings using LangChain](./cache-tutorial-vector-similarity.md)
20
+
-[Sample: Using Redis as semantic cache in a Dall-E powered image gallery with Redis OM for .NET](https://github.com/Azure-Samples/azure-redis-dalle-semantic-caching)
22
21
23
22
## Scope of Availability
24
23
25
-
Vector search capabilities in Redis require [Redis Stack](https://redis.io/docs/latest/operate/oss_and_stack/stack-with-enterprise/), specifically the [RediSearch](https://redis.io/docs/interact/search-and-query/) module. This capability is only available in the [Enterprise tiers of Azure Cache for Redis](./cache-redis-modules.md).
24
+
Vector search capabilities in Redis require [Redis Stack](https://redis.io/docs/latest/operate/oss_and_stack/stack-with-enterprise/), specifically the [RediSearch](https://redis.io/docs/interact/search-and-query/) module. This capability is only available in the [Enterprise tiers of Azure Cache for Redis](./cache-redis-modules.md) and Azure Managed Redis.
26
25
27
26
This table contains the information for vector search availability in different tiers.
Vector embeddings are a fundamental concept in machine learning and natural language processing that enable the representation of data, such as words, documents, or images as numerical vectors in a high-dimension vector space. The primary idea behind vector embeddings is to capture the underlying relationships and semantics of the data by mapping them to points in this vector space. That means converting your text or images into a sequence of numbers that represents the data, and then comparing the different number sequences. This allows complex data to be manipulated and analyzed mathematically, making it easier to perform tasks like similarity comparison, recommendation, and classification.
38
-
39
-
<!-- TODO - Add image example -->
34
+
Vector embeddings are a fundamental concept in machine learning and natural language processing that enable the representation of data, such as words, documents, or images, as numerical vectors in a high-dimension vector space. The primary idea behind vector embeddings is to capture the underlying relationships and semantics of the data by mapping them to points in this vector space. That means converting your text or images into a sequence of numbers that represents the data, and then comparing the different number sequences. This allows complex data to be manipulated and analyzed mathematically, making it easier to perform tasks like similarity comparison, recommendation, and classification.
40
35
41
36
Each machine learning model classifies data and produces the vector in a different manner. Furthermore, it's typically not possible to determine exactly what semantic meaning each vector dimension represents. But because the model is consistent between each block of input data, similar words, documents, or images have vectors that are also similar. For example, the words `basketball` and `baseball` have embeddings vectors much closer to each other than a word like `rainforest`.
42
37
@@ -81,9 +76,9 @@ Vector similarity search can be used in multiple applications. Some common use-c
81
76
-**Semantic Caching**. Reduce the cost and latency of LLMs by caching LLM completions. LLM queries are compared using vector similarity. If a new query is similar enough to a previously cached query, the cached query is returned. [Semantic Caching example using LangChain](https://python.langchain.com/docs/integrations/llm_caching/#redis-cache)
82
77
-**LLM Conversation Memory**. Persist conversation history with an LLM as embeddings in a vector database. Your application can use vector search to pull relevant history or "memories" into the response from the LLM. [LLM Conversation Memory example](https://github.com/continuum-llms/chatgpt-memory)
83
78
84
-
## Why choose Azure Cache for Redis for storing and searching vectors?
79
+
## Why choose Azure Redis for storing and searching vectors?
85
80
86
-
Azure Cache for Redis can be used effectively as a vector database to store embeddings vectors and to perform vector similarity searches. Support for vector storage and search has been available in many key machine learning frameworks like:
81
+
Azure Redis caches can be used effectively as a vector database to store embeddings vectors and to perform vector similarity searches. Support for vector storage and search has been available in many key machine learning frameworks like:
#CustomerIntent: As a developer, I want to develop some code using a sample so that I see an example of a vector similarity with an AI-based large language model.
13
13
---
14
14
15
-
# Tutorial: Conduct vector similarity search on Azure OpenAI embeddings using Azure Cache for Redis
15
+
# Tutorial: Conduct vector similarity search on Azure OpenAI embeddings using Azure Redis
16
16
17
17
<!-- cawa - need to mention AMR in this tutorial -->
18
-
In this tutorial, you'll walk through a basic vector similarity search use-case. You'll use embeddings generated by Azure OpenAI Service and the built-in vector search capabilities of the Enterprise tier of Azure Cache for Redis to query a dataset of movies to find the most relevant match.
18
+
In this tutorial, you walk through a basic vector similarity search use-case. You use embeddings generated by Azure OpenAI Service and the built-in vector search capabilities of the Enterprise tier of Azure Cache for Redis to query a dataset of movies to find the most relevant match.
19
19
20
-
The tutorial uses the [Wikipedia Movie Plots dataset](https://www.kaggle.com/datasets/jrobischon/wikipedia-movie-plots) that features plot descriptions of over 35,000 movies from Wikipedia covering the years 1901 to 2017.
21
-
The dataset includes a plot summary for each movie, plus metadata such as the year the film was released, the director(s), main cast, and genre. You'll follow the steps of the tutorial to generate embeddings based on the plot summary and use the other metadata to run hybrid queries.
20
+
The tutorial uses the [Wikipedia Movie Plots dataset](https://www.kaggle.com/datasets/jrobischon/wikipedia-movie-plots) that features plot descriptions of over 35,000 movies from Wikipedia covering the years 1901 to 2017. The dataset includes a plot summary for each movie, plus metadata such as the year the film was released, the director(s), main cast, and genre. You follow the steps of the tutorial to generate embeddings based on the plot summary and use the other metadata to run hybrid queries.
22
21
23
22
In this tutorial, you learn how to:
24
23
25
24
> [!div class="checklist"]
26
-
> * Create an Azure Cache for Redis instance configured for vector search
27
-
> * Install Azure OpenAI and other required Python libraries.
28
-
> * Download the movie dataset and prepare it for analysis.
29
-
> * Use the **text-embedding-ada-002 (Version 2)** model to generate embeddings.
30
-
> * Create a vector index in Azure Cache for Redis
31
-
> * Use cosine similarity to rank search results.
32
-
> * Use hybrid query functionality through [RediSearch](https://redis.io/docs/interact/search-and-query/) to prefilter the data and make the vector search even more powerful.
25
+
> - Create an Azure Cache for Redis instance configured for vector search
26
+
> - Install Azure OpenAI and other required Python libraries.
27
+
> - Download the movie dataset and prepare it for analysis.
28
+
> - Use the **text-embedding-ada-002 (Version 2)** model to generate embeddings.
29
+
> - Create a vector index in Azure Cache for Redis
30
+
> - Use cosine similarity to rank search results.
31
+
> - Use hybrid query functionality through [RediSearch](https://redis.io/docs/interact/search-and-query/) to prefilter the data and make the vector search even more powerful.
33
32
34
33
>[!IMPORTANT]
35
-
>This tutorial will walk you through building a Jupyter Notebook. You can follow this tutorial with a Python code file (.py) and get *similar* results, but you will need to add all of the code blocks in this tutorial into the `.py` file and execute once to see results. In other words, Jupyter Notebooks provides intermediate results as you execute cells, but this is not behavior you should expect when working in a Python code file.
34
+
>This tutorial walks you through building a Jupyter Notebook. You can follow this tutorial with a Python code file (.py) and get _similar_ results, but you need to add all of the code blocks in this tutorial into the `.py` file and execute once to see results. In other words, Jupyter Notebooks provides intermediate results as you execute cells, but this is not behavior you should expect when working in a Python code file.
36
35
37
36
>[!IMPORTANT]
38
-
>If you would like to follow along in a completed Jupyter notebook instead, [download the Jupyter notebook file named *tutorial.ipynb*](https://github.com/Azure-Samples/azure-cache-redis-samples/tree/main/tutorial/vector-similarity-search-open-ai) and save it into the new *redis-vector* folder.
37
+
>If you would like to follow along in a completed Jupyter notebook instead, [download the Jupyter notebook file named _tutorial.ipynb_](https://github.com/Azure-Samples/azure-cache-redis-samples/tree/main/tutorial/vector-similarity-search-open-ai) and save it into the new _redis-vector_ folder.
39
38
40
39
## Prerequisites
40
+
<!-- Continue here. -->
41
41
42
-
* An Azure subscription - [Create one for free](https://azure.microsoft.com/free/cognitive-services?azure-portal=true)
43
-
* Access granted to Azure OpenAI in the desired Azure subscription. Currently, you must apply for access to Azure OpenAI. You can apply for access to Azure OpenAI by completing the form at <ahref="https://aka.ms/oai/access"target="_blank">https://aka.ms/oai/access</a>.
44
-
* <ahref="https://www.python.org/"target="_blank">Python 3.8 or later version</a>
* An Azure OpenAI resource with the **text-embedding-ada-002 (Version 2)** model deployed. This model is currently only available in [certain regions](/azure/ai-services/openai/concepts/models#model-summary-table-and-region-availability). See the [resource deployment guide](/azure/ai-services/openai/how-to/create-resource) for instructions on how to deploy the model.
42
+
- An Azure subscription - [Create one for free](https://azure.microsoft.com/free/cognitive-services?azure-portal=true)
43
+
- Access granted to Azure OpenAI in the desired Azure subscription. Currently, you must apply for access to Azure OpenAI. You can apply for access to Azure OpenAI by completing the form at [https://aka.ms/oai/access](https://aka.ms/oai/access). <!-- I don't know if this is still true -->
44
+
-[Python 3.8 or later version](https://www.python.org/)
- An Azure OpenAI resource with the **text-embedding-ada-002 (Version 2)** model deployed. This model is currently only available in [certain regions](/azure/ai-services/openai/concepts/models#model-summary-table-and-region-availability). See the [resource deployment guide](/azure/ai-services/openai/how-to/create-resource) for instructions on how to deploy the model.
47
47
48
48
## Create an Azure Cache for Redis Instance
49
49
50
-
1. Follow the [Quickstart: Create a Redis Enterprise cache](quickstart-create-redis-enterprise.md) guide. On the **Advanced** page, make sure that you've added the **RediSearch** module and have chosen the **Enterprise** Cluster Policy. All other settings can match the default described in the quickstart.
50
+
1. Follow the [Quickstart: Create a Redis Enterprise cache](quickstart-create-redis-enterprise.md) guide, but make sure you add the RedisSearch module at create time.
51
+
52
+
1. On the **Advanced** page, make sure that you've added the **RediSearch** module and have chosen the **Enterprise** Cluster Policy. All other settings can match the default described in the quickstart.
51
53
52
54
It takes a few minutes for the cache to create. You can move on to the next step in the meantime.
1. Create a folder on your local computer named *redis-vector* in the location where you typically save your projects.
60
+
1. Create a folder on your local computer named _redis-vector_ in the location where you typically save your projects.
59
61
60
-
1. Create a new python file (*tutorial.py*) or Jupyter notebook (*tutorial.ipynb*) in the folder.
62
+
1. Create a new python file (_tutorial.py_) or Jupyter notebook (_tutorial.ipynb_) in the folder.
61
63
62
64
1. Install the required Python packages:
63
65
@@ -71,9 +73,9 @@ In this tutorial, you learn how to:
71
73
72
74
1. Sign in or register with Kaggle. Registration is required to download the file.
73
75
74
-
1. Select the **Download** link on Kaggle to download the *archive.zip* file.
76
+
1. Select the **Download** link on Kaggle to download the _archive.zip_ file.
75
77
76
-
1. Extract the *archive.zip* file and move the *wiki_movie_plots_deduped.csv* into the *redis-vector* folder.
78
+
1. Extract the _archive.zip_ file and move the _wiki_movie_plots_deduped.csv_ into the _redis-vector_ folder.
77
79
78
80
## Import libraries and set up connection information
79
81
@@ -170,7 +172,6 @@ Next, you'll read the csv file into a pandas DataFrame.
170
172
defnormalize_text(s, sep_token="\n"):
171
173
s = re.sub(r'\s+', '', s).strip()
172
174
s = re.sub(r". ,","",s)
173
-
# remove all instances of multiple spaces
174
175
s = s.replace("..",".")
175
176
s = s.replace(". .",".")
176
177
s = s.replace("\n", "")
@@ -207,7 +208,7 @@ Next, you'll read the csv file into a pandas DataFrame.
207
208
208
209
## Load DataFrame into LangChain
209
210
210
-
Load the DataFrame into LangChain using the `DataFrameLoader` class. Once the data is in LangChain documents, it's far easier to use LangChain libraries to generate embeddings and conduct similarity searches. Set *Plot* as the `page_content_column` so that embeddings are generated on this column.
211
+
Load the DataFrame into LangChain using the `DataFrameLoader` class. Once the data is in LangChain documents, it's far easier to use LangChain libraries to generate embeddings and conduct similarity searches. Set _Plot_ as the `page_content_column` so that embeddings are generated on this column.
211
212
212
213
1. Add the following code to a new code cell and execute it:
213
214
@@ -338,9 +339,9 @@ With Azure Cache for Redis and Azure OpenAI Service, you can use embeddings and
338
339
339
340
## Related Content
340
341
341
-
*[Learn more about Azure Cache for Redis](cache-overview.md)
342
-
* Learn more about Azure Cache for Redis [vector search capabilities](./cache-overview-vector-similarity.md)
343
-
* Learn more about [embeddings generated by Azure OpenAI Service](/azure/ai-services/openai/concepts/understand-embeddings)
344
-
* Learn more about [cosine similarity](https://en.wikipedia.org/wiki/Cosine_similarity)
345
-
*[Read how to build an AI-powered app with OpenAI and Redis](https://techcommunity.microsoft.com/blog/azuredevcommunityblog/vector-similarity-search-with-azure-cache-for-redis-enterprise/3822059)
346
-
*[Build a Q&A app with semantic answers](https://github.com/ruoccofabrizio/azure-open-ai-embeddings-qna)
342
+
-[Learn more about Azure Cache for Redis](cache-overview.md)
343
+
- Learn more about Azure Cache for Redis [vector search capabilities](./cache-overview-vector-similarity.md)
344
+
- Learn more about [embeddings generated by Azure OpenAI Service](/azure/ai-services/openai/concepts/understand-embeddings)
345
+
- Learn more about [cosine similarity](https://en.wikipedia.org/wiki/Cosine_similarity)
346
+
-[Read how to build an AI-powered app with OpenAI and Redis](https://techcommunity.microsoft.com/blog/azuredevcommunityblog/vector-similarity-search-with-azure-cache-for-redis-enterprise/3822059)
347
+
-[Build a Q&A app with semantic answers](https://github.com/ruoccofabrizio/azure-open-ai-embeddings-qna)
0 commit comments