RAG with Azure AI Search: give your Foundry agent your documents
Ground a Microsoft Foundry agent in your own documents with Azure AI Search: pick between the one-index search tool and a Foundry IQ knowledge base, build a vector index the agent can cite, connect it without keys, and fix the usual no-citations and 403 problems.
AI & agentsFix a problem7 min read
Retrieval-augmented generation, or RAG, is how an agent answers from your documents instead of from what its model happened to learn: the question goes to a search index first, and the best passages go to the model with the question. In Microsoft Foundry, Azure AI Search is the index, and there are two ways to wire it to an agent. One is simple and generally available; the other reaches several sources at once and is partly in preview. This guide helps you choose, then sets up the simple one properly.
Choose a route
| Azure AI Search tool | Foundry IQ knowledge base | |
|---|---|---|
| What it is | A built-in agent tool that queries one index | A knowledge base in Azure AI Search that spans several knowledge sources, queried through agentic retrieval |
| Sources | An index you built | Indexes, Azure Blob Storage, SharePoint, OneLake, and public web content |
| How it searches | One query per call; hybrid vector and semantic by default | Breaks a complex question into sub-queries, runs them in parallel, reranks, and can synthesise an answer |
| Permissions | What the index returns | Can enforce each user's document permissions at query time |
| Status | Generally available | Some parts generally available, others preview, depending on the API version |
| Connection | A project connection to the search service | A project connection to the knowledge base's MCP endpoint |
| Choose it for | A clear, well-indexed corpus; the least to set up | Questions that span sources, permission-aware answers, or several agents sharing one knowledge layer |
Microsoft's own guidance: use agentic retrieval for new RAG work when relevance matters most and queries are conversational; use classic, single-query retrieval when you need generally available features only or simplicity. This guide sets up the tool; the knowledge base route is at the end. (Copilot Studio agents add an Azure AI Search index as a knowledge source instead; our Power Platform and Azure overview covers that.)
Build the index
The tool needs a vector index. The quickest way is the Import and vectorize data wizard in the Azure portal, which chunks your documents, generates embeddings with a model you choose, and creates the index. Whichever way you build it, the index must have:
- at least one
Edm.Stringfield that is searchable and retrievable; - at least one vector field,
Collection(Edm.Single), that is searchable; - a retrievable content field holding the text you want the agent to quote;
- a retrievable field with the source URL, and optionally a title, so citations can link somewhere.
Add semantic ranking on the search service if you can; the tool's default query type is vector_semantic_hybrid, which combines vector, keyword and semantic reranking. The other options are simple, vector, semantic and vector_simple_hybrid. The search service and the Foundry project must be in the same tenant.
Connect the search service to the project
Use the project's managed identity rather than an admin key. It's the only option that works with private networking, and it means no key to leak or rotate.
- On the search service in the Azure portal, copy the endpoint from Overview (
https://<name>.search.windows.net) and, under Settings > Keys, select Both so role-based access is enabled. - On the Foundry resource, open Identity and copy the Object (principal) ID of its system-assigned managed identity.
- Back on the search service, Access control (IAM) > Add role assignment: give that identity Search Index Data Contributor and Search Service Contributor. Use Check access to confirm both appear.
- In the Foundry portal, create a project connection to Azure AI Search with the endpoint and managed-identity authentication. The Azure CLI equivalent is
az cognitiveservices account project connection create; the oldaz mlcommands don't work with Foundry projects and fail with "Workspace not found".
Note the connection's ID. The tool refers to the connection, not the service.
Add the tool to the agent
Add Azure AI Search to the agent, in the portal under the agent's tools or in code as part of its definition, with these settings:
| Setting | Required | Notes |
|---|---|---|
| Project connection | Yes | The connection from the previous section |
| Index name | Yes | Exactly as in Azure AI Search; it's case-sensitive |
| Query type | No | Defaults to vector_semantic_hybrid |
| Top k | No | How many results go to the model; defaults to 5 |
| Filter | No | An OData filter applied to every query the agent makes |
Then tell the agent to cite. Citations come back as url_citation annotations on the response, but only if the instructions ask for them. Microsoft's template for a knowledge-grounded agent is a good start:
You are a helpful assistant.
Use the search tool to answer user questions.
If the search results don't contain the answer, respond with "I don't know".
When you use information from the search results, include citations to the retrieved sources.
An agent can have one Azure AI Search tool, and that tool targets one index. If several agents need the same index, put the tool in a toolbox, which shares it through one managed endpoint with one set of credentials.
Things that catch people out
| Symptom | Cause | Fix |
|---|---|---|
| Answers have no citations | The instructions don't ask for them | Add the line above; when streaming, make sure your code reads url_citation annotations |
401 or 403 from the index | Missing roles on the managed identity, or a disabled key | Assign Search Index Data Contributor and Search Service Contributor; check the key is enabled if you use one |
| "Index not found" | Name or connection mismatch | Match the index name's case; confirm the connection points at the service that holds it |
| "Cannot connect to host … DNS server returned answer with no data" | A key-based connection with a private network | Switch the connection to managed identity |
| The tool can't reach a private search service | The basic agent set-up can't use private endpoints | Deploy the standard agent set-up with virtual network injection |
| No results for questions you can answer by hand | The index doesn't hold what you think | Run the same query in Azure AI Search's search explorer |
| Slow answers | Index not optimised | Review the schema; add semantic ranking |
The Foundry IQ route
When one index isn't enough, create a knowledge base in Azure AI Search with one or more knowledge sources, and connect it to the agent as an MCP tool through a project connection of category RemoteTool that uses the project's managed identity. The agent is then allowed exactly one MCP tool, knowledge_base_retrieve. Permissions: the project's managed identity needs Search Index Data Reader on the search service (plus Data Contributor if the agent writes to indexes); if the knowledge base uses a model for query planning or answer synthesis, the search service's identity needs Cognitive Services User on the Foundry resource; the person creating the connection needs Foundry Project Manager. For permission-aware answers, forward each user's token in the x-ms-query-source-authorization header so protected sources filter results per user. Agentic retrieval adds latency in exchange for handling multi-part and conversational questions, and the SDK and API versions it needs are preview, so check what's generally available before you build production on it.
Sources
- Connect an Azure AI Search index to Foundry agents, Microsoft Learn
- Retrieval-augmented generation (RAG) in Azure AI Search, Microsoft Learn
- Agentic retrieval in Azure AI Search, Microsoft Learn
- What is Foundry IQ?, Microsoft Learn
- Connect a Foundry IQ knowledge base to Foundry Agent Service, Microsoft Learn
- Quickstart: Vectorize text and images using the Azure portal, Microsoft Learn
Did this fix it?
Comments
No comments yet. Share what worked for you.
Sign in to comment. Comments show under a display name you choose, never your email.