Skip to content

Commit fdb00be

Browse files
committed
updates to rag quickstart
1 parent a1409a5 commit fdb00be

File tree

1 file changed

+59
-21
lines changed

1 file changed

+59
-21
lines changed

articles/search/search-get-started-rag.md

Lines changed: 59 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ms.service: azure-ai-search
88
ms.custom:
99
- ignite-2024
1010
ms.topic: quickstart
11-
ms.date: 01/07/2025
11+
ms.date: 01/09/2025
1212
---
1313

1414
# Quickstart: Generative search (RAG) with grounding data from Azure AI Search
@@ -17,13 +17,26 @@ This quickstart shows you how to send queries to a chat completion model for a c
1717

1818
## Prerequisites
1919

20-
- An Azure subscription. [Create one for free](https://azure.microsoft.com/free/).
20+
- [Visual Studio Code](https://code.visualstudio.com/download) with the [Python extension](https://marketplace.visualstudio.com/items?itemName=ms-python.python) and the [Jupyter package](https://pypi.org/project/jupyter/). For more information, see [Python in Visual Studio Code](https://code.visualstudio.com/docs/languages/python).
2121

22-
- [Azure AI Search](search-create-service-portal.md), Basic tier or higher so that you can [enable semantic ranker](semantic-how-to-enable-disable.md). Region must be the same one used for Azure OpenAI.
22+
- An Azure subscription with permissions to assign roles. [Create one for free](https://azure.microsoft.com/free/).
2323

24-
- [Azure OpenAI](https://aka.ms/oai/access) resource with a deployment of `gpt-4o`, `gpt-4o-mini`, or equivalent chat completion model, in the same region as Azure AI Search.
24+
- [Azure OpenAI](https://learn.microsoft.com/azure/ai-services/openai/how-to/create-resource)
2525

26-
- [Visual Studio Code](https://code.visualstudio.com/download) with the [Python extension](https://marketplace.visualstudio.com/items?itemName=ms-python.python) and the [Jupyter package](https://pypi.org/project/jupyter/). For more information, see [Python in Visual Studio Code](https://code.visualstudio.com/docs/languages/python).
26+
- [Choose a region](https://learn.microsoft.com/azure/ai-services/openai/concepts/models?tabs=global-standard%2Cstandard-chat-completions#global-standard-model-availability) that supports the chat completion model you want to use (gpt-4o, gpt-4o-mini, or equivalent model).
27+
- [Deploy the chat completion model](https://learn.microsoft.com/azure/ai-studio/how-to/deploy-models-openai) in Azure AI Foundry or [use another approach](https://learn.microsoft.com/azure/ai-services/openai/how-to/working-with-models?tabs=powershell).
28+
29+
- [Azure AI Search](https://learn.microsoft.com/azure/search/search-create-service-portal)
30+
31+
- Same region as Azure OpenAI.
32+
- Basic tier or higher is recommended.
33+
- [Enable semantic ranking](semantic-how-to-enable-disable.md).
34+
- Enable role-based access control.
35+
- Enable a system identity for Azure AI Search.
36+
37+
To meet the same-region requirement, start by reviewing the [regions for the chat model](https://learn.microsoft.com/azure/ai-services/openai/concepts/models#model-summary-table-and-region-availability) you want to use. Once you identify a region, confirm that Azure AI Search is available in the [same region](https://learn.microsoft.com/azure/search/search-region-support#azure-public-regions).
38+
39+
Make sure you know the name of the deployed model, and have the endpoints for both Azure resources at hand. You'll provide this information in the steps that follow.
2740

2841
## Download file
2942

@@ -37,20 +50,12 @@ Requests to the search endpoint must be authenticated and authorized. You can us
3750

3851
You're setting up two clients, so you need permissions on both resources.
3952

40-
Azure AI Search is receiving the query request from your local system. Assign yourself the **Search Index Data Reader** role assignment for that task. If you're also creating and loading the hotel sample index, add **Search Service Contributor** and **Search Index Data Contributor** roles as well.
53+
Azure AI Search is receiving the query request from your local system. Assign yourself the **Search Index Data Reader** role assignment if the hotels sample index already exists. If it doesn't exist, assign yourself **Search Service Contributor** and **Search Index Data Contributor** roles so that you can create and query the index.
4154

42-
Azure OpenAI is receiving the (query) "Can you recommend a few hotels" from your local system, plus its receiving the search results (source) from the search service. Assign yourself and the search service the **Cognitive Services OpenAI User** role.
55+
Azure OpenAI is receiving the query and the search results from your local system. Assign yourself the **Cognitive Services OpenAI User** role on Azure OpenAI.
4356

4457
1. Sign in to the [Azure portal](https://portal.azure.com).
4558

46-
1. Configure Azure AI Search to use a system-assigned managed identity so that you can you give it role assignments:
47-
48-
1. In the Azure portal, [find your search service](https://portal.azure.com/#blade/HubsExtension/BrowseResourceBlade/resourceType/Microsoft.Search%2FsearchServices).
49-
50-
1. On the left menu, select **Settings** > **Identity**.
51-
52-
1. On the System assigned tab, set status to **On**.
53-
5459
1. Configure Azure AI Search for role-based access:
5560

5661
1. In the Azure portal, find your Azure AI Search service.
@@ -61,12 +66,12 @@ Azure OpenAI is receiving the (query) "Can you recommend a few hotels" from your
6166

6267
1. On the left menu, select **Access control (IAM)**.
6368

64-
1. On Azure AI Search, make sure you have permissions to create, load, and query a search index:
69+
1. On Azure AI Search, select these roles to create, load, and query a search index, and then assign them to your Microsoft Entra ID user identity:
6570

6671
- **Search Index Data Contributor**
6772
- **Search Service Contributor**
6873

69-
1. On Azure OpenAI, select **Access control (IAM)** to assign yourself and the search service identity permissions on Azure OpenAI. The code for this quickstart runs locally. Requests to Azure OpenAI originate from your system. Also, search results from the search engine are passed to Azure OpenAI. For these reasons, both you and the search service need permissions on Azure OpenAI.
74+
1. On Azure OpenAI, select **Access control (IAM)** to assign this role to yourself on Azure OpenAI:
7075

7176
- **Cognitive Services OpenAI User**
7277

@@ -211,6 +216,34 @@ In the remaining sections, you set up API calls to Azure OpenAI and Azure AI Sea
211216
212217
1. On the **Overview** home page, select the link to view the endpoints. Copy the URL. An example endpoint might look like `https://example.openai.azure.com/`.
213218
219+
## Create a virtual environment
220+
221+
In this step, switch back to your local system and Visual Studio Code. We recommend that you create a virtual environment so that you can install the dependencies in isolation.
222+
223+
1. In Visual Studio Code, open the folder containing Quickstart-RAG.ipynb.
224+
225+
1. Press Ctrl-shift-P to open the command palette, search for "Python: Create Environment", and then select `Venv` to create a virtual environment in the current workspace.
226+
227+
1. Select Quickstart-RAG\requirements.txt for the dependencies.
228+
229+
It takes several minutes to create the environment. When the environment is ready, continue to the next step.
230+
231+
## Sign in to Azure
232+
233+
You're using Microsoft Entra ID and role assignments for the connection. Make sure you're logged in to the same tenant and subscription as Azure AI Search and Azure OpenAI. You can use the Azure CLI on the command line to show current properties, change properties, and to sign in. For more information, see [Connect without keys](https://learn.microsoft.com/azure/search/search-get-started-rbac).
234+
235+
Run each of the following commands in sequence.
236+
237+
```azure-cli
238+
az account show
239+
240+
az account set --subscription <PUT YOUR SUBSCRIPTION ID HERE>
241+
242+
az login --tenant <PUT YOUR TENANT ID HERE>
243+
```
244+
245+
You should now be logged in to Azure from your local device.
246+
214247
## Set up the query and chat thread
215248

216249
This section uses Visual Studio Code and Python to call the chat completion APIs on Azure OpenAI.
@@ -271,18 +304,20 @@ This section uses Visual Studio Code and Python to call the chat completion APIs
271304
Sources:\n{sources}
272305
"""
273306

274-
# Query is the question being asked. It's sent to the search engine and the LLM.
307+
# Query is the question being asked. It's sent to the search engine and the chat model
275308
query="Can you recommend a few hotels with complimentary breakfast?"
276309

277-
# Set up the search results and the chat thread.
278-
# Retrieve the selected fields from the search index related to the question.
310+
# Search results are created by the search client
311+
# Search results are composed of the top 5 results and the fields selected from the search index
312+
# Search results include the top 5 matches to your query
279313
search_results = search_client.search(
280314
search_text=query,
281315
top=5,
282316
select="Description,HotelName,Tags"
283317
)
284318
sources_formatted = "\n".join([f'{document["HotelName"]}:{document["Description"]}:{document["Tags"]}' for document in search_results])
285319

320+
# Send the search results and the query to the LLM to generate a response based on the prompt.
286321
response = openai_client.chat.completions.create(
287322
messages=[
288323
{
@@ -293,6 +328,7 @@ This section uses Visual Studio Code and Python to call the chat completion APIs
293328
model=AZURE_DEPLOYMENT_MODEL
294329
)
295330

331+
# Here is the response from the chat model.
296332
print(response.choices[0].message.content)
297333
```
298334

@@ -321,6 +357,8 @@ This section uses Visual Studio Code and Python to call the chat completion APIs
321357

322358
If you get an **Authorization failed** error message, wait a few minutes and try again. It can take several minutes for role assignments to become operational.
323359

360+
If you get a **Resource not found** error message, check the resource URIs and make sure the API version on the chat model is valid.
361+
324362
Otherwise, to experiment further, change the query and rerun the last step to better understand how the model works with the grounding data.
325363

326364
You can also modify the prompt to change the tone or structure of the output.
@@ -331,7 +369,7 @@ This section uses Visual Studio Code and Python to call the chat completion APIs
331369

332370
Azure AI Search supports [complex types](search-howto-complex-data-types.md) for nested JSON structures. In the hotels-sample-index, `Address` is an example of a complex type, consisting of `Address.StreetAddress`, `Address.City`, `Address.StateProvince`, `Address.PostalCode`, and `Address.Country`. The index also has complex collection of `Rooms` for each hotel.
333371

334-
If your index has complex types, your query can provide those fields if you first convert the search results output to JSON, and then pass the JSON to the LLM. The following example adds complex types to the request. The formatting instructions include a JSON specification.
372+
If your index has complex types, your query can provide those fields if you first convert the search results output to JSON, and then pass the JSON to the chat model. The following example adds complex types to the request. The formatting instructions include a JSON specification.
335373

336374
```python
337375
import json

0 commit comments

Comments
 (0)