{"id":38401,"date":"2020-02-07T06:00:48","date_gmt":"2020-02-07T13:00:48","guid":{"rendered":"http:\/\/devblogs.microsoft.com\/premier-developer\/?p=38401"},"modified":"2020-02-06T12:46:10","modified_gmt":"2020-02-06T19:46:10","slug":"leverage-qna-maker-search-within-a-client-application","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/premier-developer\/leverage-qna-maker-search-within-a-client-application\/","title":{"rendered":"Leverage QnA Maker Search within a Client Application"},"content":{"rendered":"<p>In this post, App Dev Manager <a href=\"https:\/\/www.linkedin.com\/in\/patrick-king-62417b81\/\">Patrick King<\/a> explains how to integrate a QnA Maker knowledgebase into a client application.<\/p>\n<hr \/>\n<p><a href=\"https:\/\/azure.microsoft.com\/en-us\/services\/cognitive-services\/qna-maker\/\">QnA Maker<\/a> is an Azure Cognitive Service that enables you to ask questions and get answers from a knowledgebase built from your own documentation. QnA Maker also makes it very simple to add an intelligent chatbot interface to query your KB conversationally, but usage of QnA Maker is not limited to use in Chatbot apps. I recently worked on a proof-of-concept where the goal was to provide Q&amp;A style help within a Windows application, and found that it is easy to leverage QnA Maker to search a knowledgebase from almost any kind of application using its Web-based API.<\/p>\n<h2>Step 1 \u2013 Provision a QnA Maker Knowledgebase<\/h2>\n<p>The first steps are to create the QnA Maker service, load your documents into it, and create the knowledgebase. Those steps are covered in the <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/cognitive-services\/QnAMaker\/Quickstarts\/create-publish-knowledge-base\">Quickstart: Create, train, and publish your QnA Maker knowledge base<\/a>.<\/p>\n<h2>Step 2 \u2013 Collect Settings Needed by the API<\/h2>\n<p>QnA Maker exposes a runtime API that is used to submit questions and get results via the <a href=\"https:\/\/docs.microsoft.com\/en-us\/rest\/api\/cognitiveservices\/qnamakerruntime\/runtime\/generateanswer\">GenerateAnswer<\/a> API method. You need three settings to call the runtime API, which you can only retrieve once the knowledgebase has been created because some are specific to the knowledgebase.<\/p>\n<p>Once you have created the knowledge base, retrieve the settings from the QnA Maker knowledgebase settings by going to the <a href=\"https:\/\/www.qnamaker.ai\/Home\/MyServices\">QnA portal knowledgebase list<\/a> and clicking the <strong>View Code<\/strong> button for the knowledgebase you want to connect to. The settings are:<\/p>\n<ul>\n<li><strong>Runtime Endpoint<\/strong>: the URL of the Runtime API service, which is an Azure App Service Web Site that is provisioned by QnA Maker.<\/li>\n<li><strong>Runtime Key<\/strong>: the security key your code uses to access the API &amp; Knowledgebase<\/li>\n<li><strong>Knowledgebase Id<\/strong>: the unique ID of the knowledgebase you are accessing.<\/li>\n<\/ul>\n<p><img decoding=\"async\" width=\"1131\" height=\"1099\" class=\"wp-image-38402\" src=\"http:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2020\/02\/image-of-retrieving-qna-maker-knowedgebase-setting.png\" alt=\"Image of retrieving QnA Maker Knowedgebase settings via the online portal.\" srcset=\"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2020\/02\/image-of-retrieving-qna-maker-knowedgebase-setting.png 1131w, https:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2020\/02\/image-of-retrieving-qna-maker-knowedgebase-setting-300x292.png 300w, https:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2020\/02\/image-of-retrieving-qna-maker-knowedgebase-setting-1024x995.png 1024w, https:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2020\/02\/image-of-retrieving-qna-maker-knowedgebase-setting-768x746.png 768w\" sizes=\"(max-width: 1131px) 100vw, 1131px\" \/><\/p>\n<h2>Step 3 \u2013Call the QnA Maker Runtime API<\/h2>\n<p>To query your knowledgebase, submit the user question in a call to the QnA Maker Runtime API\u2019s <strong>GenerateAnswer<\/strong> method as illustrated below. The GenerateAnswer method returns question\/answer pairs that matched your question along with the source document name or URL that the answer was found in.<\/p>\n<p><img decoding=\"async\" width=\"1430\" height=\"1033\" class=\"wp-image-38403\" src=\"http:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2020\/02\/screenshot-of-c-call-to-the-qna-maker-runtime-api.png\" alt=\"Screenshot of C# call to the QnA Maker runtime API's GenerateAnswer method.\" srcset=\"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2020\/02\/screenshot-of-c-call-to-the-qna-maker-runtime-api.png 1430w, https:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2020\/02\/screenshot-of-c-call-to-the-qna-maker-runtime-api-300x217.png 300w, https:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2020\/02\/screenshot-of-c-call-to-the-qna-maker-runtime-api-1024x740.png 1024w, https:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2020\/02\/screenshot-of-c-call-to-the-qna-maker-runtime-api-768x555.png 768w\" sizes=\"(max-width: 1430px) 100vw, 1430px\" \/><\/p>\n<p>Calling the QnA Maker Runtime API requires that you have the settings we discussed in Step 2 above, and that you can make an outbound call on port 443 to the runtime endpoint. While you can make the call as a direct http request, several SDK\u2019s exist to lessen the effort.<\/p>\n<ul>\n<li>Help documentation for calling GenerateAnswer using REST calls in C# is <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/cognitive-services\/qnamaker\/tutorials\/create-publish-answer#get-an-answer\">here<\/a>,.<\/li>\n<li>An example of calling GenerateAnswer using the QnA Maker SDK in C# is <a href=\"https:\/\/github.com\/patrick-king\/CodeSamples\/blob\/master\/QnAMakerRuntimeAPI\/QnAMakerRuntimeAPI\/Providers\/QnAGateway.cs\">here<\/a><\/li>\n<\/ul>\n<p>Below is an example of iterating over the results and transferring them into a custom class. The results list is in the Answers property of the QnASearchResult:<\/p>\n<p><img decoding=\"async\" width=\"1231\" height=\"620\" class=\"wp-image-38404\" src=\"http:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2020\/02\/code-listing.png\" alt=\"Code Listing\" srcset=\"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2020\/02\/code-listing.png 1231w, https:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2020\/02\/code-listing-300x151.png 300w, https:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2020\/02\/code-listing-1024x516.png 1024w, https:\/\/devblogs.microsoft.com\/premier-developer\/wp-content\/uploads\/sites\/31\/2020\/02\/code-listing-768x387.png 768w\" sizes=\"(max-width: 1231px) 100vw, 1231px\" \/><\/p>\n<p>That\u2019s all it takes to get started using a QnA Maker knowledgebase in your own application. You can find more help and examples in the QnA Maker <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/cognitive-services\/QnAMaker\/\">documentation<\/a>.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>QnA Maker is an Azure Cognitive Service that enables you to ask questions and get answers from a knowledgebase built from your own documentation. In this post, learn how to integrate a QnA Maker knowledgebase into a client application.<\/p>\n","protected":false},"author":582,"featured_media":38406,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[80,25],"tags":[24,72,3],"class_list":["post-38401","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-net","category-azure","tag-azure","tag-cognitive-services","tag-team"],"acf":[],"blog_post_summary":"<p>QnA Maker is an Azure Cognitive Service that enables you to ask questions and get answers from a knowledgebase built from your own documentation. In this post, learn how to integrate a QnA Maker knowledgebase into a client application.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/posts\/38401","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/users\/582"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/comments?post=38401"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/posts\/38401\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/media\/38406"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/media?parent=38401"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/categories?post=38401"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/premier-developer\/wp-json\/wp\/v2\/tags?post=38401"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}