You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this quickstart, you use [agentic retrieval](../../search-agentic-retrieval-concept.md) to create a conversational search experience powered by large language models (LLMs) and your proprietary data. Agentic retrieval breaks down complex user queries into subqueries, runs the subqueries in parallel, and extracts grounding data from documents indexed in Azure AI Search. The output is intended for integration with custom chat solutions.
12
+
In this quickstart, you use [agentic retrieval](../../search-agentic-retrieval-concept.md) to create a conversational search experience powered by large language models (LLMs) and your proprietary data. Agentic retrieval breaks down complex user queries into subqueries, runs the subqueries in parallel, and extracts grounding data from documents indexed in Azure AI Search. The output is intended for integration with agentic and custom chat solutions.
13
13
14
14
Although you can provide your own data, this quickstart uses [sample JSON documents](https://github.com/Azure-Samples/azure-search-sample-data/tree/main/nasa-e-book/earth-at-night-json) from NASA's Earth at Night e-book. The documents describe general science topics and images of Earth at night as observed from space.
15
15
16
+
This quickstart is based on the [Quickstart-Agentic-Retrieval](https://github.com/Azure-Samples/azure-search-python-samples/tree/main/Quickstart-Agentic-Retrieval) Jupyter notebook on GitHub.
17
+
16
18
## Prerequisites
17
19
18
20
+ An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
@@ -66,7 +68,7 @@ To configure the recommended role-based access:
66
68
67
69
1. On your Azure AI Search service, [assign the following roles](../../search-security-rbac.md#how-to-assign-roles-in-the-azure-portal) to yourself.
68
70
69
-
+**Owner/Contributor** or **Search Service Contributor**
Copy file name to clipboardExpand all lines: articles/search/includes/quickstarts/agentic-retrieval-rest.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -279,9 +279,9 @@ POST {{baseUrl}}/indexes/{{index-name}}/docs/index?api-version={{api-version}}
279
279
}
280
280
```
281
281
282
-
## Create a search agent
282
+
## Create a knowledge agent
283
283
284
-
To connect Azure AI Search to your `gpt-4o-mini` deployment and target the `earth_at_night` index at query time, you need a search agent. Use [Create Knowledge Agents](/rest/api/searchservice/knowledge-agents/create?view=rest-searchservice-2025-05-01-preview&preserve-view=true) to define an agent named `earth-search-agent`, which you specified using the `@agent-name` variable in a previous section.
284
+
To connect Azure AI Search to your `gpt-4o-mini` deployment and target the `earth_at_night` index at query time, you need a knowledge agent. Use [Create Knowledge Agents](/rest/api/searchservice/knowledge-agents/create?view=rest-searchservice-2025-05-01-preview&preserve-view=true) to define an agent named `earth-search-agent`, which you specified using the `@agent-name` variable in a previous section.
285
285
286
286
To ensure relevant and semantically meaningful responses, `defaultRerankerThreshold` is set to exclude responses with a reranker score of `2.5` or lower.
# Build an agent-to-agent retrieval solution using Azure AI Search
@@ -19,30 +19,80 @@ This article describes an approach or pattern for building a solution that uses
19
19
20
20
This article supports the [agentic-retrieval-pipeline-example](https://github.com/Azure-Samples/azure-search-python-samples/tree/main/agentic-retrieval-pipeline-example) Python sample on GitHub.
21
21
22
-
This exercise differs from the [Agentic Retrieval Quickstart](search-get-started-agentic-retrieval.md) in how it uses Azure AI Agent to determine whether to retrieve data from the index, and how it uses an agent tool for orchestration.
22
+
This exercise differs from the [Agentic Retrieval Quickstart](search-get-started-agentic-retrieval.md) in how it uses Azure AI Agent to retrieve data from the index, and how it uses an agent tool for orchestration. If you want to understand the retrieval pipeline in its simplest form, begin with the quickstart.
23
23
24
24
## Prerequisites
25
25
26
26
The following resources are required for this design pattern:
27
27
28
-
+ Azure AI Search, basic tier or higher, in a [region that provides semantic ranker](search-region-support.md).
28
+
+ Azure AI Search, basic tier or higher, in a [region that provides semantic ranking](search-region-support.md).
29
29
30
30
+ A search index that satisfies the [index criteria for agentic retrieval](search-agentic-retrieval-how-to-index.md).
31
31
32
-
+Azure OpenAI, and you should have an **Azure AI Developer** role assignment to create a Foundry project.
32
+
+A project in Azure AI Foundry, with an Azure AI Agent in a Basic setup.
33
33
34
-
+ A project in Azure AI Foundry, with a deployment of a supported large language model and an Azure AI Agent in a basic setup. To meet this requirement, follow the steps in [Quickstart: Create a new agent (Preview)](/azure/ai-services/agents/quickstart?pivots=ai-foundry-portal). We recommend 100,000 token capacity for your model. You can find capacity and the rate limit in the model deployments list in the Azure AI Foundry portal.
34
+
Follow the steps in [Create a project for Azure AI Foundry](/azure/ai-foundry/how-to/create-projects). Creating the project also creates the Azure AI Foundry resource in your Azure subscription.
35
+
36
+
+ Azure OpenAI with a deployment of one of the chat completion models listed below. We recommend a minimum of 100,000 token capacity for your model. You can find capacity and the rate limit in the model deployments list in the Azure AI Foundry portal. You can also deploy text embedding models if you want [vectorization at query time](vector-search-integrated-vectorization.md#using-integrated-vectorization-in-queries).
35
37
36
38
### Supported large language models
37
39
38
-
Use Azure OpenAI or an equivalent open source model:
40
+
Use one of the following chat completion models with your AI agent:
39
41
40
42
+`gpt-4o`
41
43
+`gpt-4o-mini`
42
44
+`gpt-4.1`
43
45
+`gpt-4.1-nano`
44
46
+`gpt-4.1-mini`
45
47
48
+
### Package version requirements
49
+
50
+
Use a package version that provides preview functionality. See the [`requirements.txt`](https://github.com/Azure-Samples/azure-search-python-samples/blob/main/agentic-retrieval-pipeline-example/requirements.txt) file for more packages used in the example solution.
51
+
52
+
```
53
+
azure-ai-projects==1.0.0b11
54
+
azure-ai-agents==1.0.0
55
+
azure-search-documents==11.6.0b12
56
+
```
57
+
58
+
### Configure access
59
+
60
+
Before you begin, make sure you have permissions to access content and operations. We recommend Microsoft Entra ID authentication and role-based access for authorization. You must be an **Owner** or **User Access Administrator** to assign roles. If roles aren't feasible, you can use [key-based authentication](search-security-api-keys.md) instead.
61
+
62
+
Configure access to each resource identified in this section.
63
+
64
+
### [**Azure AI Search**](#tab/search-perms)
65
+
66
+
Azure AI Search provides the agentic retrieval pipeline. Configure access for yourself, your app, and your search service for downstream access to models.
1.[Configure a managed identity](search-howto-managed-identities-data-sources.md).
70
+
1.[Assign roles](search-security-rbac.md):
71
+
72
+
+ For local testing, you must have **Search Service Contributor**, **Search Index Data Contributor**, and **Search Index Data Reader** role assignments to create, load, and retrieve on Azure AI Search.
73
+
74
+
+ For integrated operations, ensure that all clients using the retrieval pipeline (agent and tool) have **Search Index Data Reader** role assignments for sending retrieval requests.
75
+
76
+
### [**Azure AI Foundry**](#tab/foundry-perms)
77
+
78
+
Azure AI Foundry hosts the AI agent and tool. Permissions are needed to create and use the resource.
79
+
80
+
+ You must be an **Owner** of your Azure subscription to create the project and resource.
81
+
82
+
+ For local testing, you must be an **Azure AI User** to access chat completion models deployed to the Foundry resource. This assignment is conferred automatically for **Owners** when you create the resource. Other users need a specific role assignment. For more information, see [Role-based access control in Azure AI Foundry portal](/azure/ai-foundry/concepts/rbac-azure-ai-foundry).
83
+
84
+
+ For integrated operations, ensure your [search service identity](search-howto-managed-identities-data-sources.md) has an **Azure AI User** role assignment on the Foundry resource.
85
+
86
+
### [**Azure OpenAI**](#tab/openai-perms)
87
+
88
+
Azure OpenAI hosts the models used by the agentic retrieval pipeline. Configure access for yourself and for the search service.
89
+
90
+
+ For local testing, ensure that you have a **Cognitive Services User** role assignment to access the chat completion model and embedding models (if using).
91
+
92
+
+ For integrated operations, ensure your [search service identity](search-howto-managed-identities-data-sources.md) has a **Cognitive Services User** role assignment for model access.
93
+
94
+
---
95
+
46
96
## Development tasks
47
97
48
98
Development tasks on the Azure AI Search side include:
@@ -55,25 +105,13 @@ Development tasks on the Azure AI Search side include:
55
105
56
106
Your custom application makes API calls to Azure AI Search and an Azure SDK.
57
107
58
-
+ External data from anywhere
59
-
+ Azure AI Search, hosting indexed data and the agentic data retrieval engine
60
-
+ Azure AI Foundry Model, providing a chat model (an LLM) for user interaction
61
-
+ Azure SDK with a Foundry project, providing programmatic access to chat and chat history
62
-
+ Azure AI Agent, with an agent for handling the conversation, and a tool for orchestration
63
-
64
-
## How to customize grounding data
65
-
66
-
Search results are consolidating into a large unified string that you can pass to a conversational language model for a grounded answer. The following indexing and relevance tuning features in Azure AI Search are available to help you generate high quality results:
108
+
+ External data from anywhere, although we recommend [data sources used for integrated indexing](search-data-sources-gallery.md).
109
+
+ Azure AI Search, hosting indexed data and the agentic data retrieval engine.
110
+
+ Azure AI Foundry, hosting the AI agent and tool.
111
+
+ Azure SDK with a Foundry project, providing programmatic access to Azure AI Foundry.
112
+
+ Azure OpenAI, hosting a chat completion model used by the knowledge agent and any embedding models used by vectorizers for vector search.
67
113
68
-
+ Scoring profiles (added to your search index) provide built-in boosting criteria. Your index must specify a default scoring profile, and that's the one used by the retrieval engine when queries include fields associated with that profile.
69
-
70
-
+ Semantic configuration is required, but you determine which fields are prioritized and used for ranking.
71
-
72
-
+ For plain text content, you can use analyzers to control tokenization during indexing.
73
-
74
-
+ For multimodal or image content, you can use image verbalization for LLM-generated descriptions of your images, or classic OCR and image analysis via skillsets during indexing.
75
-
76
-
## Create the project
114
+
## Set up your environment
77
115
78
116
The canonical use case for agentic retrieval is through the Azure AI Agent service. We recommend it because it's the easiest way to create a chatbot.
79
117
@@ -85,29 +123,73 @@ You need endpoints for:
85
123
+ Azure OpenAI
86
124
+ Azure AI Foundry project
87
125
88
-
You can find endpoints for Azure AI Search and Azure OpenAI in the [Azure portal](https://portal.azure.com).
126
+
You can find endpoints for Azure AI Search and Azure OpenAI in the [Azure portal](https://portal.azure.com), in the **Overview** pages for each resource.
89
127
90
-
You can find the project connection string in the Azure AI Foundry portal:
128
+
You can find the project endpoint in the Azure AI Foundry portal:
91
129
92
130
1. Sign in to the [Azure AI Foundry portal](https://ai.azure.com) and open your project.
93
131
94
-
1. In the **Project details** tile, find and copy the **Project connection string**.
95
-
96
-
A hypothetical connection string might look like this: `eastus2.api.azureml.ms;00000000-0000-0000-0000-0000000000;rg-my-resource-group-name;my-foundry-project-name`
132
+
1. In the **Overview** tile, find and copy the Azure AI Foundry project endpoint.
97
133
98
-
1. Check the authentication type for your Azure OpenAI resource and make sure it uses an API key shared to all projects. Still in **Project details**, expand the **Connected resources** tile to view the authentication type for your Azure OpenAI resource.
134
+
A hypothetical endpoint might look like this: `https://your-foundry-resource.services.ai.azure.com/api/projects/your-foundry-project`
99
135
100
136
If you don't have an Azure OpenAI resource in your Foundry project, revisit the model deployment prerequisite. A connection to the resource is created when you deploy a model.
101
137
138
+
### Set up an AI project client and create an agent
139
+
140
+
Use [AIProjectClient](/python/api/azure-ai-projects/azure.ai.projects.aiprojectclient?view=azure-python-preview&preserve-view=true) to create your AI agent.
Your agent is backed by a supported language model and instructions inform the agent of its scope.
151
+
152
+
```python
153
+
instructions ="""
154
+
A Q&A agent that can answer questions about the Earth at night.
155
+
Sources have a JSON format with a ref_id that must be cited in the answer using the format [ref_id].
156
+
If you do not have the answer, respond with "I don't know".
157
+
"""
158
+
agent = project_client.agents.create_agent(
159
+
model=agent_model,
160
+
name=agent_name,
161
+
instructions=instructions
162
+
)
163
+
164
+
print(f"AI agent '{agent_name}' created or updated successfully")
165
+
```
166
+
102
167
### Add an agentic retrieval tool to AI Agent
103
168
104
169
An end-to-end pipeline needs an orchestration mechanism for coordinating calls to the retriever and knowledge agent. You can use a [tool](/azure/ai-services/agents/how-to/tools/function-calling) for this task. The tool calls the Azure AI Search knowledge retrieval client and the Azure AI agent, and it drives the conversations with the user.
105
170
106
-
## How to design a prompt
171
+
```python
172
+
from azure.ai.agents.models import FunctionTool, ToolSet, ListSortOrder
173
+
174
+
from azure.search.documents.agent import KnowledgeAgentRetrievalClient
175
+
from azure.search.documents.agent.models import KnowledgeAgentRetrievalRequest, KnowledgeAgentMessage, KnowledgeAgentMessageTextContent, KnowledgeAgentIndexParams
107
176
108
-
The prompt sent to the LLM includes instructions for working with the grounding data, which is passed as a large single string with no serialization or structure.
The messages sent to the agent tool include instructions for chat history and using the results obtained from [knowledge retrieval](/rest/api/searchservice/knowledge-retrieval/retrieve?view=rest-searchservice-2025-05-01-preview&preserve-view=true) on Azure AI Search. The response is passed as a large single string with no serialization or structure.
Search results are consolidated into a large unified string that you can pass to a chat completion model for a grounded answer. The following indexing and relevance tuning features in Azure AI Search are available to help you generate high quality results. You can implement these features in the search index, and the improvements in search relevance are evident in the quality of the response returned during retrieval.
142
223
143
-
instructions ="""
144
-
An Q&A agent that can answer questions about the Earth at night.
145
-
Sources have a JSON format with a ref_id that must be cited in the answer.
146
-
If you do not have the answer, respond with "I don't know".
147
-
"""
148
-
agent = project_client.agents.create_agent(
149
-
model=agent_model,
150
-
name=agent_name,
151
-
instructions=instructions
152
-
)
153
-
```
224
+
+[Scoring profiles](index-add-scoring-profiles.md) (added to your search index) provide built-in boosting criteria. Your index must specify a default scoring profile, and that's the one used by the retrieval engine when queries include fields associated with that profile.
225
+
226
+
+[Semantic configuration](semantic-how-to-configure.md) is required, but you determine which fields are prioritized and used for ranking.
227
+
228
+
+ For plain text content, you can use [analyzers](index-add-custom-analyzers.md) to control tokenization during indexing.
229
+
230
+
+ For [multimodal or image content](multimodal-search-overview.md), you can use image verbalization for LLM-generated descriptions of your images, or classic OCR and image analysis via skillsets during indexing.
154
231
155
232
## Control the number of subqueries
156
233
@@ -178,7 +255,7 @@ Look at output tokens in the [activity array](search-agentic-retrieval-how-to-re
178
255
179
256
+ Summarize message threads.
180
257
181
-
+ Use `gpt mini`.
258
+
+ Use `gpt mini` or a smaller model that performs faster.
182
259
183
260
+ Set `maxOutputSize` in the [knowledge agent](search-agentic-retrieval-how-to-create.md) to govern the size of the response, or `maxRuntimeInSeconds` for time-bound processing.
Copy file name to clipboardExpand all lines: articles/search/search-query-access-control-rbac-enforcement.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,7 +43,7 @@ The end-user application sends user permission as part of the search query reque
43
43
44
44
Azure AI Search dynamically constructs security filters based on the user permissions provided. These security filters are automatically appended to any filters that might come in with the query if the index has the permission filter option enabled.
45
45
46
-
For Azure RBAC, permissions are lists of resource ID strings, and there must be an Azure role assignment (Storage Blob Data Reader) on the data the source that grants access to the security principal token in the authorization header. The filter excludes documents if there's no role assignment for the principal behind the access token on the request.
46
+
For Azure RBAC, permissions are lists of resource ID strings. There must be an Azure role assignment (Storage Blob Data Reader) on the data the source that grants access to the security principal token in the authorization header. The filter excludes documents if there's no role assignment for the principal behind the access token on the request.
0 commit comments