# AzureAISearchRetriever

> **Class** in `langchain_community`

📖 [View in docs](https://reference.langchain.com/python/langchain-community/retrievers/azure_ai_search/AzureAISearchRetriever)

`Azure AI Search` service retriever.

## Signature

```python
AzureAISearchRetriever()
```

## Description

**Setup:**

See here for more detail: https://python.langchain.com/docs/integrations/retrievers/azure_ai_search/

We will need to install the below dependencies and set the required
environment variables:

.. code-block:: bash

    pip install -U langchain-community azure-identity azure-search-documents
    export AZURE_AI_SEARCH_SERVICE_NAME="<YOUR_SEARCH_SERVICE_NAME>"
    export AZURE_AI_SEARCH_INDEX_NAME="<YOUR_SEARCH_INDEX_NAME>"

    export AZURE_AI_SEARCH_API_KEY="<YOUR_API_KEY>"
    or
    export AZURE_AI_SEARCH_BEARER_TOKEN="<YOUR_BEARER_TOKEN>"

**Key init args:**

content_key: str
top_k: int
index_name: str

**Instantiate:**

.. code-block:: python

from langchain_community.retrievers import AzureAISearchRetriever

retriever = AzureAISearchRetriever(
    content_key="content", top_k=1, index_name="langchain-vector-demo"
)

**Usage:**

.. code-block:: python

retriever.invoke("here is my unstructured query string")

**Use within a chain:**

.. code-block:: python

from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.runnables import RunnablePassthrough
from langchain_openai import AzureChatOpenAI

prompt = ChatPromptTemplate.from_template(
    """Answer the question based only on the context provided.

Context: {context}

Question: {question}"""
)

llm = AzureChatOpenAI(azure_deployment="gpt-35-turbo")

def format_docs(docs):
    return "\n\n".join(doc.page_content for doc in docs)

chain = (
    {"context": retriever | format_docs, "question": RunnablePassthrough()}
    | prompt
    | llm
    | StrOutputParser()
)

chain.invoke("...")

## Extends

- `BaseRetriever`

## Properties

- `service_name`
- `index_name`
- `api_key`
- `api_version`
- `aiosession`
- `azure_ad_token`
- `content_key`
- `top_k`
- `filter`
- `model_config`

## Methods

- [`validate_environment()`](https://reference.langchain.com/python/langchain-community/retrievers/azure_ai_search/AzureAISearchRetriever/validate_environment)

---

[View source on GitHub](https://github.com/langchain-ai/langchain-community/blob/a6a6079511ac8a5c1293337f88096b8641562e77/libs/community/langchain_community/retrievers/azure_ai_search.py#L21)