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
> You can [download the source code](https://github.com/Azure-Samples/azure-search-dotnet-samples/tree/main/quickstart-semantic-search/SemanticSearchQuickstart) to start with a finished project or follow these steps to create your own.
15
15
16
16
## Set up the client
@@ -31,6 +31,10 @@ We recommend [Visual Studio](https://visualstudio.microsoft.com/vs/community/) f
31
31
32
32
1. Select **Install** to add the assembly to your project and solution.
33
33
34
+
### Sign in to Azure
35
+
36
+
If you signed in to the [Azure portal](https://portal.azure.com), you're signed into Azure. If you aren't sure, use the Azure CLI or Azure PowerShell to log in: `az login` or `az connect`. If you have multiple tenants and subscriptions, see [Quickstart: Connect without keys](../../search-get-started-rbac.md) for help on how to connect.
37
+
34
38
### Create a search client
35
39
36
40
1. In *Program.cs*, add the following `using` directives.
@@ -68,15 +72,22 @@ We recommend [Visual Studio](https://visualstudio.microsoft.com/vs/community/) f
68
72
69
73
## Update and query the index
70
74
71
-
Inthissection, youupdateasearchindexandsendaquerythatinvokessemanticranking. VisualStudioCodedisplaystheresponseafteryouruneachcell. Formoreinformationabouteachstep, see [Explainingthecode](#explaining-the-code).
75
+
Inthissection, youupdateasearchindexandsendaquerythatinvokessemanticranking. Thecoderunsalloperationsinsequence, fromindexupdatesthroughaseriesofqueries. Formoreinformationabouteachstep, see [Explainingthecode](#explaining-the-code). Thecodeperformstwotypesoftasks:
### Add a semantic configuration to the hotels-sample-index
74
81
82
+
```csharp
75
83
CODEGOESHERE
84
+
```
76
85
77
-
### Add semantic query parameters to a query
86
+
### Add semantic parameters to a query
78
87
88
+
```csharp
79
89
CODEGOESHERE
90
+
```
80
91
81
92
### Run the program
82
93
@@ -86,18 +97,45 @@ Output includes messages from [Console.WriteLine](/dotnet/api/system.console.wri
86
97
87
98
## Explaining the code
88
99
89
-
Add `SemanticConfiguration` toasearchindexdefinition. Ifyou're updating an existing index, this modification doesn'trequireareindexingbecausethestructureofyourdocumentsisunchanged.
100
+
This section explains the updates to the index and queries. If you're updating an existing index, the additional of a semantic configuration doesn't require a reindexing because the structure of your documents is unchanged.
90
101
91
-
+ [Update an index with a semantic configuration](#update-an-index-with-a-semantic-configuration)
To update the index, provide the existing schema in its entirety, plus the new `SemanticConfiguration` section. We recommend retrieving the index schema from the search service to ensure you're working with the current version. If the original and updated schemas differ in field definitions or other constructs, the update fails.
95
105
96
-
TBD
106
+
This example highlights the C# code that adds a semantic configuration to an index.
107
+
108
+
```csharp
109
+
CODEGOESHERE
110
+
```
97
111
98
-
### Query the index using semantic parameters
112
+
### Query parameters
99
113
100
-
Here's a query that invokes semantic ranker, with search options for specifying parameters:
114
+
Required semantic parameters include `query_type` and `semantic_configuration_name`. Here is an example of a basic semantic query using the minimum parameters.
115
+
116
+
```csharp
117
+
Console.WriteLine("Example of a semantic query.");
response=srchclient.Search<Hotel>("walking distance to live music", options);
133
+
WriteDocuments(response);
134
+
```
135
+
136
+
### Return captions
137
+
138
+
Optionally, you can add captions to extract portions of the text and apply hit highlighting to the important terms and phrases. This query adds captions.
101
139
102
140
```csharp
103
141
Console.WriteLine("Example of a semantic query.");
response=srchclient.Search<Hotel>("restaurant on site", options);
157
+
response=srchclient.Search<Hotel>("walking distance to live music", options);
120
158
WriteDocuments(response);
121
159
```
122
160
123
-
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:
161
+
### Return semantic answers
124
162
125
-
:::image type="content" source="../../media/quickstart-semantic/bm25-ranking.png" alt-text="Screenshot showing matches ranked by BM25.":::
163
+
In this final query, return semantic answers.
126
164
127
-
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.
128
-
129
-
:::image type="content" source="../../media/quickstart-semantic/semantic-ranking.png" alt-text="Screenshot showing matches ranked based on semantic ranking.":::
165
+
Semantic ranker can produce an answer to a query string that has the characteristics of a question. The generated answer is extracted verbatim from your content so it won't include composed content like what you might expect from a chat completion model. If the semantic answer isn't useful for your scenario, you can omit `semantic_answers` from your code.
130
166
167
+
To get a semantic answer, the question and answer must be closely aligned, and the model must find content that clearly answers the question. If potential answers fail to meet a confidence threshold, the model doesn't return an answer. For demonstration purposes, the question in this example is designed to get a response so that you can see the syntax.
> You can [download a finished notebook](https://github.com/Azure-Samples/azure-search-python-samples/tree/main/Quickstart-Semantic-Search) to start with a finished project or follow these steps to create your own.
15
15
16
16
## Set up the client
@@ -166,7 +166,7 @@ for result in results:
166
166
167
167
## Explaining the code
168
168
169
-
This section explains the updates to the index and queries. If you're updating an existing index, this modification doesn't require a reindexing because the structure of your documents is unchanged.
169
+
This section explains the updates to the index and queries. If you're updating an existing index, the additional of a semantic configuration doesn't require a reindexing because the structure of your documents is unchanged.
Copy file name to clipboardExpand all lines: articles/search/includes/quickstarts/semantic-ranker-rest.md
+45-7Lines changed: 45 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,21 +41,59 @@ We recommend [Visual Studio Code](https://code.visualstudio.com/download) with a
41
41
42
42
In this section, you make REST API calls to update a search index to include a semantic configuration, and then 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
43
44
-
```json
44
+
+[Add a semantic configuration to an index](#add-a-semantic-configuration-to-the-hotels-sample-index)
45
+
+[Add semantic parameters to a query](#add-semantic-parameters-to-a-query)
46
+
47
+
### Add a semantic configuration to the hotels-sample-index
48
+
49
+
```https
50
+
TBD
51
+
```
52
+
53
+
### Add semantic parameters to a query
54
+
55
+
```https
45
56
TBD
46
57
```
47
58
48
59
## Explaining the code
49
60
50
-
This section explains the REST API calls that you made to:
61
+
This section explains the updates to the index and queries. If you're updating an existing index, the additional of a semantic configuration doesn't require a reindexing because the structure of your documents is unchanged.
62
+
63
+
### Index updates
64
+
65
+
To update the index, provide the existing schema in its entirety, plus the new `SemanticConfiguration` section. We recommend retrieving the index schema from the search service to ensure you're working with the current version. If the original and updated schemas differ in field definitions or other constructs, the update fails.
66
+
67
+
This example shows the JSON that adds a semantic configuration to an index.
68
+
69
+
```json
70
+
TBD
71
+
```
72
+
73
+
### Query parameters
51
74
52
-
+[Update an index with a semantic configuration](#add-a-semantic-configuration-to-the-index)
53
-
+[Query the index using semantic parameters](#add-semantic-ranking-to-queries)
75
+
Required semantic parameters include `query_type` and `semantic_configuration_name`. Here is an example of a basic semantic query using the minimum parameters.
54
76
55
-
### Update an index with a semantic configuration
77
+
```json
78
+
TBD
79
+
```
56
80
81
+
### Return captions
82
+
83
+
Optionally, you can add captions to extract portions of the text and apply hit highlighting to the important terms and phrases. This query adds captions.
84
+
85
+
```json
57
86
TBD
87
+
```
88
+
89
+
### Return semantic answers
90
+
91
+
In this final query, return semantic answers.
92
+
93
+
Semantic ranker can produce an answer to a query string that has the characteristics of a question. The generated answer is extracted verbatim from your content so it won't include composed content like what you might expect from a chat completion model. If the semantic answer isn't useful for your scenario, you can omit `semantic_answers` from your code.
58
94
59
-
### Query the index using semantic parameters
95
+
To get a semantic answer, the question and answer must be closely aligned, and the model must find content that clearly answers the question. If potential answers fail to meet a confidence threshold, the model doesn't return an answer. For demonstration purposes, the question in this example is designed to get a response so that you can see the syntax.
0 commit comments