Connect an Azure AI Search index to Foundry agents
Ground your Foundry agent’s responses in your proprietary content by connecting it to an Azure AI Search index. The Azure AI Search tool retrieves indexed documents and generates answers with inline citations, enabling accurate, source-backed responses.Usage support
| Microsoft Foundry support | Python SDK | C# SDK | JavaScript SDK | Java SDK | REST API | Basic agent setup | Standard agent setup |
|---|---|---|---|---|---|---|---|
| ✔️ | ✔️ | ✔️ | ✔️ | - | ✔️ | ✔️ | ✔️ |
Prerequisites
Estimated setup time: 15-30 minutes if you have an existing search index- A basic or standard agent environment.
- The latest prerelease package. See the quickstart for details.
- Python:
pip install azure-ai-projects --pre - C#: Install the
Azure.AI.ProjectsNuGet package (prerelease) - JavaScript/TypeScript:
npm install @azure/ai-projects
- Python:
- An Azure subscription and Microsoft Foundry project with:
- Project endpoint
- Model deployment name
- Authentication configured (for example,
DefaultAzureCredential)
- An Azure AI Search index configured for vector search with:
- One or more
Edm.Stringfields that are searchable and retrievable - One or more
Collection(Edm.Single)vector fields that are searchable - At least one retrievable text field that contains the content you want the agent to cite
- A retrievable field that contains a source URL (and optionally a title) so citations can include a link
- One or more
- A connection between your Foundry project and your Azure AI Search service (see Setup).
- For keyless authentication, assign the following Azure role-based access control (RBAC) roles to your project’s managed identity:
- Search Index Data Contributor
- Search Service Contributor
Set environment variables
| Variable | Description |
|---|---|
FOUNDRY_PROJECT_ENDPOINT | Your Foundry project endpoint. |
FOUNDRY_MODEL_DEPLOYMENT_NAME | Your model deployment name. |
AZURE_AI_SEARCH_CONNECTION_NAME | The name of your project connection to Azure AI Search (used by the SDK samples to look up the connection ID). |
AZURE_AI_SEARCH_CONNECTION_ID | The resource ID of your project connection to Azure AI Search (used by the TypeScript and REST samples). |
AI_SEARCH_INDEX_NAME | Your Azure AI Search index name. |
Configure tool parameters
| Azure AI Search tool parameter | Required | Notes |
|---|---|---|
project_connection_id | Yes | The resource ID of the project connection to Azure AI Search. |
index_name | Yes | The name of the index in your Azure AI Search resource. |
top_k | No | Defaults to 5. |
query_type | No | Defaults to vector_semantic_hybrid. Supported values: simple, vector, semantic, vector_simple_hybrid, vector_semantic_hybrid. |
filter | No | Applies to all queries the agent makes to the index. |
Code example
- You need the latest prerelease package. For more information, see the quickstart.
- If you’re using the REST or TypeScript sample, the connection ID is in the format
/subscriptions/{{subscriptionId}}/resourceGroups/{{resourceGroupName}}/providers/Microsoft.CognitiveServices/accounts/{{foundryAccountName}}/projects/{{foundryProjectName}}/connections/{{connectionName}}. - If you’re using the Python or C# sample, you can provide the connection name and retrieve the connection ID with the SDK.
Quick verification
Before running the full sample, verify your Azure AI Search connection exists:Full sample
Expected outcome
The agent queries the search index and returns a response with inline citations. Console output shows the agent ID, streaming delta updates as the response generates, URL citations with start and end indices, and the final complete response text. The agent is then successfully deleted.Quick verification
Before running the full sample, verify your Azure AI Search connection exists:Full sample
The following sample code shows synchronous examples of how to use the Azure AI Search tool in Azure.AI.Projects.OpenAI to query an index. For asynchronous C# examples, see the GitHub repo. This example shows how to use the Azure AI Search tool with agents to query an index.Expected outcome
The agent queries the specified index for information about the sleeping bag. The response includes the temperature rating and a formatted citation with the document title and URL. The response status isCompleted, and the agent version is successfully deleted.
Use agents with Azure AI Search tool for streaming scenarios
This example shows how to use the Azure AI Search tool with agents to query an index in a streaming scenario.Expected outcome
The streaming response displays the agent’s response creation, text deltas as they stream in real-time, and a formatted citation when complete. The final output includes the sleeping bag temperature rating with document reference. The agent version is deleted after the query completes.Use agents with Azure AI Search tool
The following example shows how to use the Azure AI Search tool with the REST API to query an index. The example uses cURL, but you can use any HTTP client. Before running this sample, obtain a bearer token for authentication. Use the Azure CLI to get a token:AGENT_TOKEN to the token value and API_VERSION to the current API version (for example, 2025-01-01-preview).
Expected outcome
The API returns a JSON response containing the agent’s answer about mental health services from the Premera index. The response includes citations and references to the indexed documents that generated the answer.Quick verification
Before running the full sample, verify your Azure AI Search connection exists:Full sample
This sample demonstrates how to create an AI agent with Azure AI Search capabilities by using theAzureAISearchAgentTool and synchronous Azure AI Projects client. The agent can search indexed content and provide responses with citations from search results.
Expected outcome
The application creates an agent with Azure AI Search capabilities, prompts for user input, queries the search index, and streams the response with real-time delta updates. Console output includes the agent ID, streaming text deltas, URL citations with indices, and confirmation of successful agent deletion. The agent provides answers grounded in the indexed content with proper citations.Limitations
Keep these constraints in mind when using the Azure AI Search tool:- Virtual network access: Azure AI Search doesn’t support virtual network (vNET) configurations with agents at this time.
- The Azure AI Search tool can only target one index.
- Your Azure AI Search resource and your Microsoft Foundry Agent must be in the same tenant.
Verify results
After you run a sample, validate that the agent is grounding responses from your index.- Ask a question that you know is answered in a specific indexed document.
- Confirm the response includes citations formatted as
[message_idx:search_idx†source]. - If you’re streaming, confirm you see
url_citationannotations in the response with valid URLs. - Verify the cited content matches your source documents in the search index.
Setup
In this section, you create a connection between the Microsoft Foundry project that contains your agent and the Azure AI Search service that contains your index. If you already connected your project to your search service, skip this section. To create the connection, you need your search service endpoint and authentication method. The following steps guide you through gathering these details.Gather connection details
Before creating a project connection, gather your Azure AI Search service endpoint and authentication credentials. The project connection requires the endpoint of your search service and either key-based authentication or keyless authentication with Microsoft Entra ID. For keyless authentication, you must enable role-based access control (RBAC) and assign roles to your project’s managed identity. Although this method involves extra steps, it enhances security by eliminating the need for hard-coded API keys. Select the tab for your desired authentication method.- Key-based authentication
- Keyless authentication
- Sign in to the Azure portal and select your search service.
- To get the endpoint:
- From the left pane, select Overview.
- Make a note of the URL, which should look like
https://my-service.search.windows.net.

- To get the API key:
- From the left pane, select Settings > Keys.
- Select Both to enable both key-based and keyless authentication, which is recommended for most scenarios.

- Make a note of one of the keys under Manage admin keys.
Create a project connection
Create the project connection by using the search service details you gathered. Use one of the following options.- Azure CLI
- Python
Create the following connection.yml file:You can use a YAML configuration file for both key-based and keyless authentication. Replace the Here’s a keyless example:Then, run the following command:Replace the placeholders with the resource group and project name.
name, endpoint, and api_key (optional) placeholders with your search service details. For more information, see the Azure AI Search connection YAML schema.Here’s a key-based example:Don’t put real keys in source control. Store secrets in a secure store (for example, Azure Key Vault) and inject them at deployment time.
Confirm the connection ID
If you use the REST or TypeScript sample, you need the project connection ID. PythonTroubleshooting
| Issue | Cause | Resolution |
|---|---|---|
| Response has no citations | Agent instructions don’t request citations | Update your agent instructions to explicitly request citations in responses. |
| Response has no citations (streaming) | Annotations not captured | Confirm you receive url_citation annotations when streaming. Check your stream processing logic. |
| Tool can’t access the index (401/403) | Missing RBAC roles (keyless auth) | Assign the Search Index Data Contributor and Search Service Contributor roles to the Foundry project’s managed identity. See Azure RBAC in Foundry. |
| Tool can’t access the index (401/403) | Invalid or disabled API key | Confirm the API key is correct and enabled in the Azure AI Search resource. |
| Tool returns “index not found” | Index name mismatch | Confirm AI_SEARCH_INDEX_NAME matches the exact index name in your Azure AI Search resource (case-sensitive). |
| Tool returns “index not found” | Wrong connection endpoint | Confirm the project connection points to the Azure AI Search resource that contains the index. |
| Search returns no results | Query doesn’t match indexed content | Verify the index contains the expected data. Use Azure AI Search’s test query feature to validate. |
| Slow search performance | Index not optimized | Review index configuration, consider adding semantic ranking, or optimize the index schema. |