Azure AI Search
Azure AI Search (formerly known as Azure Search
and Azure Cognitive Search
) is a cloud search service that gives developers infrastructure, APIs, and tools for information retrieval of vector, keyword, and hybrid queries at scale.
You'll need to install langchain-community
with pip install -qU langchain-community
to use this integration
Install Azure AI Search SDK
Use azure-search-documents package version 11.4.0 or later.
%pip install --upgrade --quiet azure-search-documents
%pip install --upgrade --quiet azure-identity
Import required libraries
OpenAIEmbeddings
is assumed, but if you're using Azure OpenAI, import AzureOpenAIEmbeddings
instead.
import os
from langchain_community.vectorstores.azuresearch import AzureSearch
from langchain_openai import AzureOpenAIEmbeddings, OpenAIEmbeddings
Configure OpenAI settings
Set variables for your OpenAI provider. You need either an OpenAI account or an Azure OpenAI account to generate the embeddings.
# Option 1: use an OpenAI account
openai_api_key: str = "PLACEHOLDER FOR YOUR API KEY"
openai_api_version: str = "2023-05-15"
model: str = "text-embedding-ada-002"
# Option 2: use an Azure OpenAI account with a deployment of an embedding model
azure_endpoint: str = "PLACEHOLDER FOR YOUR AZURE OPENAI ENDPOINT"
azure_openai_api_key: str = "PLACEHOLDER FOR YOUR AZURE OPENAI KEY"
azure_openai_api_version: str = "2023-05-15"
azure_deployment: str = "text-embedding-ada-002"
Configure vector store settings
You need an Azure subscription and Azure AI Search service to use this vector store integration. No-cost versions are available for small and limited workloads.
Set variables for your Azure AI Search URL and admin API key. You can get these variables from the Azure portal.
vector_store_address: str = "YOUR_AZURE_SEARCH_ENDPOINT"
vector_store_password: str = "YOUR_AZURE_SEARCH_ADMIN_KEY"