Skip to content

Commit 428fc56

Browse files
Merge pull request #284889 from HeidiSteen/heidist-august
[azure search] Updates to rag quickstart
2 parents f6f9821 + 89ebd06 commit 428fc56

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

articles/search/retrieval-augmented-generation-overview.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ Here are some tips for maximizing relevance and recall:
151151

152152
In comparison and benchmark testing, hybrid queries with text and vector fields, supplemented with semantic ranking, produce the most relevant results.
153153

154-
### Example code of an Azure AI Search query for RAG scenarios
154+
### Example code for a RAG workflow
155155

156156
The following Python code demonstrates the essential components of a RAG workflow in Azure AI Search. You need to set up the clients, define a system prompt, and provide a query. The prompt tells the LLM to use just the results from the query, and how to return the results. For more steps based on this example, see this [RAG quickstart](search-get-started-rag.md).
157157

@@ -176,7 +176,8 @@ search_client = SearchClient(
176176
credential=credential
177177
)
178178

179-
# This prompt provides instructions to the model
179+
# This prompt provides instructions to the model.
180+
# The prompt includes the query and the source, which are specified further down in the code.
180181
GROUNDED_PROMPT="""
181182
You are a friendly assistant that recommends hotels based on activities and amenities.
182183
Answer the query using only the sources provided below in a friendly and concise bulleted manner.
@@ -187,7 +188,7 @@ Query: {query}
187188
Sources:\n{sources}
188189
"""
189190

190-
# Query is the question being asked
191+
# The query is sent to the search engine, but it's also passed in the prompt
191192
query="Can you recommend a few hotels near the ocean with beach access and good views"
192193

193194
# Retrieve the selected fields from the search index related to the question
@@ -205,7 +206,7 @@ response = openai_client.chat.completions.create(
205206
"content": GROUNDED_PROMPT.format(query=query, sources=sources_formatted)
206207
}
207208
],
208-
model="gpt-4o"
209+
model="gpt-35"
209210
)
210211

211212
print(response.choices[0].message.content)

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ author: HeidiSteen
66
ms.author: heidist
77
ms.service: cognitive-search
88
ms.topic: quickstart
9-
ms.date: 07/22/2024
9+
ms.date: 08/16/2024
1010
---
1111

1212
# Quickstart: Generative search (RAG) with grounding data from Azure AI Search
@@ -35,11 +35,11 @@ Requests to the search endpoint must be authenticated and authorized. You can us
3535

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

38-
1. Configure Azure OpenAI to use a system-assigned managed identity:
38+
1. Configure Azure AI Search to use a system-assigned managed identity:
3939

40-
1. In the Azure portal, find your Azure OpenAI resource.
40+
1. In the Azure portal, [find your search service](https://portal.azure.com/#blade/HubsExtension/BrowseResourceBlade/resourceType/Microsoft.Search%2FsearchServices).
4141

42-
1. On the left menu, select **Resource management** > **Identity**.
42+
1. On the left menu, select **Settings** > **Identity**.
4343

4444
1. On the System assigned tab, set status to **On**.
4545

@@ -53,12 +53,13 @@ Requests to the search endpoint must be authenticated and authorized. You can us
5353

5454
1. On the left menu, select **Access control (IAM)**.
5555

56-
1. On Azure AI Search, add two role assignments for the Azure OpenAI managed identity:
56+
1. On Azure AI Search, make sure you have permissions to create, load, and query a search index:
5757

5858
- **Search Index Data Reader**
59+
- **Search Index Data Contributor**
5960
- **Search Service Contributor**
6061

61-
1. On Azure OpenAI, select **Access control (IAM)** to assign yourself to a role. The code for this quickstart runs locally. Requests to Azure OpenAI originate from your system:
62+
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.
6263

6364
- **Cognitive Services OpenAI User**
6465

@@ -165,6 +166,7 @@ This section uses Visual Studio Code and Python to call the chat completion APIs
165166
! pip install azure-search-documents==11.6.0b4 --quiet
166167
! pip install azure-identity==1.16.0 --quiet
167168
! pip install openai --quiet
169+
! pip intall aiohttp --quiet
168170
```
169171

170172
1. Set the following variables, substituting placeholders with the endpoints you collected in the previous step.
@@ -175,7 +177,7 @@ This section uses Visual Studio Code and Python to call the chat completion APIs
175177
AZURE_DEPLOYMENT_MODEL: str = "gpt-35-turbo"
176178
```
177179

178-
1. Run the following code to set query parameters. The query is a keyword search using semantic ranking. In a keyword search, the search engine returns up to 50 matches, but only the top 5 are provided to the model. If you can't enable semantic ranking on your search service, set the value to false.
180+
1. Run the following code to set query parameters. The query is a keyword search using semantic ranking. In a keyword search, the search engine returns up to 50 matches, but only the top 5 are provided to the model. If you can't [enable semantic ranking](semantic-how-to-enable-disable.md) on your search service, set the value to false.
179181

180182
```python
181183
# Set query parameters for grounding the conversation on your search index
@@ -308,6 +310,8 @@ This section uses Visual Studio Code and Python to call the chat completion APIs
308310
Several other hotels have views and water features, but do not offer beach access or views of the ocean.
309311
```
310312

313+
If you get an authorization error message, wait a few minutes and try again. It can take several minutes for role assignments to become operational.
314+
311315
To experiment further, change the query and rerun the last step to better understand how the model works with your data.
312316

313317
You can also modify the prompt to change the tone or structure of the output.

0 commit comments

Comments
 (0)