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.Import required libraries
OpenAIEmbeddings is assumed, but if you’re using Azure OpenAI, import AzureOpenAIEmbeddings instead.
Configure OpenAI settings
Set variables for your OpenAI provider. You need either an OpenAI account or an Azure OpenAI account to generate the embeddings.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.Create embeddings and vector store instances
Create instances of theOpenAIEmbeddings and AzureSearch classes. When you complete this step, you should have an empty search index on your Azure AI Search resource. The integration module provides a default schema.
Create vector store instance
Create instance of the AzureSearch class using the embeddings from aboveInsert text and embeddings into vector store
This step loads, chunks, and vectorizes the sample document, and then indexes the content into a search index on Azure AI Search.Perform a vector similarity search
Execute a pure vector similarity search using the similarity_search() method:Perform a vector similarity search with relevance scores
Execute a pure vector similarity search using the similarity_search_with_relevance_scores() method. Queries that don’t meet the threshold requirements are exluded.Perform a hybrid search
Execute hybrid search using the search_type or hybrid_search() method. Vector and nonvector text fields are queried in parallel, results are merged, and top matches of the unified result set are returned.Custom schemas and queries
This section shows you how to replace the default schema with a custom schema.Create a new index with custom filterable fields
This schema shows field definitions. It’s the default schema, plus several new fields attributed as filterable. Because it’s using the default vector configuration, you won’t see vector configuration or vector profile overrides here. The name of the default vector profile is “myHnswProfile” and it’s using a vector configuration of Hierarchical Navigable Small World (HNSW) for indexing and queries against the content_vector field. There’s no data for this schema in this step. When you execute the cell, you should get an empty index on Azure AI Search.Add data and perform a query that includes a filter
This example adds data to the vector store based on the custom schema. It loads text into the title and source fields. The source field is filterable. The sample query in this section filters the results based on content in the source field.Create a new index with a scoring profile
Here’s another custom schema that includes a scoring profile definition. A scoring profile is used for relevance tuning of nonvector content, which is helpful in hybrid search scenarios.Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.