Skip to content

Commit 655e501

Browse files
authored
Merge pull request #115 from HeidiSteen/main
RAG quickstart updates
2 parents 38e6ec6 + 688a512 commit 655e501

File tree

2 files changed

+71
-21
lines changed

2 files changed

+71
-21
lines changed

Quickstart-RAG/Quickstart-rag.ipynb

Lines changed: 67 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,31 @@
2525
"source": [
2626
"## Prerequisites\n",
2727
"\n",
28-
"- Azure AI Search, Basic tier or higher is recommended. Enable semantic ranking and role-based access control.\n",
28+
"- [Azure OpenAI](https://learn.microsoft.com/azure/ai-services/openai/how-to/create-resource)\n",
2929
"\n",
30-
"- Azure OpenAI, in the same region as Azure AI Search. Configure Azure OpenAI to use a system managed identity.\n",
30+
" - Configure Azure OpenAI to use a system managed identity.\n",
31+
" - Deploy a chat model (GPT-3.5-Turbo, GPT-4, or equivalent LLM).\n",
3132
"\n",
32-
"- Deployment GPT-3.5-Turbo, GPT-4, or equivalent LLM.\n",
33+
"- [Azure AI Search](https://learn.microsoft.com/azure/search/search-create-service-portal)\n",
3334
"\n",
34-
"- Create the hotels-sample-index using [this quickstart](https://learn.microsoft.com/azure/search/search-get-started-portal), and then modify it to use this semantic configuration:\n",
35+
" - Basic tier or higher is recommended.\n",
36+
" - Choose the same region as Azure OpenAI.\n",
37+
" - Enable semantic ranking.\n",
38+
" - Enable role-based access control.\n",
39+
"\n",
40+
"## Configure access\n",
41+
"\n",
42+
"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",
43+
"\n",
44+
"1. To create and load the sample index on Azure AI Search, you must have role assignments for: **Search Index Data Reader**, **Search Index Data Contributor**, **Search Service Contributor**.\n",
45+
"\n",
46+
"1. To send the query and results from the search engine to Azure OpenAI, the search system identity must have **Cognitive Services OpenAI User** permissions on Azure OpenAI.\n",
47+
"\n",
48+
"## Create the sample index\n",
49+
"\n",
50+
"This quickstart assumes the hotels-sample-index, which you can create in minutes using [this quickstart](https://learn.microsoft.com/azure/search/search-get-started-portal).\n",
51+
"\n",
52+
"Once the index exists, modify it in the Azure portal to use this semantic configuration:\n",
3553
" \n",
3654
" ```json\n",
3755
" \"semantic\": {\n",
@@ -49,38 +67,47 @@
4967
" }]},\n",
5068
" ```\n",
5169
"\n",
52-
"- On Azure AI Search, create a role assignment for the Azure OpenAI managed identity. Required roles: **Search Index Data Reader**, **Search Service Contributor**.\n",
70+
"Now that you have your Azure resources, an index, and model in place, you can run the script to chat with the index."
71+
]
72+
},
73+
{
74+
"cell_type": "markdown",
75+
"metadata": {},
76+
"source": [
77+
"## Run the code\n",
78+
"\n",
79+
"1. Create a virtual environment. In Visual Studio Code, 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.\n",
80+
"\n",
81+
"1. Select Quickstart-RAG\\requirements.txt for the dependencies.\n",
5382
"\n",
54-
"- On Azure OpenAI, create a role assigment for the user running the code: Required role: **Cognitive Services OpenAI User**."
83+
"It takes several minutes to create the environment. When the environment is ready, continue to the next step."
5584
]
5685
},
5786
{
5887
"cell_type": "code",
59-
"execution_count": null,
88+
"execution_count": 6,
6089
"metadata": {},
6190
"outputs": [],
6291
"source": [
6392
"# Package install for quickstart\n",
64-
"! pip install azure-search-documents==11.6.0b4 --quiet\n",
65-
"! pip install azure-identity==1.16.0 --quiet\n",
66-
"! pip install openai --quiet"
93+
"! pip install -r requirements.txt --quiet"
6794
]
6895
},
6996
{
7097
"cell_type": "code",
71-
"execution_count": null,
98+
"execution_count": 7,
7299
"metadata": {},
73100
"outputs": [],
74101
"source": [
75-
"# Set endpoints and deployment model\n",
76-
"AZURE_SEARCH_SERVICE: str = \"PUT YOUR SEARCH SERVICE ENDPOINT HERE\"\n",
77-
"AZURE_OPENAI_ACCOUNT: str = \"PUT YOUR AZURE OPENAI ENDPOINT HERE\"\n",
78-
"AZURE_DEPLOYMENT_MODEL: str = \"gpt-35-turbo\""
102+
"# Set endpoints and deployment model (provide the name of the deployment)\n",
103+
" AZURE_SEARCH_SERVICE: str = \"PUT YOUR SEARCH SERVICE ENDPOINT HERE\"\n",
104+
" AZURE_OPENAI_ACCOUNT: str = \"PUT YOUR AZURE OPENAI ENDPOINT HERE\"\n",
105+
" AZURE_DEPLOYMENT_MODEL: str = \"gpt-35-turbo\""
79106
]
80107
},
81108
{
82109
"cell_type": "code",
83-
"execution_count": null,
110+
"execution_count": 8,
84111
"metadata": {},
85112
"outputs": [],
86113
"source": [
@@ -92,7 +119,7 @@
92119
},
93120
{
94121
"cell_type": "code",
95-
"execution_count": null,
122+
"execution_count": 16,
96123
"metadata": {},
97124
"outputs": [],
98125
"source": [
@@ -185,9 +212,21 @@
185212
},
186213
{
187214
"cell_type": "code",
188-
"execution_count": null,
215+
"execution_count": 19,
189216
"metadata": {},
190-
"outputs": [],
217+
"outputs": [
218+
{
219+
"name": "stdout",
220+
"output_type": "stream",
221+
"text": [
222+
"Based on your preferences, I recommend the following hotels: \n",
223+
"\n",
224+
"- Ocean Air Motel: This hotel is oceanfront with beach access, two pools, and a private balcony with ocean views. \n",
225+
"- Marquis Plaza & Suites: This hotel has a view of the ocean and amenities like free Wi-Fi, a full kitchen, and a free breakfast buffet. \n",
226+
"- Trails End Motel: Though not directly on the ocean, this hotel does have a view and is only 8 miles from downtown. Amenities include an on-site bar/restaurant, free hot breakfast buffet, and free Wi-Fi.\n"
227+
]
228+
}
229+
],
191230
"source": [
192231
"# Instantiate the chat thread and run the conversation\n",
193232
"import azure.identity.aio\n",
@@ -201,12 +240,19 @@
201240
" query=\"Can you recommend a few hotels near the ocean with beach access and good views\",\n",
202241
" search_type=SearchType(search_type),\n",
203242
" use_semantic_reranker=use_semantic_reranker,\n",
204-
" sources_to_include=sources_to_include,\n",
205-
" k=k)\n",
243+
" sources_to_include=sources_to_include\n",
244+
" )\n",
206245
" await chat_thread.get_openai_response(openai_client=openai_client, model=chat_deployment)\n",
207246
"\n",
208247
"print(chat_thread.get_last_message()[\"content\"])"
209248
]
249+
},
250+
{
251+
"cell_type": "markdown",
252+
"metadata": {},
253+
"source": [
254+
"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."
255+
]
210256
}
211257
],
212258
"metadata": {

Quickstart-RAG/requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
azure-search-documents==11.6.0b4
2+
azure-identity==1.16.0
3+
openai
4+
aiohttp

0 commit comments

Comments
 (0)