question

NShini-4293 avatar image
0 Votes"
NShini-4293 asked romungi-MSFT answered

How can I pre-filter answers from user input?

Hi,
I am currently developing a chatbot using QnA Maker. I am using the multi-turn feature by uploading an excel file with all the required questions, answers and other necessary details.

My premise is as follows:

  • I have a list of tools, their descriptions and in which category the tools fall into.

  • The bot is supposed to guide the user towards a tool according to the description they give.

  • The description of the tool are the questions and the tool name is the answer in the KB.

  • The tools are divided into different categories. For instance, say we have Category 1, Category 2 & Category 3 and Tool A, Tool B, Tool C & Tool D.

  • Category 1 contains Tool A & Tool C

  • Category 2 contains Tool B & Tool C

  • Category 3 contains Tool A, Tool C & Tool D

  • The user is first presented with a choice of categories in the form of buttons and I want to be able to pre filter the answers accordingly.

  • Therefore, if a user chooses Category 1, the bot is supposed to limit the search to only Tools A & C

Is there a way to achieve this in QnA Maker or maybe add the categories in the excel?

azure-bot-serviceazure-qna-maker
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

romungi-MSFT avatar image
0 Votes"
romungi-MSFT answered

@NShini-4293 As a initial thought I could see this possible using the metadata tags on answers in your KB. This should help filter answers based on the tags i.e key value pair. For example:

 Pair                                  Question                         Answer                            Metadata
 1                          I want to drill a hole                  Power Drill                        Category: 1
                            I want to tighten a screw                                                  Category: 1
    
 2                          I want to smoothen surface              File                               Category: 2

The documentation should help you get a better idea of its usage.
Since QnAMaker helps you to deploy a bot automatically after publish you would need to test the same directly from the portal to check if your KB is working as expected. That is, check if all the required answers are returned and then you can filter the metadata in the response in your client app or bot later.


· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello thanks for the response. I am using QnA Maker to ask the user to choose a category and I have inserted the metadata in the QnA Maker. I have seen a few documentation on metadata in C# but they are just snippets and I have no idea where and how to implement it in my code. I have attached a screenshot of my project. Thank you in advance.

121321-image-1.png


1 Vote 1 ·
image-1.png (54.3 KiB)

You can add them as options in your call to generateAnswerAsync(), For example:

 using Microsoft.Bot.Builder.AI.QnA;
 var metadata = new Microsoft.Bot.Builder.AI.QnA.Metadata();
 var qnaOptions = new QnAMakerOptions();
    
 metadata.Name = 'Category';
 metadata.Value = '1';
 qnaOptions.StrictFilters = new Microsoft.Bot.Builder.AI.QnA.Metadata[] { metadata };
 qnaOptions.Top = Constants.DefaultTop;
 qnaOptions.ScoreThreshold = 0.3F;
 var response = await _services.QnAServices[QnAMakerKey].GetAnswersAsync(turnContext, qnaOptions);

This should only return answers with metadata key category set to 1. Basically we are using the qnaOptions to pass the metadata in StrictFilters to return only the key/value pair we require. You could as well get the complete response and then filter the JSON to read all the categories.


1 Vote 1 ·

Thanks a lot for your help. It is working perfectly fine now :)

1 Vote 1 ·