Share via


Azure Cognitive Language Services Question Answering Authoring client library for .NET - version 1.0.0-beta.1

The Question Answering Authoring client library lets you manage Question Answering projects: create and configure projects, add and update knowledge sources, add QnA pairs, deploy a project, and delete it. Use this library to automate lifecycle management while using the runtime (Inference) library to ask questions.

Source code | Package (NuGet) | API reference | Samples | Product documentation | REST API docs

If you only need to query deployed projects, install the runtime package (Azure.AI.Language.QuestionAnswering.Inference).

If you need to create/update/deploy projects (authoring), use the authoring preview package (Azure.AI.Language.QuestionAnswering.Authoring).

Getting started

Service API versions:

  • Stable (no --prerelease): 2022-10-13
  • Preview (--prerelease): 2025-05-15-preview

Install the package

Stable (GA) - installs latest released (non-preview) version:

dotnet add package Azure.AI.Language.QuestionAnswering

Preview (opt into new features and 2025-05-15-preview service version):

dotnet add package Azure.AI.Language.QuestionAnswering.Authoring --prerelease
dotnet add package Azure.AI.Language.QuestionAnswering.Inference --prerelease

Install without --prerelease for stable; add --prerelease to opt into preview features and newer service version.

for

Prerequisites

  • An Azure subscription
  • A Cognitive Services Language resource with Question Answering enabled
  • Endpoint (e.g. https://<resource>.cognitiveservices.azure.com/)
  • API key OR an Azure AD identity (role: “Cognitive Services Language Contributor” or appropriate RBAC)

Authenticate the client

You can use an API key or Azure Active Directory (AAD) credentials (including Managed Identity).

Namespaces

Add the authoring namespace:

using Azure.AI.Language.QuestionAnswering.Authoring;

Create a QuestionAnsweringAuthoringClient (API key)

Uri endpoint = new Uri("https://myaccount.cognitiveservices.azure.com/");
AzureKeyCredential credential = new AzureKeyCredential("{api-key}");

QuestionAnsweringAuthoringClient client = new QuestionAnsweringAuthoringClient(endpoint, credential);

Create a QuestionAnsweringAuthoringClient (Managed Identity / DefaultAzureCredential)

Uri endpoint = new Uri("https://myaccount.cognitiveservices.azure.com/");
TokenCredential credential = new DefaultAzureCredential();

QuestionAnsweringAuthoringClient client = new QuestionAnsweringAuthoringClient(endpoint, credential, new QuestionAnsweringAuthoringClientOptions());

Regional endpoints may require a custom domain configuration to use AAD / Managed Identity. See official authentication docs for details.

Key concepts

Concept Description
Project A container for language configuration, knowledge sources, QnA pairs, and deployments.
Deployment A named, queryable snapshot of a project used by runtime clients.
Knowledge Source A URL / file / structured or unstructured content ingested into the project.
QnA Pair A question with one or more answers that can be updated incrementally.
Long‑running Operations Creating deployments, updating sources, updating QnAs, and export operations return Operation<T>.

Thread safety

Client instances are thread-safe and intended to be reused.

Additional concepts

Client options | Accessing the response | Long-running operations | Handling failures | Diagnostics | Mocking | Client lifetime

Examples

Create a project

// Set project name and request content parameters
string newProjectName = "{ProjectName}";
RequestContent creationRequestContent = RequestContent.Create(
    new {
        description = "This is the description for a test project",
        language = "en",
        multilingualResource = false,
        settings = new {
            defaultAnswer = "No answer found for your question."
            }
        }
    );

Response creationResponse = client.CreateProject(newProjectName, creationRequestContent);

// Projects can be retrieved as follows
Pageable<QuestionAnsweringProject> projects = client.GetProjects();

Console.WriteLine("Projects: ");
foreach (QuestionAnsweringProject project in projects)
{
    Console.WriteLine(project);
}

Deploy a project

// Set deployment name and start operation
string newDeploymentName = "{DeploymentName}";

Operation deploymentOperation = client.DeployProject(WaitUntil.Completed, newProjectName, newDeploymentName);

// Deployments can be retrieved as follows
Pageable<ProjectDeployment> deployments = client.GetDeployments(newProjectName);
Console.WriteLine("Deployments: ");
foreach (ProjectDeployment deployment in deployments)
{
    Console.WriteLine(deployment);
}

Add (or update) knowledge sources

// Set request content parameters for updating our new project's sources
string sourceUri = "{KnowledgeSourceUri}";
RequestContent updateSourcesRequestContent = RequestContent.Create(
    new[] {
        new {
                op = "add",
                value = new
                {
                    displayName = "MicrosoftFAQ",
                    source = sourceUri,
                    sourceUri = sourceUri,
                    sourceKind = "url",
                    contentStructureKind = "unstructured",
                    refresh = false
                }
            }
    });

Operation updateSourcesOperation = client.UpdateSources(WaitUntil.Completed, newProjectName, updateSourcesRequestContent);

// Knowledge Sources can be retrieved as follows
BinaryData sources = updateSourcesOperation.GetRawResponse().Content;

Console.WriteLine($"Sources: {sources}");

Additional operations (update QnAs, export, delete) follow similar patterns using Operation<T> or direct Response objects.

Type forwarding & migration

As of the 2.0.0 preview split (use --prerelease to opt in):

  • The main package (Azure.AI.Language.QuestionAnswering) focuses on authoring but continues to expose inference types via type forwarding.
  • The runtime implementation is provided by Azure.AI.Language.QuestionAnswering.Inference.
  • Existing source code using inference or authoring APIs should compile without change after upgrading, because public inference types remain in the reference surface (source + binary compatibility).
  • If you only need runtime querying, you can depend solely on the inference package for a reduced dependency surface.
  • Future previews may de-emphasize inference APIs in the main package—follow the CHANGELOG for updates.

No code changes are required for upgrading typical projects. Use dotnet add package <package> for stable; add --prerelease only if you need preview features or the newer service version.

Troubleshooting

Issue Possible Cause Mitigation
401/403 Invalid key or missing AAD role Regenerate key or assign proper role
404 Project or deployment name incorrect Verify spelling and casing
409 Concurrent modification conflict Introduce retry / sequence operations
Operation timeout Long-running network or service delay Poll with backoff; inspect diagnostics / activity IDs

Enable diagnostics logging:

using Azure.Core.Diagnostics;
using AzureEventSourceListener listener = AzureEventSourceListener.CreateConsoleLogger();

Next steps

  • Export a project and store the snapshot in version control.
  • Automate deployment after source updates.
  • Integrate with CI/CD to promote projects across environments.

Contributing

See the root repository contributing guide for how to build, test, and submit changes.