This repository contains multiple notebooks that demonstrate how to use Azure AI Search for vector and non-vector content in RAG patterns and in traditional search solutions.
Start with azure-search-vector-python-sample.ipynb for the basic steps. The code reads the data/text-sample.json file, which contains the input strings for which embeddings are generated. Output is a combination of human-readable text and embeddings that's pushed into a search index.
Once you understand the basics, continue with the following notebooks for more exploration:
| Sample | Description |
|---|---|
| backup-restore | Backup retrievable index fields and restore them on a new index on a different search service. |
| custom-embeddings | Use an open source embedding model such as SentenceTransformers to vectorize content and queries. |
| custom-skills | End-to-end sample that creates and calls a custom embedding model using a custom skill. This sample includes source code for an Azure function and a notebook for end-to-end steps. The function uses Azure AI Vision Image Retrieval for it's built-in support of image vectorization. |
| integrated-vectorization | Demonstrates integrated data chunking and vectorization (preview) using skills to split text and call an Azure OpenAI embedding model. |
| azure-search-vector-image-index-creation-python-sample.ipynb | Vectorization using Azure AI Vision image embedding. |
| azure-search-vector-image-python-sample.ipynb | Vectorize images using Azure AI Vision image retrieval. In contrast with the custom-skills example, this notebook uses the push API (no indexers or skillsets) for indexing. It calls the embedding model directly. |
| azure-search-vector-python-huggingface-model-sample.ipynb | Vectorize using Hugging Face E5-small-V2 embedding model. |
| azure-search-vector-python-langchain-sample.ipynb | LangChain integration. |
| azure-search-vector-python-llamaindex-sample.ipynb | LlamaIndex integration. |
| vectors | Basic vector indexing and queries using push model APIs. Start here. |
To run the Python samples in this folder, you should have:
- An Azure subscription, with access to Azure OpenAI.
- Azure AI Search, any tier, but choose a service that can handle the workload. We strongly recommend Basic or higher.
- Azure OpenAI is used in most samples. A deployment of the
text-embedding-ada-002is a common requirement. - Python (these instructions were tested with version 3.11.x)
You can use Visual Studio Code with the Python extension for these demos.
-
Clone this repository.
-
Create a
.envbased on thecode/.env-samplefile. Copy your new .env file to the folder containing your notebook and update the variables. -
If you're using Visual Studio Code with the Python extension, make sure you also have the Jupyter extension.
-
Open the
codefolder and sample subfolder. Open aipynbfile in Visual Studio Code. -
Optionally, create a virtual environment so that you can control which package versions are used. Use Ctrl+shift+P to open a command palette. Search for
Python: Create environment. SelectVenvto create an environment within the current workspace. -
Copy the
.envfile to the subfolder containing the notebook. -
Execute the cells one by one, or select Run or Shift+Enter.
If you get error 429 from Azure OpenAI, it means the resource is over capacity:
-
Check the Activity Log of the Azure OpenAI service to see what else might be running.
-
Check the Tokens Per Minute (TPM) on the deployed model. On a system that isn't running other jobs, a TPM of 33K or higher should be sufficient to generate vectors for the sample data. You can try a model with more capacity if 429 errors persist.
-
Review these articles for information on rate limits: Understanding rate limits and A Guide to Azure OpenAI Service's Rate Limits and Monitoring.