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
@@ -53,9 +53,17 @@ It can take a minute to set up. If you run into problems, see [Python environmen
53
53
index_name: str="hotels-quickstart"
54
54
```
55
55
56
-
### Create or update an index
56
+
## Update and query the index
57
57
58
-
Create or update an index schema to include a `SemanticConfiguration`. If you're updating an existing index, this modification doesn't require a reindexing because the structure of your documents is unchanged.
58
+
In this section, you update a search index and send a query that invokes semantic ranking. Visual Studio Code displays the response after you run each cell. For more information about each step, see [Explaining the code](#explaining-the-code).
59
+
60
+
## Explaining the code
61
+
62
+
Add `SemanticConfiguration` to a search index definition. If you're updating an existing index, this modification doesn't require a reindexing because the structure of your documents is unchanged.
63
+
64
+
Provide the entire schema plus the new SemanticConfiguration section. We recommend getting the index schema from the search service to ensure you're updating the correct schema.
65
+
66
+
This example is the Python code for the Hotels sample index schema, plus the semantic configuration.
59
67
60
68
```python
61
69
from azure.search.documents.indexes import SearchIndexClient
@@ -72,7 +80,7 @@ from azure.search.documents.indexes.models import (
72
80
SemanticSearch
73
81
)
74
82
75
-
#Create a search schema
83
+
#Update the search schema, providing the entire schema plus the changes.
76
84
index_client= SearchIndexClient(
77
85
endpoint=search_endpoint, credential=credential)
78
86
fields= [
@@ -117,104 +125,6 @@ result = index_client.create_or_update_index(index)
117
125
print(f'{result.name} created')
118
126
```
119
127
120
-
### Create a documents payload
121
-
122
-
You can push JSON documents to a search index. Documents must match the index schema.
123
-
124
-
```python
125
-
documents = [
126
-
{
127
-
"@search.action": "upload",
128
-
"HotelId": "1",
129
-
"HotelName": "Stay-Kay City Hotel",
130
-
"Description": "This classic hotel is fully-refurbished and ideally located on the main commercial artery of the city in the heart of New York. A few minutes away is Times Square and the historic centre of the city, as well as other places of interest that make New York one of America's most attractive and cosmopolitan cities.",
"Description": "The hotel is situated in a nineteenth century plaza, which has been expanded and renovated to the highest architectural standards to create a modern, functional and first-class hotel in which art and unique historical elements coexist with the most modern comforts. The hotel also regularly hosts events like wine tastings, beer dinners, and live music.",
149
-
"Category": "Boutique",
150
-
"Tags": [ "pool", "free wifi", "concierge" ],
151
-
"ParkingIncluded": "false",
152
-
"LastRenovationDate": "2019-02-18T00:00:00Z",
153
-
"Rating": 3.60,
154
-
"Address": {
155
-
"StreetAddress": "140 University Town Center Dr",
156
-
"City": "Sarasota",
157
-
"StateProvince": "FL",
158
-
"PostalCode": "34243",
159
-
"Country": "USA"
160
-
}
161
-
},
162
-
{
163
-
"@search.action": "upload",
164
-
"HotelId": "3",
165
-
"HotelName": "Gastronomic Landscape Hotel",
166
-
"Description": "The Gastronomic Hotel stands out for its culinary excellence under the management of William Dough, who advises on and oversees all of the Hotel’s restaurant services.",
"Description": "Sublime Palace Hotel is located in the heart of the historic center of Sublime in an extremely vibrant and lively area within short walking distance to the sites and landmarks of the city and is surrounded by the extraordinary beauty of churches, buildings, shops and monuments. Sublime Cliff is part of a lovingly restored 19th century resort, updated for every modern convenience.",
result = search_client.upload_documents(documents=documents)
209
-
print("Upload of new document succeeded: {}".format(result[0].succeeded))
210
-
exceptExceptionas ex:
211
-
print (ex.message)
212
-
213
-
214
-
index_client = SearchIndexClient(
215
-
endpoint=search_endpoint, credential=credential)
216
-
```
217
-
218
128
### Run your first query
219
129
220
130
Start with an empty query as a verification step, proving that the index is operational. You should get an unordered list of hotel names and descriptions, with a count of 4 indicating that there are four documents in the index.
Copy file name to clipboardExpand all lines: articles/search/includes/quickstarts/semantic-ranker-rest.md
+26-4Lines changed: 26 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,16 +20,38 @@ We recommend [Visual Studio Code](https://code.visualstudio.com/download) with a
20
20
21
21
1. Start Visual Studio Code and create a new .http or .rest file.
22
22
23
-
1. At the top, specify environment variables.
23
+
1. At the top, specify environment variables for your search service, authorization, and index name.
24
+
25
+
+ For @baseURL, sign in to the Azure portal and copy the URL from the search service **Overview** page.
26
+
27
+
+ For @token, follow the instruction in [Connect without keys](../../search-get-started-rbac.md) to get your personal identity token.
28
+
29
+
+ For @index-name, provide a unique name or use the default, *hotel-semantic-quickstart*.
24
30
25
31
1. Paste in your first request and then select **Send**. This request returns a list of existing indexes. You should get an HTTP 200 Success status code and a list of indexes, including hotels-sample-index. This step confirms access to the search service.
26
32
27
-
## Add semantic configuration to an index
33
+
```http
34
+
### List existing indexes by name (verify the connection)
35
+
GET {{baseUrl}}/indexes?api-version=2024-07-01&$select=name HTTP/1.1
36
+
Content-Type: application/json
37
+
Authorization: Bearer {{token}}
38
+
```
28
39
29
-
TBD
40
+
## Update and query the index
41
+
42
+
In this section, you make REST API calls to update a search index and send a query that invokes semantic ranking. Visual Studio Code displays the response to each request in an adjacent pane. For more information about each step, see [Explaining the code](#explaining-the-code).
43
+
44
+
## Explaining the code
45
+
46
+
This section explains the REST API calls that you made to:
47
+
48
+
+[Update an index with a semantic configuration](#add-a-semantic-configuration-to-the-index)
49
+
+[Query the index using semantic parameters](#add-semantic-ranking-to-queries)
@@ -41,9 +41,11 @@ When you're working in your own subscription, it's a good idea at the end of a p
41
41
42
42
You can find and manage resources in the Azure portal, using the **All resources** or **Resource groups** link in the left-navigation pane.
43
43
44
-
## Next step
44
+
## Related content
45
45
46
-
In this quickstart, you learned how to invoke semantic ranking on an existing index. We recommend trying semantic ranking on your own indexes as a next step. However, if you want to continue with demos, try the following tutorial:
46
+
In this quickstart, you learned how to invoke semantic ranking on an existing index. We recommend trying semantic ranking on your own indexes as a next step. The following articles can help you get started.
47
47
48
-
> [!div class="nextstepaction"]
49
-
> [Tutorial: Add search to web apps](tutorial-csharp-overview.md)
0 commit comments