Overview

This exercise demonstrates how to create a Question Answering solution using Azure AI Language. The solution enables users to query a knowledge base of FAQs using natural language.


Steps & Configuration Details

1. Provision an Azure AI Language Resource

  • Open Azure Portal (https://portal.azure.com) and sign in.
  • Select Create a resource → Search for Language Service → Click Create.
  • Configuration Items:
    • Subscription: Your Azure subscription.
    • Resource Group: Select or create a resource group.
    • Region: Choose any available location.
    • Name: Enter a unique name.
    • Pricing Tier: F0 (Free) or S (Standard).
    • Azure Search Region: Same global region as Language resource.
    • Azure Search Pricing Tier: Free (F) or Basic (B).
    • Responsible AI Notice: Agree.

After provisioning, navigate to Keys and Endpoint in the Resource Management section.


2. Create a Question Answering Project

  • Open Language Studio (https://language.cognitive.azure.com) and sign in.
  • Select Custom Question AnsweringCreate a project.
  • Configuration Items:
    • Azure Directory: Your Azure directory.
    • Azure Subscription: Your Azure subscription.
    • Resource Type: Language.
    • Resource Name: The Azure AI Language resource created earlier.
    • Project Name: LearnFAQ
    • Description: FAQ for Microsoft Learn
    • Default Answer: "Sorry, I don't understand the question."

3. Add Sources to the Knowledge Base

  • Import FAQ Data:
    • Select Add SourceURLs.
    • Name: Learn FAQ Page
    • URL: https://docs.microsoft.com/en-us/learn/support/faq
  • Add Chit-Chat Responses:
    • Select Add SourceChitchat.
    • Choose Friendly → Click Add Chitchat.

4. Edit the Knowledge Base

  • Open Edit Knowledge Base.
  • Add a new Question-Answer Pair:
    • Source: https://docs.microsoft.com/en-us/learn/support/faq
    • Question: "What are Microsoft credentials?"
    • Answer: "Microsoft credentials enable you to validate and prove your skills with Microsoft technologies."
  • Add Alternate Questions:
    • "How can I demonstrate my Microsoft technology skills?"
  • Add Follow-up Prompts:
    • Text: "Learn more about credentials"
    • Link: [Microsoft credentials page](https://docs.microsoft.com/learn/credentials/)
    • Contextual Flow: Enabled.

5. Train and Test the Knowledge Base

  • Save changes → Click Test.
  • Submit queries:
    Hello
    What is Microsoft Learn?
    Thanks!
    Tell me about Microsoft credentials.
    
  • Verify responses and follow-up prompts.

6. Deploy the Knowledge Base

  • Open Deploy Knowledge Base → Click Deploy.
  • Retrieve the Prediction URL:
    • Project Name: LearnFAQ
    • Deployment Name: production

7. Configure Your Application

  • Clone the repository:
    git clone https://github.com/MicrosoftLearning/mslearn-ai-language
    
  • Open the folder in Visual Studio Code.
  • Install dependencies:
    • C#:
      dotnet add package Azure.AI.Language.QuestionAnswering
      
    • Python:
      pip install azure-ai-language-questionanswering
      
  • Open the configuration file:
    • C#: appsettings.json
    • Python: .env
  • Update Configuration Values:
    • Azure AI Language Endpoint
    • API Key
    • Project Name (LearnFAQ)
    • Deployment Name (production)
  • Save the configuration file.

8. Add Code to Query the Knowledge Base

  • Open the code file:
    • C#: Program.cs
    • Python: qna-app.py
  • Add references:
    • C#:
      using Azure;
      using Azure.AI.Language.QuestionAnswering;
      
    • Python:
      from azure.core.credentials import AzureKeyCredential
      from azure.ai.language.questionanswering import QuestionAnsweringClient
      
  • Create the AI Language client:
    • C#:
      AzureKeyCredential credentials = new AzureKeyCredential(aiSvcKey);
      Uri endpoint = new Uri(aiSvcEndpoint);
      QuestionAnsweringClient aiClient = new QuestionAnsweringClient(endpoint, credentials);
      
    • Python:
      credential = AzureKeyCredential(ai_key)
      ai_client = QuestionAnsweringClient(endpoint=ai_endpoint, credential=credential)
      
  • Submit a question:
    • C#:
      string user_question = "";
      while (true) {
          Console.Write("Question: ");
          user_question = Console.ReadLine();
          if (user_question.ToLower() == "quit") break;
          QuestionAnsweringProject project = new QuestionAnsweringProject(projectName, deploymentName);
          Response<AnswersResult> response = aiClient.GetAnswers(user_question, project);
          foreach (KnowledgeBaseAnswer answer in response.Value.Answers) {
              Console.WriteLine(answer.Answer);
              Console.WriteLine($"Confidence: {answer.Confidence:P2}");
              Console.WriteLine($"Source: {answer.Source}");
              Console.WriteLine();
          }
      }
      
    • Python:
      user_question = ''
      while True:
          user_question = input('\nQuestion:\n')
          if user_question.lower() == "quit":
              break
          response = ai_client.get_answers(question=user_question, project_name=ai_project_name, deployment_name=ai_deployment_name)
          for candidate in response.answers:
              print(candidate.answer)
              print("Confidence: {}".format(candidate.confidence))
              print("Source: {}".format(candidate.source))
      

9. Run Your Application

  • C#:
    dotnet run
    
  • Python:
    python qna-app.py
    
  • Example prompt:
    What is a learning path?
    
  • The response should display the answer, confidence score, and source.

10. Clean Up

  • Delete Azure resources to avoid unnecessary costs:

This summary captures the essential steps while highlighting all configuration items and code references required for creating a Question Answering solution using Azure AI Language.

Related Posts