LowCodeStacks™
Sign in

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 problem9 min read

Checked against Microsoft Learn 6 sources · Updated By · drafted with AI help, checked by a personHow we write guides

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.

How the Azure AI Search tool grounds a Foundry agent. A user asks a question; the agent, whose instructions ask for citations, calls the Azure AI Search tool, which queries one vector index, using vector_semantic_hybrid by default. The top passages, 5 by default, go back to the model with the question, and it answers from them. The answer carries url_citation annotations, but only if the instructions asked for citations. Set up once: the index needs a searchable, retrievable Edm.String field; a searchable vector field; a retrievable content field to quote; a retrievable source URL field for citations. Connect with the managed identity, not a key: a project connection to the search service; the Foundry resource's identity needs the Search Index Data Contributor and Search Service Contributor roles; and the search service and project must be in one tenant.
How a question flows through the Azure AI Search tool, and what to set up once for it to work.

Choose a route

Azure AI Search toolFoundry IQ knowledge base
What it isA built-in agent tool that queries one indexA knowledge base in Azure AI Search that spans several knowledge sources, queried through agentic retrieval
SourcesAn index you builtIndexes, Azure Blob Storage, SharePoint, OneLake, and public web content
How it searchesOne query per call; hybrid vector and semantic by defaultBreaks a complex question into sub-queries, runs them in parallel, reranks, and can synthesise an answer
PermissionsWhat the index returnsCan enforce each user's document permissions at query time
StatusGenerally availableSome parts generally available, others preview, depending on the API version
ConnectionA project connection to the search serviceA project connection to the knowledge base's MCP endpoint
Choose it forA clear, well-indexed corpus; the least to set upQuestions 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 data wizard in the Azure portal: on the search service's Overview page select Import data, choose your data source, then RAG. It 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.String field 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.

  1. On the search service in the Azure portal, copy the endpoint from Overview (https://<name>.search.windows.net) and, under Settings > Keys, select Role-based access control. Choose Both only while clients that still use keys move over. With roles only, give your own account Search Service Contributor and Search Index Data Contributor too, or the portal's index pages stop working for you.
  2. On the Foundry resource, open Identity and copy the Object (principal) ID of its system-assigned managed identity.
  3. 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.
  4. 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 old az ml commands don't work with Foundry projects and fail with "Workspace not found".

What the search service's Keys page shows, as of October 2025:

  1. API Access control: API keys (the default) requires a key on every request, Role-based access control requires a role assignment, and Both accepts either. Microsoft recommends Role-based access control, and Both only while clients still move off keys.
  2. Manage admin keys: the Primary admin key and Secondary admin key, masked, each with Regenerate. The managed-identity connection doesn't use them.
  3. Manage query keys: keys with read-only access to the documents in an index, added with Add.
The Keys page of the search service lcs-search-prod in the Azure portal, under the breadcrumb Home, lcs-search-prod, with the subtitle Search service. Under API Access control are three options: API keys, Role-based access control with an information icon, which is selected, and Both. Under Manage admin keys are the Primary admin key and the Secondary admin key, each shown masked in a box with show and copy buttons and a Regenerate button beside it. Under Manage query keys are Add and a greyed-out Delete, and a list with the columns Name and Key holding one masked key with no name.
Recreated by LowCodeStacks from Microsoft Learn screenshots (CC BY 4.0): the Keys page of an Azure AI Search service in the Azure portal, interface as of October 2025, with made-up names.

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:

SettingRequiredNotes
Project connectionYesThe connection from the previous section
Index nameYesExactly as in Azure AI Search; it's case-sensitive
Query typeNoDefaults to vector_semantic_hybrid
Top kNoHow many results go to the model; defaults to 5
FilterNoAn 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:

text
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

SymptomCauseFix
Answers have no citationsThe instructions don't ask for themAdd the line above; when streaming, make sure your code reads url_citation annotations
401 or 403 from the indexMissing roles on the managed identity, or a disabled keyAssign Search Index Data Contributor and Search Service Contributor; check the key is enabled if you use one
"Index not found"Name or connection mismatchMatch 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 networkSwitch the connection to managed identity
The tool can't reach a private search serviceThe basic agent set-up can't use private endpointsDeploy the standard agent set-up with virtual network injection
No results for questions you can answer by handThe index doesn't hold what you thinkRun the same query in Azure AI Search's search explorer
Slow answersIndex not optimisedReview 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

Add LowCodeStacks as a preferred source on Google

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.