Azure Cognitive Search) is a Microsoft cloud search service that gives developers infrastructure, APIs, and tools for information retrieval of vector, keyword, and hybrid queries at scale.
AzureAISearchRetriever returns documents from an unstructured query. It sends the query as a full-text search request to the 2023-11-01 stable REST API version of Azure AI Search. It does not embed the query or run a vector query. For vector or hybrid retrieval, use AzureSearch.as_retriever() from the vector store integration.
This guide shows how to get started with the Azure AI Search retriever. For all AzureAISearchRetriever features and configurations, see the API reference.
Setup
To use this module, you need:- An Azure AI Search service. You can create one for free if you sign up for the Azure trial. A free service has lower quotas, but it’s sufficient for running the code in this notebook.
-
An existing index with a searchable text field that matches
content_key. The vector store module creates an index that works with this retriever. You can also create an index with the Azure AI Search REST APIs. -
An API key or Azure AD Token.
- API keys are generated when you create the search service. If you’re just querying an index, you can use the query API key, otherwise use an admin API key. See Find your API keys for details.
- Azure AD Token can be used with Azure Managed Identity. See Connect your app to Azure AI Search using identities for details.
AzureAISearchRetriever. The search index provides the searchable content.
With an API Key
Installation
This retriever ships in thelangchain-azure-ai package, which also installs langchain-openai, azure-search-documents, and azure-identity:
Instantiation
ForAzureAISearchRetriever, provide an index_name, content_key, and top_k set to the number of results you’d like to retrieve. If you don’t set top_k, the request omits $top and Azure AI Search applies its default page size.
Usage
Now you can use it to retrieve documents from Azure AI Search. Callinvoke to retrieve documents. It returns up to top_k documents that match the query.
Example
This section demonstrates using the retriever over built-in sample data. You can skip this step if you already have a vector index on your search service. Start by providing the endpoints and keys. Because this step creates a vector index, specify a text embedding model to get a vector representation of the text. This example assumes Azure OpenAI with a deployment of text-embedding-3-small. Because this step creates an index, be sure to use an admin API key for your search service.langchain-vector-demo creates a new vector store associated with that index name.
state_of_the_union.txt file and splits the text into 400-character chunks with no overlap. The chunks are then added to the vector store as embeddings.
index_name variable is langchain-vector-demo from the last step. If you skipped vector store creation, provide your index name in the parameter. In this query, the top result is returned.
Use within a chain
API reference
For detailed documentation of allAzureAISearchRetriever features and configurations head to the API reference.
Connect these docs to your agent of choice via MCP for real-time answers.

