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
# Quickstart: Generative search (RAG) with grounding data from Azure AI Search
13
13
14
-
This quickstart shows you how to send queries to a Large Language Model (LLM) for a conversational search experience over your indexed content on Azure AI Search. You use the Azure portal to set up the resources, and then run Python code to call the APIs.
14
+
This quickstart shows you how to send basic and complex queries to a Large Language Model (LLM) for a conversational search experience over your indexed content on Azure AI Search. You use the Azure portal to set up the resources, and then run Python code to call the APIs.
15
15
16
16
## Prerequisites
17
17
18
18
- An Azure subscription. [Create one for free](https://azure.microsoft.com/free/).
19
19
20
20
-[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.
21
21
22
-
-[Azure OpenAI](https://aka.ms/oai/access) resource with a deployment of `gpt-35-turbo`, `gpt-4`, or equivalent model, in the same region as Azure AI Search.
22
+
-[Azure OpenAI](https://aka.ms/oai/access) resource with a deployment of `gpt-4o`, `gpt-4o-mini`, or equivalent LLM, in the same region as Azure AI Search.
23
23
24
24
-[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).
25
25
@@ -122,28 +122,68 @@ We recommend the hotels-sample-index, which can be created in minutes and runs o
122
122
123
123
1. **Save** your changes.
124
124
125
-
1. Run the following query in [Search Explorer](search-explorer.md) to test your index: `hotels near the ocean with beach access and good views`.
125
+
1. Run the following query in [Search Explorer](search-explorer.md) to test your index: `complimentary breakfast`.
126
126
127
-
Output should look similar to the following example. Results that are returned directly from the search engine consist of fields and their verbatim values, along with metadata like a search score and a semantic ranking score and caption if you use semantic ranker.
127
+
Output should look similar to the following example. Results that are returned directly from the search engine consist of fields and their verbatim values, along with metadata like a search score and a semantic ranking score and caption if you use semantic ranker. We used a [select statement](search-query-odata-select.md) to return just the HotelName, Description, and Tags fields.
128
128
129
129
```
130
-
"@search.score": 5.600783,
131
-
"@search.rerankerScore": 2.4191176891326904,
132
-
"@search.captions": [
133
-
{
134
-
"text": "Contoso Ocean Motel. Budget. pool\r\nair conditioning\r\nbar. Oceanfront hotel overlooking the beach features rooms with a private balcony and 2 indoor and outdoor pools. Various shops and art entertainment are on the boardwalk, just steps away..",
135
-
"highlights": "Contoso Ocean Motel. Budget.<em> pool\r\nair conditioning\r\nbar. O</em>ceanfront hotel overlooking the beach features rooms with a private balcony and 2 indoor and outdoor pools. Various shops and art entertainment are on the boardwalk, just steps away."
136
-
}
137
-
],
138
-
"HotelId": "41",
139
-
"HotelName": "Contoso Ocean Motel",
140
-
"Description": "Oceanfront hotel overlooking the beach features rooms with a private balcony and 2 indoor and outdoor pools. Various shops and art entertainment are on the boardwalk, just steps away.",
141
-
"Category": "Budget",
142
-
"Tags": [
143
-
"pool",
144
-
"air conditioning",
145
-
"bar"
146
-
],
130
+
{
131
+
"@odata.count": 18,
132
+
"@search.answers": [],
133
+
"value": [
134
+
{
135
+
"@search.score": 2.2896252,
136
+
"@search.rerankerScore": 2.506816864013672,
137
+
"@search.captions": [
138
+
{
139
+
"text": "Head Wind Resort. Suite. coffee in lobby\r\nfree wifi\r\nview. The best of old town hospitality combined with views of the river and cool breezes off the prairie. Our penthouse suites offer views for miles and the rooftop plaza is open to all guests from sunset to 10 p.m. Enjoy a **complimentary continental breakfast** in the lobby, and free Wi-Fi throughout the hotel..",
140
+
"highlights": ""
141
+
}
142
+
],
143
+
"HotelName": "Head Wind Resort",
144
+
"Description": "The best of old town hospitality combined with views of the river and cool breezes off the prairie. Our penthouse suites offer views for miles and the rooftop plaza is open to all guests from sunset to 10 p.m. Enjoy a complimentary continental breakfast in the lobby, and free Wi-Fi throughout the hotel.",
145
+
"Tags": [
146
+
"coffee in lobby",
147
+
"free wifi",
148
+
"view"
149
+
]
150
+
},
151
+
{
152
+
"@search.score": 2.2158256,
153
+
"@search.rerankerScore": 2.288334846496582,
154
+
"@search.captions": [
155
+
{
156
+
"text": "Swan Bird Lake Inn. Budget. continental breakfast\r\nfree wifi\r\n24-hour front desk service. We serve a continental-style breakfast each morning, featuring a variety of food and drinks. Our locally made, oh-so-soft, caramel cinnamon rolls are a favorite with our guests. Other breakfast items include coffee, orange juice, milk, cereal, instant oatmeal, bagels, and muffins..",
157
+
"highlights": ""
158
+
}
159
+
],
160
+
"HotelName": "Swan Bird Lake Inn",
161
+
"Description": "We serve a continental-style breakfast each morning, featuring a variety of food and drinks. Our locally made, oh-so-soft, caramel cinnamon rolls are a favorite with our guests. Other breakfast items include coffee, orange juice, milk, cereal, instant oatmeal, bagels, and muffins.",
162
+
"Tags": [
163
+
"continental breakfast",
164
+
"free wifi",
165
+
"24-hour front desk service"
166
+
]
167
+
},
168
+
{
169
+
"@search.score": 0.92481667,
170
+
"@search.rerankerScore": 2.221315860748291,
171
+
"@search.captions": [
172
+
{
173
+
"text": "White Mountain Lodge & Suites. Resort and Spa. continental breakfast\r\npool\r\nrestaurant. Live amongst the trees in the heart of the forest. Hike along our extensive trail system. Visit the Natural Hot Springs, or enjoy our signature hot stone massage in the Cathedral of Firs. Relax in the meditation gardens, or join new friends around the communal firepit. Weekend evening entertainment on the patio features special guest musicians or poetry readings..",
174
+
"highlights": ""
175
+
}
176
+
],
177
+
"HotelName": "White Mountain Lodge & Suites",
178
+
"Description": "Live amongst the trees in the heart of the forest. Hike along our extensive trail system. Visit the Natural Hot Springs, or enjoy our signature hot stone massage in the Cathedral of Firs. Relax in the meditation gardens, or join new friends around the communal firepit. Weekend evening entertainment on the patio features special guest musicians or poetry readings.",
179
+
"Tags": [
180
+
"continental breakfast",
181
+
"pool",
182
+
"restaurant"
183
+
]
184
+
},
185
+
. . .
186
+
]}
147
187
```
148
188
149
189
## Get service endpoints
@@ -169,29 +209,21 @@ This section uses Visual Studio Code and Python to call the chat completion APIs
1. Set the following variables, substituting placeholders with the endpoints you collected in the previous step.
179
220
180
221
```python
181
222
AZURE_SEARCH_SERVICE: str="PUT YOUR SEARCH SERVICE ENDPOINT HERE"
182
223
AZURE_OPENAI_ACCOUNT: str="PUT YOUR AZURE OPENAI ENDPOINT HERE"
183
-
AZURE_DEPLOYMENT_MODEL: str="gpt-35-turbo"
224
+
AZURE_DEPLOYMENT_MODEL: str="gpt-4o"
184
225
```
185
226
186
-
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 rankersemantic-how-to-enable-disable.md) on your search service, set the value to false.
187
-
188
-
```python
189
-
# Set query parameters for grounding the conversation on your search index
190
-
search_type="text"
191
-
use_semantic_reranker=True
192
-
sources_to_include=5
193
-
```
194
-
195
227
1. Set up clients, the prompt, query, and response.
196
228
197
229
```python
@@ -227,7 +259,7 @@ This section uses Visual Studio Code and Python to call the chat completion APIs
227
259
"""
228
260
229
261
# Query is the question being asked. It's sent to the search engine and the LLM.
230
-
query="Can you recommend a few hotels near the ocean with beach access and good views"
262
+
query="Can you recommend a few hotels with complimentary breakfast?"
231
263
232
264
# Set up the search results and the chat thread.
233
265
# Retrieve the selected fields from the search index related to the question.
@@ -254,12 +286,22 @@ This section uses Visual Studio Code and Python to call the chat completion APIs
254
286
Output isfrom Azure OpenAI, and it consists of recommendations for several hotels. Here's an example of what the output might look like:
255
287
256
288
```
257
-
Based on your criteria, we recommend the following hotels:
258
-
259
-
- Contoso Ocean Motel: located right on the beach and has private balconies with ocean views. They also have indoor and outdoor pools. It's located on the boardwalk near shops and art entertainment.
260
-
- Northwind Plaza & Suites: offers ocean views, free Wi-Fi, full kitchen, and a free breakfast buffet. Although not directly on the beach, this hotel has great views andis near the aquarium. They also have a pool.
261
-
262
-
Several other hotels have views and water features, but do not offer beach access or views of the ocean.
289
+
Sure! Here are a few hotels that offer complimentary breakfast:
290
+
291
+
-**Head Wind Resort**
292
+
- Complimentary continental breakfast in the lobby
293
+
- Free Wi-Fi throughout the hotel
294
+
295
+
-**Double Sanctuary Resort**
296
+
- Continental breakfast included
297
+
298
+
-**White Mountain Lodge & Suites**
299
+
- Continental breakfast available
300
+
301
+
-**Swan Bird Lake Inn**
302
+
- Continental-style breakfast each morning with a variety of food and drinks
303
+
such as caramel cinnamon rolls, coffee, orange juice, milk, cereal,
304
+
instant oatmeal, bagels, and muffins
263
305
```
264
306
265
307
If you get a **Forbidden** error message, check Azure AI Search configuration to make sure role-based access is enabled.
@@ -272,6 +314,85 @@ This section uses Visual Studio Code and Python to call the chat completion APIs
272
314
273
315
You might also try the query without semantic ranking by setting `use_semantic_reranker=False`in the query parameters step. Semantic ranking can noticably improve the relevance of query results and the ability of the LLM to return useful information. Experimentation can help you decide whether it makes a difference for your content.
274
316
317
+
## Send a complex RAG query
318
+
319
+
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 complextype, consisting of `Address.StreetAddress`, `Address.City`, `Address.StateProvince`, `Address.PostalCode`, and`Address.Country`. The index also has complex collection of `Rooms`for each hotel.
320
+
321
+
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.
322
+
323
+
```python
324
+
import json
325
+
326
+
# Query is the question being asked. It's sent to the search engine and the LLM.
327
+
query="Can you recommend a few hotels that offer complimentary breakfast?
328
+
Tell me their description, address, tags, and the rate for one room that sleeps 4 people."
329
+
330
+
# Set up the search results and the chat thread.
331
+
# Retrieve the selected fields from the search index related to the question.
0 commit comments