2

I'm using the following code in my chat bot (using v4 azure MS bot framework), to query the question and answers (Client side code - using plain JavaScript and J Query),

  function generateAnswer() 
  {
        var question = {
            question: "will you marry me"
        }
        $.ajax({
            type: "POST",
            url: "https://YourEndPointURL/qnamaker/knowledgebases/eb895acb-e034-4f7c-asda7c-1955458ecec6/generateAnswer&$filter=source eq 'Editorial'",
            data: JSON.stringify(question),
            beforeSend: function (xhr) {
                xhr.setRequestHeader('Authorization','EndpointKey c44444_Your_Endpoint_Key_4556');
            },
            dataType: "json",
            contentType: "application/json",
            success: function (data) {
                console.log(data);
                console.log(data.answers[0].answer);   
            }
        });
    }

while using this code, i"m getting the following error response

The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

So please help me with the correct syntax to apply filter for my query.

Jegan Baskaran
  • 337
  • 2
  • 16
  • What do you Intent to get? QnA endpoint doesn't support query filter, please add your expected output. Do you want to get `Editorial` value? – Md Farid Uddin Kiron Jan 23 '20 at 10:59
  • @MdFaridUddinKiron , thanks for replying, my intention is to get the answers only from a particular source in the knowledge base, the expected output same as this [output](https://i.stack.imgur.com/V7GTj.png) , however when i have multiple sources in my knowledge base i should restrict the results / narrow down the results with only one source – Jegan Baskaran Jan 23 '20 at 11:02
  • So Its better to filter your result from response , but query filter is to supported for QnA maker request service. If I am not wrong you want just a single result right? – Md Farid Uddin Kiron Jan 23 '20 at 11:11
  • **Consider this Example** : when a user enter a question - what is your name ? the results is saved in two places i.e. Editorial source and mykb.xslx source, the bot now gives me the results from Editorial source only, but i want the results from mykb.xslx only. Hope this will be clear, is there any way i can filter the source of results – Jegan Baskaran Jan 23 '20 at 11:16
  • When you would select your KB it should have request endpoint information like this POST /knowledgebases/KEY/generateAnswer Host: YourURL/qnamaker Authorization: EndpointKey YourKey Content-Type: application/json {"question":""} So it should give you response from your KB – Md Farid Uddin Kiron Jan 23 '20 at 11:41

1 Answers1

1

According to https://learn.microsoft.com/en-us/azure/cognitive-services/qnamaker/how-to/metadata-generateanswer-usage, you need to specify filters in the body (the data property)

function generateAnswer() 
  {
        var data = {
            question: "will you marry me",
            strictFilters: [
            {
              "name": "source",
              "value": "Editorial"
            }],
        }
        $.ajax({
            type: "POST",
            url: "https://YourEndPointURL/qnamaker/knowledgebases/eb895acb-e034-4f7c-asda7c-1955458ecec6/generateAnswer",
            data: JSON.stringify(data),
            beforeSend: function (xhr) {
                xhr.setRequestHeader('Authorization','EndpointKey c44444_Your_Endpoint_Key_4556');
            },
            dataType: "json",
            contentType: "application/json",
            success: function (data) {
                console.log(data);
                console.log(data.answers[0].answer);   
            }
        });
    }

Moreover, you are missing 2 things:

  1. your hostname, to replace YourEndPointURL
  2. endpoint key, to replace c44444_Your_Endpoint_Key_4556
djolf
  • 1,196
  • 6
  • 18
  • Hi, thanks for replying.. I'm getting the following error code by trying your idea, "{ "error": { "code": "AzureSearchBadState", "message": "Strict filter (source) does not exist in the KB. Please retry with valid strict filters." } }" – Jegan Baskaran Jan 23 '20 at 10:57
  • It's because it doesn't support query filter above answer is not correct. If you want to fetch `Editorial value` let me know. – Md Farid Uddin Kiron Jan 23 '20 at 11:01
  • @MdFaridUddinKiron , Yes, i want to fetch editorial results alone in one scenario and another source in different scenario , please help me with the correct method. – Jegan Baskaran Jan 23 '20 at 11:27
  • My previous answer getting answer from my knowledge base I am wondering why I have to filter it again and What I have to filter I am confused now! – Md Farid Uddin Kiron Jan 23 '20 at 11:33
  • one knowledge base contains multiple sources (Editorial , Mycsutom Excel, qnamker chit chat..etc ), i want to query only one source ( Mycsutom Excel) – Jegan Baskaran Jan 23 '20 at 11:46