Skip to content

Commit 57dc0fb

Browse files
authored
Merge pull request #5524 from HeidiSteen/heidist-work
Fixed semantic ranking quickstarts to use approved hotels data
2 parents 7bb2613 + 0ed5bb6 commit 57dc0fb

File tree

4 files changed

+26
-32
lines changed

4 files changed

+26
-32
lines changed

articles/search/includes/quickstarts/dotnet-semantic.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ms.service: azure-ai-search
55
ms.custom:
66
- ignite-2023
77
ms.topic: include
8-
ms.date: 10/22/2024
8+
ms.date: 06/13/2025
99
---
1010

1111
Build a console application by using the [**Azure.Search.Documents**](/dotnet/api/overview/azure/search.documents-readme) client library to add semantic ranking to an existing search index.
@@ -78,13 +78,12 @@ private static void CreateIndex(string indexName, SearchIndexClient adminClient)
7878
{
7979
Configurations =
8080
{
81-
new SemanticConfiguration("my-semantic-config", new()
81+
new SemanticConfiguration("semantic-config", new()
8282
{
8383
TitleField = new SemanticField("HotelName"),
8484
ContentFields =
8585
{
8686
new SemanticField("Description"),
87-
new SemanticField("Description_fr")
8887
},
8988
KeywordsFields =
9089
{
@@ -125,7 +124,7 @@ options = new SearchOptions()
125124
QueryType = Azure.Search.Documents.Models.SearchQueryType.Semantic,
126125
SemanticSearch = new()
127126
{
128-
SemanticConfigurationName = "my-semantic-config",
127+
SemanticConfigurationName = "semantic-config",
129128
QueryCaption = new(QueryCaptionType.Extractive)
130129
}
131130
};
@@ -134,15 +133,15 @@ options.Select.Add("Category");
134133
options.Select.Add("Description");
135134

136135
// response = srchclient.Search<Hotel>("*", options);
137-
response = srchclient.Search<Hotel>("what hotel has a good restaurant on site", options);
136+
response = srchclient.Search<Hotel>("restaurant on site", options);
138137
WriteDocuments(response);
139138
```
140139

141-
For comparison, here are results from a query that uses the default BM25 ranking, based on term frequency and proximity. Given the query "what hotel has a good restaurant on site", the BM25 ranking algorithm returns matches in the order shown in this screenshot:
140+
For comparison, here are results from a query that uses the default BM25 ranking, based on term frequency and proximity. Given the query "restaurant on site", the BM25 ranking algorithm returns matches in the order shown in this screenshot, where the match on the "site" is considered more relevant because it's rare across the dataset:
142141

143142
:::image type="content" source="../../media/quickstart-semantic/bm25-ranking.png" alt-text="Screenshot showing matches ranked by BM25.":::
144143

145-
In contrast, when semantic ranking is applied to the same query ("what hotel has a good restaurant on site"), the results are reranked based on semantic relevance to the query. This time, the top result is the hotel with the restaurant, which aligns better to user expectations.
144+
In contrast, when semantic ranking is applied to the same query ("restaurant on site"), the results are reranked based on semantic relevance to the query. This time, the top result is the hotel with the restaurant, which aligns better to user expectations.
146145

147146
:::image type="content" source="../../media/quickstart-semantic/semantic-ranking.png" alt-text="Screenshot showing matches ranked based on semantic ranking.":::
148147

articles/search/includes/quickstarts/python-semantic.md

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ms.service: azure-ai-search
55
ms.custom:
66
- ignite-2023
77
ms.topic: include
8-
ms.date: 10/22/2024
8+
ms.date: 06/13/2025
99
---
1010

1111
Use a Jupyter notebook and the [**azure-search-documents**](/python/api/overview/azure/search-documents-readme) library in the Azure SDK for Python to learn about semantic ranking.
@@ -20,7 +20,7 @@ We recommend a virtual environment for this quickstart:
2020

2121
1. Start Visual Studio Code.
2222

23-
1. Create a new ipynb file.
23+
1. Create a new .ipynb file.
2424

2525
1. Open the Command Palette by using **Ctrl+Shift+P**.
2626

@@ -76,7 +76,6 @@ fields = [
7676
SimpleField(name="HotelId", type=SearchFieldDataType.String, key=True),
7777
SearchableField(name="HotelName", type=SearchFieldDataType.String, sortable=True),
7878
SearchableField(name="Description", type=SearchFieldDataType.String, analyzer_name="en.lucene"),
79-
SearchableField(name="Description_fr", type=SearchFieldDataType.String, analyzer_name="fr.lucene"),
8079
SearchableField(name="Category", type=SearchFieldDataType.String, facetable=True, filterable=True, sortable=True),
8180

8281
SearchableField(name="Tags", collection=True, type=SearchFieldDataType.String, facetable=True, filterable=True),
@@ -95,7 +94,7 @@ fields = [
9594
]
9695

9796
semantic_config = SemanticConfiguration(
98-
name="my-semantic-config",
97+
name="semantic-config",
9998
prioritized_fields=SemanticPrioritizedFields(
10099
title_field=SemanticField(field_name="HotelName"),
101100
keywords_fields=[SemanticField(field_name="Category")],
@@ -125,12 +124,11 @@ documents = [
125124
"@search.action": "upload",
126125
"HotelId": "1",
127126
"HotelName": "Stay-Kay City Hotel",
128-
"Description": "The hotel is ideally located on the main commercial artery of the city in the heart of New York. A few minutes away is Time's 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.",
129-
"Description_fr": "L'hôtel est idéalement situé sur la principale artère commerciale de la ville en plein cœur de New York. A quelques minutes se trouve la place du temps et le centre historique de la ville, ainsi que d'autres lieux d'intérêt qui font de New York l'une des villes les plus attractives et cosmopolites de l'Amérique.",
127+
"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.",
130128
"Category": "Boutique",
131-
"Tags": [ "pool", "air conditioning", "concierge" ],
129+
"Tags": [ "view", "air conditioning", "concierge" ],
132130
"ParkingIncluded": "false",
133-
"LastRenovationDate": "1970-01-18T00:00:00Z",
131+
"LastRenovationDate": "2022-01-18T00:00:00Z",
134132
"Rating": 3.60,
135133
"Address": {
136134
"StreetAddress": "677 5th Ave",
@@ -144,12 +142,11 @@ documents = [
144142
"@search.action": "upload",
145143
"HotelId": "2",
146144
"HotelName": "Old Century Hotel",
147-
"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.",
148-
"Description_fr": "L'hôtel est situé dans une place du XIXe siècle, qui a été agrandie et rénovée aux plus hautes normes architecturales pour créer un hôtel moderne, fonctionnel et de première classe dans lequel l'art et les éléments historiques uniques coexistent avec le confort le plus moderne.",
145+
"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.",
149146
"Category": "Boutique",
150147
"Tags": [ "pool", "free wifi", "concierge" ],
151148
"ParkingIncluded": "false",
152-
"LastRenovationDate": "1979-02-18T00:00:00Z",
149+
"LastRenovationDate": "2019-02-18T00:00:00Z",
153150
"Rating": 3.60,
154151
"Address": {
155152
"StreetAddress": "140 University Town Center Dr",
@@ -163,10 +160,9 @@ documents = [
163160
"@search.action": "upload",
164161
"HotelId": "3",
165162
"HotelName": "Gastronomic Landscape Hotel",
166-
"Description": "The Hotel stands out for its gastronomic excellence under the management of William Dough, who advises on and oversees all of the Hotel's restaurant services.",
167-
"Description_fr": "L'hôtel est situé dans une place du XIXe siècle, qui a été agrandie et rénovée aux plus hautes normes architecturales pour créer un hôtel moderne, fonctionnel et de première classe dans lequel l'art et les éléments historiques uniques coexistent avec le confort le plus moderne.",
168-
"Category": "Resort and Spa",
169-
"Tags": [ "air conditioning", "bar", "continental breakfast" ],
163+
"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.",
164+
"Category": "Suite",
165+
"Tags": [ "restaurant", "bar", "continental breakfast" ],
170166
"ParkingIncluded": "true",
171167
"LastRenovationDate": "2015-09-20T00:00:00Z",
172168
"Rating": 4.80,
@@ -182,12 +178,11 @@ documents = [
182178
"@search.action": "upload",
183179
"HotelId": "4",
184180
"HotelName": "Sublime Palace Hotel",
185-
"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 Palace is part of a lovingly restored 1800 palace.",
186-
"Description_fr": "Le Sublime Palace Hotel est situé au coeur du centre historique de sublime dans un quartier extrêmement animé et vivant, à courte distance de marche des sites et monuments de la ville et est entouré par l'extraordinaire beauté des églises, des bâtiments, des commerces et Monuments. Sublime Palace fait partie d'un Palace 1800 restauré avec amour.",
181+
"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.",
187182
"Category": "Boutique",
188-
"Tags": [ "concierge", "view", "24-hour front desk service" ],
183+
"Tags": [ "concierge", "view", "air conditioning" ],
189184
"ParkingIncluded": "true",
190-
"LastRenovationDate": "1960-02-06T00:00:00Z",
185+
"LastRenovationDate": "2020-02-06T00:00:00Z",
191186
"Rating": 4.60,
192187
"Address": {
193188
"StreetAddress": "7400 San Pedro Ave",
@@ -239,12 +234,12 @@ for result in results:
239234

240235
For comparison purposes, run a text query with BM25 relevance scoring. Full text search is invoked when you provide a query string. The response consists of ranked results, where higher scores are awarded to documents having more instances of matching terms, or more important terms.
241236

242-
In this query for *what hotel has a good restaurant on site*, Sublime Palace Hotel comes out on top because its description includes *site*. Terms that occur infrequently raise the search score of the document.
237+
In this query for *restaurant on site*, Sublime Palace Hotel comes out on top because its description includes *site*. Terms that occur infrequently raise the search score of the document.
243238

244239
```python
245240
# Run a text query (returns a BM25-scored result set)
246241
results = search_client.search(query_type='simple',
247-
search_text="what hotel has a good restaurant on site" ,
242+
search_text="restaurant on site" ,
248243
select='HotelName,HotelId,Description',
249244
include_total_count=True)
250245

@@ -262,8 +257,8 @@ It's the same query, but notice that the semantic ranker correctly identifies Ga
262257

263258
```python
264259
# Runs a semantic query (runs a BM25-ranked query and promotes the most relevant matches to the top)
265-
results = search_client.search(query_type='semantic', semantic_configuration_name='my-semantic-config',
266-
search_text="what hotel has a good restaurant on site",
260+
results = search_client.search(query_type='semantic', semantic_configuration_name='semantic-config',
261+
search_text="restaurant on site",
267262
select='HotelName,Description,Category', query_caption='extractive')
268263

269264
for result in results:
@@ -288,7 +283,7 @@ Semantic ranker can generate answers to a query string that has the characterist
288283

289284
```python
290285
# Run a semantic query that returns semantic answers
291-
results = search_client.search(query_type='semantic', semantic_configuration_name='my-semantic-config',
286+
results = search_client.search(query_type='semantic', semantic_configuration_name='semantic-config',
292287
search_text="what hotel is in a historic building",
293288
select='HotelName,Description,Category', query_caption='extractive', query_answer="extractive",)
294289

23.9 KB
Loading

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ms.custom:
1111
- devx-track-python
1212
- ignite-2023
1313
ms.topic: quickstart
14-
ms.date: 03/04/2025
14+
ms.date: 06/13/2025
1515
---
1616

1717
# Quickstart: Semantic ranking using .NET or Python

0 commit comments

Comments
 (0)