Skip to content

Commit 480bb13

Browse files
authored
Add simple overloads for QueryKnowledgeBase (Azure#24181)
* Add simple overloads for QueryKnowledgeBase Resolves Azure#24172. Also regenerated with transform swagger as needed for Azure#24067, but that is waiting on the final expected swagger changes. * Rebase on main to fix build breaks * Resolve PR feedback
1 parent df6d6eb commit 480bb13

File tree

47 files changed

+562
-397
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+562
-397
lines changed

sdk/cognitivelanguage/Azure.AI.Language.Conversations/README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,10 @@ The following examples show common scenarios using the `client` [created above](
7979
The only input required to a ask a question using an existing knowledge base is just the question itself:
8080

8181
```C# Snippet:QuestionAnsweringClient_QueryKnowledgeBase
82-
QueryKnowledgeBaseOptions options = new QueryKnowledgeBaseOptions("How long should my Surface battery last?");
83-
84-
Response<KnowledgeBaseAnswers> response = client.QueryKnowledgeBase("FAQ", options);
82+
string projectName = "FAQ";
83+
string deploymentName = "prod";
84+
QueryKnowledgeBaseOptions options = new QueryKnowledgeBaseOptions(projectName, deploymentName, "How long should my Surface battery last?");
85+
Response<KnowledgeBaseAnswers> response = client.QueryKnowledgeBase(options);
8586

8687
foreach (KnowledgeBaseAnswer answer in response.Value.Answers)
8788
{
@@ -98,14 +99,16 @@ You can set additional properties on `QuestionAnsweringClientOptions` to limit t
9899
If your knowledge base is configured for [chit-chat][questionanswering_docs_chat], you can ask a follow-up question provided the previous question-answering ID and, optionally, the exact question the user asked:
99100

100101
```C# Snippet:QuestionAnsweringClient_Chat
102+
string projectName = "FAQ";
103+
string deploymentName = "prod";
101104
// Answers are ordered by their ConfidenceScore so assume the user choose the first answer below:
102105
KnowledgeBaseAnswer previousAnswer = answers.Answers.First();
103-
QueryKnowledgeBaseOptions options = new QueryKnowledgeBaseOptions("How long should charging take?")
106+
QueryKnowledgeBaseOptions options = new QueryKnowledgeBaseOptions(projectName, deploymentName, "How long should charging take?")
104107
{
105108
Context = new KnowledgeBaseAnswerRequestContext(previousAnswer.Id.Value)
106109
};
107110

108-
Response<KnowledgeBaseAnswers> response = client.QueryKnowledgeBase("FAQ", options);
111+
Response<KnowledgeBaseAnswers> response = client.QueryKnowledgeBase(options);
109112

110113
foreach (KnowledgeBaseAnswer answer in response.Value.Answers)
111114
{

sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44

55
### Features Added
66

7+
- Added support for API version 2021-07-15-preview.
8+
79
### Breaking Changes
810

11+
- Made `projectName` and `deploymentName` parameters required for `QuestionAnsweringClient` methods.
12+
- Moved `QueryKnowledgeBaseOptions`, `QueryTextOptions`, and `TextRecord` to `Azure.AI.Language.QuestionAnswering` namespace.
13+
914
### Bugs Fixed
1015

1116
### Other Changes

sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering/README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,10 @@ The following examples show common scenarios using the `client` [created above](
7979
The only input required to a ask a question using an existing knowledge base is just the question itself:
8080

8181
```C# Snippet:QuestionAnsweringClient_QueryKnowledgeBase
82-
QueryKnowledgeBaseOptions options = new QueryKnowledgeBaseOptions("How long should my Surface battery last?");
83-
84-
Response<KnowledgeBaseAnswers> response = client.QueryKnowledgeBase("FAQ", options);
82+
string projectName = "FAQ";
83+
string deploymentName = "prod";
84+
QueryKnowledgeBaseOptions options = new QueryKnowledgeBaseOptions(projectName, deploymentName, "How long should my Surface battery last?");
85+
Response<KnowledgeBaseAnswers> response = client.QueryKnowledgeBase(options);
8586

8687
foreach (KnowledgeBaseAnswer answer in response.Value.Answers)
8788
{
@@ -98,14 +99,16 @@ You can set additional properties on `QuestionAnsweringClientOptions` to limit t
9899
If your knowledge base is configured for [chit-chat][questionanswering_docs_chat], you can ask a follow-up question provided the previous question-answering ID and, optionally, the exact question the user asked:
99100

100101
```C# Snippet:QuestionAnsweringClient_Chat
102+
string projectName = "FAQ";
103+
string deploymentName = "prod";
101104
// Answers are ordered by their ConfidenceScore so assume the user choose the first answer below:
102105
KnowledgeBaseAnswer previousAnswer = answers.Answers.First();
103-
QueryKnowledgeBaseOptions options = new QueryKnowledgeBaseOptions("How long should charging take?")
106+
QueryKnowledgeBaseOptions options = new QueryKnowledgeBaseOptions(projectName, deploymentName, "How long should charging take?")
104107
{
105108
Context = new KnowledgeBaseAnswerRequestContext(previousAnswer.Id.Value)
106109
};
107110

108-
Response<KnowledgeBaseAnswers> response = client.QueryKnowledgeBase("FAQ", options);
111+
Response<KnowledgeBaseAnswers> response = client.QueryKnowledgeBase(options);
109112

110113
foreach (KnowledgeBaseAnswer answer in response.Value.Answers)
111114
{
@@ -126,7 +129,7 @@ For example, if you submit a question to a non-existant knowledge base, a `400`
126129
```C# Snippet:QuestionAnsweringClient_BadRequest
127130
try
128131
{
129-
Response<KnowledgeBaseAnswers> response = client.QueryKnowledgeBase("invalid-knowledgebase", options);
132+
Response<KnowledgeBaseAnswers> response = client.QueryKnowledgeBase("invalid-knowledgebase", "test", "Does this knowledge base exist?");
130133
}
131134
catch (RequestFailedException ex)
132135
{

sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering/api/Azure.AI.Language.QuestionAnswering.netstandard2.0.cs

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,62 @@
11
namespace Azure.AI.Language.QuestionAnswering
22
{
3+
public partial class QueryKnowledgeBaseOptions
4+
{
5+
public QueryKnowledgeBaseOptions(string projectName, string deploymentName, int qnaId) { }
6+
public QueryKnowledgeBaseOptions(string projectName, string deploymentName, string question) { }
7+
public Azure.AI.Language.QuestionAnswering.Models.AnswerSpanRequest AnswerSpanRequest { get { throw null; } set { } }
8+
public double? ConfidenceScoreThreshold { get { throw null; } set { } }
9+
public Azure.AI.Language.QuestionAnswering.Models.KnowledgeBaseAnswerRequestContext Context { get { throw null; } set { } }
10+
public string DeploymentName { get { throw null; } }
11+
public bool? IncludeUnstructuredSources { get { throw null; } set { } }
12+
public string ProjectName { get { throw null; } }
13+
public int? QnaId { get { throw null; } }
14+
public string Question { get { throw null; } }
15+
public Azure.AI.Language.QuestionAnswering.Models.RankerType? RankerType { get { throw null; } set { } }
16+
public Azure.AI.Language.QuestionAnswering.Models.StrictFilters StrictFilters { get { throw null; } set { } }
17+
public int? Top { get { throw null; } set { } }
18+
public string UserId { get { throw null; } set { } }
19+
}
20+
public partial class QueryTextOptions
21+
{
22+
public QueryTextOptions(string question, System.Collections.Generic.IEnumerable<Azure.AI.Language.QuestionAnswering.TextRecord> records) { }
23+
public string Language { get { throw null; } set { } }
24+
public string Question { get { throw null; } }
25+
public System.Collections.Generic.IList<Azure.AI.Language.QuestionAnswering.TextRecord> Records { get { throw null; } }
26+
public Azure.AI.Language.QuestionAnswering.Models.StringIndexType? StringIndexType { get { throw null; } set { } }
27+
}
328
public partial class QuestionAnsweringClient
429
{
530
protected QuestionAnsweringClient() { }
631
public QuestionAnsweringClient(System.Uri endpoint, Azure.AzureKeyCredential credential) { }
732
public QuestionAnsweringClient(System.Uri endpoint, Azure.AzureKeyCredential credential, Azure.AI.Language.QuestionAnswering.QuestionAnsweringClientOptions options) { }
833
public virtual System.Uri Endpoint { get { throw null; } }
9-
public virtual Azure.Response<Azure.AI.Language.QuestionAnswering.Models.KnowledgeBaseAnswers> QueryKnowledgeBase(string projectName, Azure.AI.Language.QuestionAnswering.Models.QueryKnowledgeBaseOptions options, string deploymentName = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
10-
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.AI.Language.QuestionAnswering.Models.KnowledgeBaseAnswers>> QueryKnowledgeBaseAsync(string projectName, Azure.AI.Language.QuestionAnswering.Models.QueryKnowledgeBaseOptions options, string deploymentName = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
11-
public virtual Azure.Response<Azure.AI.Language.QuestionAnswering.Models.TextAnswers> QueryText(Azure.AI.Language.QuestionAnswering.Models.QueryTextOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
12-
public virtual Azure.Response<Azure.AI.Language.QuestionAnswering.Models.TextAnswers> QueryText(string question, System.Collections.Generic.IEnumerable<Azure.AI.Language.QuestionAnswering.Models.TextRecord> records, string language = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
34+
public virtual Azure.Response<Azure.AI.Language.QuestionAnswering.Models.KnowledgeBaseAnswers> QueryKnowledgeBase(Azure.AI.Language.QuestionAnswering.QueryKnowledgeBaseOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
35+
public virtual Azure.Response<Azure.AI.Language.QuestionAnswering.Models.KnowledgeBaseAnswers> QueryKnowledgeBase(string projectName, string deploymentName, string question, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
36+
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.AI.Language.QuestionAnswering.Models.KnowledgeBaseAnswers>> QueryKnowledgeBaseAsync(Azure.AI.Language.QuestionAnswering.QueryKnowledgeBaseOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
37+
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.AI.Language.QuestionAnswering.Models.KnowledgeBaseAnswers>> QueryKnowledgeBaseAsync(string projectName, string deploymentName, string question, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
38+
public virtual Azure.Response<Azure.AI.Language.QuestionAnswering.Models.TextAnswers> QueryText(Azure.AI.Language.QuestionAnswering.QueryTextOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
39+
public virtual Azure.Response<Azure.AI.Language.QuestionAnswering.Models.TextAnswers> QueryText(string question, System.Collections.Generic.IEnumerable<Azure.AI.Language.QuestionAnswering.TextRecord> records, string language = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
1340
public virtual Azure.Response<Azure.AI.Language.QuestionAnswering.Models.TextAnswers> QueryText(string question, System.Collections.Generic.IEnumerable<string> records, string language = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
14-
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.AI.Language.QuestionAnswering.Models.TextAnswers>> QueryTextAsync(Azure.AI.Language.QuestionAnswering.Models.QueryTextOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
15-
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.AI.Language.QuestionAnswering.Models.TextAnswers>> QueryTextAsync(string question, System.Collections.Generic.IEnumerable<Azure.AI.Language.QuestionAnswering.Models.TextRecord> records, string language = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
41+
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.AI.Language.QuestionAnswering.Models.TextAnswers>> QueryTextAsync(Azure.AI.Language.QuestionAnswering.QueryTextOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
42+
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.AI.Language.QuestionAnswering.Models.TextAnswers>> QueryTextAsync(string question, System.Collections.Generic.IEnumerable<Azure.AI.Language.QuestionAnswering.TextRecord> records, string language = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
1643
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.AI.Language.QuestionAnswering.Models.TextAnswers>> QueryTextAsync(string question, System.Collections.Generic.IEnumerable<string> records, string language = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
1744
}
1845
public partial class QuestionAnsweringClientOptions : Azure.Core.ClientOptions
1946
{
20-
public QuestionAnsweringClientOptions(Azure.AI.Language.QuestionAnswering.QuestionAnsweringClientOptions.ServiceVersion version = Azure.AI.Language.QuestionAnswering.QuestionAnsweringClientOptions.ServiceVersion.V2021_05_01_preview) { }
47+
public QuestionAnsweringClientOptions(Azure.AI.Language.QuestionAnswering.QuestionAnsweringClientOptions.ServiceVersion version = Azure.AI.Language.QuestionAnswering.QuestionAnsweringClientOptions.ServiceVersion.V2021_07_15_Preview) { }
2148
public enum ServiceVersion
2249
{
2350
V2021_05_01_preview = 1,
51+
V2021_07_15_Preview = 2,
2452
}
2553
}
54+
public partial class TextRecord
55+
{
56+
public TextRecord(string id, string text) { }
57+
public string Id { get { throw null; } }
58+
public string Text { get { throw null; } }
59+
}
2660
}
2761
namespace Azure.AI.Language.QuestionAnswering.Models
2862
{
@@ -101,29 +135,6 @@ public MetadataFilter() { }
101135
public Azure.AI.Language.QuestionAnswering.Models.CompoundOperationKind? CompoundOperation { get { throw null; } set { } }
102136
public System.Collections.Generic.IDictionary<string, string> Metadata { get { throw null; } }
103137
}
104-
public partial class QueryKnowledgeBaseOptions
105-
{
106-
public QueryKnowledgeBaseOptions(int qnaId) { }
107-
public QueryKnowledgeBaseOptions(string question) { }
108-
public Azure.AI.Language.QuestionAnswering.Models.AnswerSpanRequest AnswerSpanRequest { get { throw null; } set { } }
109-
public double? ConfidenceScoreThreshold { get { throw null; } set { } }
110-
public Azure.AI.Language.QuestionAnswering.Models.KnowledgeBaseAnswerRequestContext Context { get { throw null; } set { } }
111-
public bool? IncludeUnstructuredSources { get { throw null; } set { } }
112-
public int? QnaId { get { throw null; } }
113-
public string Question { get { throw null; } }
114-
public Azure.AI.Language.QuestionAnswering.Models.RankerType? RankerType { get { throw null; } set { } }
115-
public Azure.AI.Language.QuestionAnswering.Models.StrictFilters StrictFilters { get { throw null; } set { } }
116-
public int? Top { get { throw null; } set { } }
117-
public string UserId { get { throw null; } set { } }
118-
}
119-
public partial class QueryTextOptions
120-
{
121-
public QueryTextOptions(string question, System.Collections.Generic.IEnumerable<Azure.AI.Language.QuestionAnswering.Models.TextRecord> records) { }
122-
public string Language { get { throw null; } set { } }
123-
public string Question { get { throw null; } }
124-
public System.Collections.Generic.IList<Azure.AI.Language.QuestionAnswering.Models.TextRecord> Records { get { throw null; } }
125-
public Azure.AI.Language.QuestionAnswering.Models.StringIndexType? StringIndexType { get { throw null; } set { } }
126-
}
127138
public static partial class QuestionAnsweringModelFactory
128139
{
129140
public static Azure.AI.Language.QuestionAnswering.Models.AnswerSpan AnswerSpan(string text = null, double? confidenceScore = default(double?), int? offset = default(int?), int? length = default(int?)) { throw null; }
@@ -193,12 +204,6 @@ public partial class TextAnswers
193204
internal TextAnswers() { }
194205
public System.Collections.Generic.IReadOnlyList<Azure.AI.Language.QuestionAnswering.Models.TextAnswer> Answers { get { throw null; } }
195206
}
196-
public partial class TextRecord
197-
{
198-
public TextRecord(string id, string text) { }
199-
public string Id { get { throw null; } }
200-
public string Text { get { throw null; } }
201-
}
202207
}
203208
namespace Microsoft.Extensions.Azure
204209
{

sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering/samples/Sample1_QueryKnowledgeBase.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ Once you have created a client, you can call synchronous or asynchronous methods
1616
## Synchronous
1717

1818
```C# Snippet:QuestionAnsweringClient_QueryKnowledgeBase
19-
QueryKnowledgeBaseOptions options = new QueryKnowledgeBaseOptions("How long should my Surface battery last?");
20-
21-
Response<KnowledgeBaseAnswers> response = client.QueryKnowledgeBase("FAQ", options);
19+
string projectName = "FAQ";
20+
string deploymentName = "prod";
21+
QueryKnowledgeBaseOptions options = new QueryKnowledgeBaseOptions(projectName, deploymentName, "How long should my Surface battery last?");
22+
Response<KnowledgeBaseAnswers> response = client.QueryKnowledgeBase(options);
2223

2324
foreach (KnowledgeBaseAnswer answer in response.Value.Answers)
2425
{
@@ -32,9 +33,9 @@ foreach (KnowledgeBaseAnswer answer in response.Value.Answers)
3233

3334
```C# Snippet:QuestionAnsweringClient_QueryKnowledgeBaseAsync
3435
string projectName = "FAQ";
35-
QueryKnowledgeBaseOptions options = new QueryKnowledgeBaseOptions("How long should my Surface battery last?");
36-
37-
Response<KnowledgeBaseAnswers> response = await client.QueryKnowledgeBaseAsync(projectName, options);
36+
string deploymentName = "prod";
37+
QueryKnowledgeBaseOptions options = new QueryKnowledgeBaseOptions(projectName, deploymentName, "How long should my Surface battery last?");
38+
Response<KnowledgeBaseAnswers> response = await client.QueryKnowledgeBaseAsync(options);
3839

3940
foreach (KnowledgeBaseAnswer answer in response.Value.Answers)
4041
{

sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering/samples/Sample2_Chat.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ Once you have created a client and have a previous question-answer result, you c
1616
## Synchronous
1717

1818
```C# Snippet:QuestionAnsweringClient_Chat
19+
string projectName = "FAQ";
20+
string deploymentName = "prod";
1921
// Answers are ordered by their ConfidenceScore so assume the user choose the first answer below:
2022
KnowledgeBaseAnswer previousAnswer = answers.Answers.First();
21-
QueryKnowledgeBaseOptions options = new QueryKnowledgeBaseOptions("How long should charging take?")
23+
QueryKnowledgeBaseOptions options = new QueryKnowledgeBaseOptions(projectName, deploymentName, "How long should charging take?")
2224
{
2325
Context = new KnowledgeBaseAnswerRequestContext(previousAnswer.Id.Value)
2426
};
2527

26-
Response<KnowledgeBaseAnswers> response = client.QueryKnowledgeBase("FAQ", options);
28+
Response<KnowledgeBaseAnswers> response = client.QueryKnowledgeBase(options);
2729

2830
foreach (KnowledgeBaseAnswer answer in response.Value.Answers)
2931
{
@@ -36,14 +38,16 @@ foreach (KnowledgeBaseAnswer answer in response.Value.Answers)
3638
## Asynchronous
3739

3840
```C# Snippet:QuestionAnsweringClient_ChatAsync
41+
string projectName = "FAQ";
42+
string deploymentName = "prod";
3943
// Answers are ordered by their ConfidenceScore so assume the user choose the first answer below:
4044
KnowledgeBaseAnswer previousAnswer = answers.Answers.First();
41-
QueryKnowledgeBaseOptions options = new QueryKnowledgeBaseOptions("How long should charging take?")
45+
QueryKnowledgeBaseOptions options = new QueryKnowledgeBaseOptions(projectName, deploymentName, "How long should charging take?")
4246
{
4347
Context = new KnowledgeBaseAnswerRequestContext(previousAnswer.Id.Value)
4448
};
4549

46-
Response<KnowledgeBaseAnswers> response = await client.QueryKnowledgeBaseAsync("FAQ", options);
50+
Response<KnowledgeBaseAnswers> response = await client.QueryKnowledgeBaseAsync(options);
4751

4852
foreach (KnowledgeBaseAnswer answer in response.Value.Answers)
4953
{

sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering/src/Generated/Models/QueryKnowledgeBaseOptions.Serialization.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering/src/Generated/Models/QueryKnowledgeBaseOptions.cs

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/cognitivelanguage/Azure.AI.Language.QuestionAnswering/src/Generated/Models/QueryTextOptions.Serialization.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)