Skip to content

Commit 664b7a2

Browse files
authored
Merge pull request #137 from HeidiSteen/main
Update Quickstart-RAG notebook
2 parents 67c92d2 + c1ab30a commit 664b7a2

File tree

1 file changed

+31
-100
lines changed

1 file changed

+31
-100
lines changed

Quickstart-RAG/Quickstart-rag.ipynb

Lines changed: 31 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"\n",
1717
"A non-vector index isn't ideal for RAG patterns, but it makes for a simpler example.\n",
1818
"\n",
19-
"Once you understand the fundamentals of integrating queries from Azure AI Search to an LLM, you can build on that experience by adding vector fields and vector and hybrid queries. We recommend the [phi-chat Python code example](https://github.com/Azure/azure-search-vector-samples/blob/main/demo-python/code/phi-chat/phi-chat.ipynb) for that step.\n",
19+
"Once you understand the fundamentals of integrating queries from Azure AI Search to a chat completion model on Azure OpenAI, you can build on that experience by adding vector fields and vector and hybrid queries. We recommend the [phi-chat Python code example](https://github.com/Azure/azure-search-vector-samples/blob/main/demo-python/code/phi-chat/phi-chat.ipynb) for that step.\n",
2020
"\n",
2121
"This example is fully documented in [Quickstart: Generative search (RAG) with grounding data from Azure AI Search](https://learn.microsoft.com/azure/search/search-get-started-rag). If you need more guidance than the readme provides, please refer to the article.\n"
2222
]
@@ -29,7 +29,7 @@
2929
"\n",
3030
"- [Azure OpenAI](https://learn.microsoft.com/azure/ai-services/openai/how-to/create-resource)\n",
3131
"\n",
32-
" - Deploy a chat model (gpt-4o, gpt-4o-mini, or equivalent LLM).\n",
32+
" - Deploy a chat completion model (gpt-4o, gpt-4o-mini, or equivalent model).\n",
3333
"\n",
3434
"- [Azure AI Search](https://learn.microsoft.com/azure/search/search-create-service-portal)\n",
3535
"\n",
@@ -45,12 +45,9 @@
4545
"\n",
4646
"This quickstart assumes authentication and authorization using Microsoft Entra ID and role assignments. It also assumes that you run this code from your local device.\n",
4747
"\n",
48-
"1. To create, load, and query the sample index on Azure AI Search, you must personally have role assignments for: **Search Index Data Reader**, **Search Index Data Contributor**, **Search Service Contributor**.\n",
48+
"1. To create, load, and query the sample hotels index on Azure AI Search, you must personally have role assignments for **Search Index Data Contributor** and **Search Service Contributor**. If the hotels index already exists, you only need **Search Index Data Reader**.\n",
4949
"\n",
50-
"1. To send the query and search results to Azure OpenAI, both you and the search system identity must have **Cognitive Services OpenAI User** permissions on Azure OpenAI.\n",
51-
"\n",
52-
" - Queries in the system prompt are sent from your local system, which is why you need permissions on Azure OpenAI.\n",
53-
" - Results used for grounding data are sent from the search engine, which is why the search service needs permissions on Azure OpenAI.\n",
50+
"1. To send the query and search results to Azure OpenAI, you must have **Cognitive Services OpenAI User** permissions on Azure OpenAI.\n",
5451
"\n",
5552
"## Create the sample index\n",
5653
"\n",
@@ -105,6 +102,22 @@
105102
"\n",
106103
"It takes several minutes to create the environment. When the environment is ready, continue to the next step.\n",
107104
"\n",
105+
"## Log in to Azure\n",
106+
"\n",
107+
"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 log in. For more information, see [Connect without keys](https://learn.microsoft.com/azure/search/search-get-started-rbac). \n",
108+
"\n",
109+
"Run each of the following commands in sequence.\n",
110+
"\n",
111+
"```azurecli\n",
112+
"az account show\n",
113+
"\n",
114+
"az account set --subscription <PUT YOUR SUBSCRIPTION ID HERE>\n",
115+
"\n",
116+
"az login --tenant <PUT YOUR TENANT ID HERE>\n",
117+
"```\n",
118+
"\n",
119+
"You should now be logged in to Azure.\n",
120+
"\n",
108121
"## Run the code"
109122
]
110123
},
@@ -136,43 +149,14 @@
136149
"source": [
137150
"## Basic RAG Query\n",
138151
"\n",
139-
"The following code demonstrates how to query fields such as strings or string collections and use them to answer a question using RAG"
152+
"The following code demonstrates how to query fields such as strings or string collections in a search index, and send the results to a chat completion model. The response returned to the user is from the chat completion model."
140153
]
141154
},
142155
{
143156
"cell_type": "code",
144-
"execution_count": 3,
157+
"execution_count": null,
145158
"metadata": {},
146-
"outputs": [
147-
{
148-
"name": "stdout",
149-
"output_type": "stream",
150-
"text": [
151-
"Sure! Here are a few hotels that offer complimentary breakfast:\n",
152-
"\n",
153-
"- **Whitefish Lodge & Suites**:\n",
154-
" - Continental breakfast\n",
155-
" - Free parking\n",
156-
" - Free wifi\n",
157-
"\n",
158-
"- **Trails End Motel**:\n",
159-
" - Free hot breakfast buffet\n",
160-
" - Free wireless internet\n",
161-
"\n",
162-
"- **Peaceful Market Hotel & Spa**:\n",
163-
" - Continental breakfast\n",
164-
" - Restaurant\n",
165-
" - View\n",
166-
"\n",
167-
"- **Marquis Plaza & Suites**:\n",
168-
" - Free breakfast buffet\n",
169-
" - Free wifi\n",
170-
" - Pool\n",
171-
"\n",
172-
"Enjoy your stay!\n"
173-
]
174-
}
175-
],
159+
"outputs": [],
176160
"source": [
177161
"# Set up the query for generating responses\n",
178162
"from azure.identity import DefaultAzureCredential\n",
@@ -218,6 +202,7 @@
218202
")\n",
219203
"sources_formatted = \"\\n\".join([f'{document[\"HotelName\"]}:{document[\"Description\"]}:{document[\"Tags\"]}' for document in search_results])\n",
220204
"\n",
205+
"# Send the search results to the LLM to generate a response based on the prompt.\n",
221206
"response = openai_client.chat.completions.create(\n",
222207
" messages=[\n",
223208
" {\n",
@@ -228,6 +213,7 @@
228213
" model=AZURE_DEPLOYMENT_MODEL\n",
229214
")\n",
230215
"\n",
216+
"# Here is the response from the chat model.\n",
231217
"print(response.choices[0].message.content)"
232218
]
233219
},
@@ -241,9 +227,9 @@
241227
"\n",
242228
"+ Make sure you [enabled RBAC](https://learn.microsoft.com/azure/search/search-security-enable-roles?tabs=config-svc-portal%2Cdisable-keys-portal) on Azure AI Search. An HttpStatusMessage of **Forbidden** is an indicator that RBAC isn't enabled.\n",
243229
"\n",
244-
"+ Recheck role assignments for yourself and for the search service system identity.\n",
230+
"+ Recheck role assignments if you get a 401 error. You should also review the steps in [Connect without keys](https://learn.microsoft.com/azure/search/search-get-started-rbac).\n",
245231
"\n",
246-
"+ Check firewall settings. This quickstart assumes public network access. If you have a firewall, you need to add rules to allow inbound requests from your device and for service-to-service connections.\n",
232+
"+ Check firewall settings. This quickstart assumes public network access. If you have a firewall, you need to add rules to allow inbound requests from your device and for service-to-service connections. For more information, see [Configure network access](https://learn.microsoft.com/azure/search/service-configure-firewall).\n",
247233
"\n",
248234
"+ For more debugging guidance, see the [troubleshooting section](https://learn.microsoft.com/azure/search/search-get-started-rag#troubleshooting-errors) in the Quickstart documentation."
249235
]
@@ -259,64 +245,9 @@
259245
},
260246
{
261247
"cell_type": "code",
262-
"execution_count": 4,
248+
"execution_count": null,
263249
"metadata": {},
264-
"outputs": [
265-
{
266-
"name": "stdout",
267-
"output_type": "stream",
268-
"text": [
269-
"Sure! Here are a few hotels that offer complimentary breakfast:\n",
270-
"\n",
271-
"1. **Trails End Motel**\n",
272-
" - **Description**: Only 8 miles from Downtown. On-site bar/restaurant, Free hot breakfast buffet, Free wireless internet, All non-smoking hotel. Only 15 miles from the airport.\n",
273-
" - **Address**: 7014 E Camelback Rd, Scottsdale, AZ 85251, USA\n",
274-
" - **Tags**: Continental breakfast, view\n",
275-
" - **Room Recommendation**: \n",
276-
" - **Type**: Suite, 2 Queen Beds (City View)\n",
277-
" - **Rate**: $266.99 per night\n",
278-
" - **Sleeps**: 4\n",
279-
"\n",
280-
"2. **Whitefish Lodge & Suites**\n",
281-
" - **Description**: Located in the heart of the forest. Enjoy Warm Weather, Beach Club Services, Natural Hot Springs, Airport Shuttle.\n",
282-
" - **Address**: 3000 E 1st Ave, Denver, CO 80206, USA\n",
283-
" - **Tags**: Continental breakfast, free parking, free wifi\n",
284-
" - **Room Recommendation**: \n",
285-
" - **Type**: Suite, 2 Queen Beds (Mountain View)\n",
286-
" - **Rate**: $256.99 per night\n",
287-
" - **Sleeps**: 4\n",
288-
"\n",
289-
"3. **Peaceful Market Hotel & Spa**\n",
290-
" - **Description**: Book now and Save up to 30%. Central location. Steps from Empire State Building & Times Square, in Chelsea neighborhood. Brand new rooms. Impeccable service.\n",
291-
" - **Address**: 11 Times Sq, New York, NY 10036, USA\n",
292-
" - **Tags**: Continental breakfast, restaurant, view\n",
293-
" - **Room Recommendation**: \n",
294-
" - **Type**: Suite, 2 Queen Beds (Waterfront View)\n",
295-
" - **Rate**: $260.99 per night\n",
296-
" - **Sleeps**: 4\n",
297-
"\n",
298-
"4. **Nova Hotel & Spa**\n",
299-
" - **Description**: 1 Mile from the airport. Free WiFi, Outdoor Pool, Complimentary Airport Shuttle, 6 miles from the beach & 10 miles from downtown.\n",
300-
" - **Address**: 4400 Ashford Dunwoody Rd NE, Atlanta, GA 30346, USA\n",
301-
" - **Tags**: Pool, continental breakfast, free parking\n",
302-
" - **Room Recommendation**: \n",
303-
" - **Type**: Deluxe Room, 2 Queen Beds (City View)\n",
304-
" - **Rate**: $161.99 per night\n",
305-
" - **Sleeps**: 4\n",
306-
"\n",
307-
"5. **Scottish Inn**\n",
308-
" - **Description**: Newly Redesigned Rooms & airport shuttle. Minutes from the airport, enjoy lakeside amenities, a resort-style pool & stylish new guestrooms with Internet TVs.\n",
309-
" - **Address**: 3301 Veterans Memorial Blvd, Metairie, LA 70002, USA\n",
310-
" - **Tags**: 24-hour front desk service, continental breakfast, free wifi\n",
311-
" - **Room Recommendation**: \n",
312-
" - **Type**: Deluxe Room, 2 Queen Beds (City View)\n",
313-
" - **Rate**: $140.99 per night\n",
314-
" - **Sleeps**: 4\n",
315-
"\n",
316-
"I hope you find these recommendations helpful! Enjoy your stay!\n"
317-
]
318-
}
319-
],
250+
"outputs": [],
320251
"source": [
321252
"import json\n",
322253
"\n",
@@ -351,7 +282,7 @@
351282
],
352283
"metadata": {
353284
"kernelspec": {
354-
"display_name": ".venv",
285+
"display_name": "Python 3",
355286
"language": "python",
356287
"name": "python3"
357288
},
@@ -365,7 +296,7 @@
365296
"name": "python",
366297
"nbconvert_exporter": "python",
367298
"pygments_lexer": "ipython3",
368-
"version": "3.11.9"
299+
"version": "3.10.11"
369300
}
370301
},
371302
"nbformat": 4,

0 commit comments

Comments
 (0)