0
votes

I'm trying to integrate luis with a working QNA active learning bot. I have created intents dialog with Luis and QNA dialogs

var luisRecognizer = new builder.LuisRecognizer(config.luisEndPoint)
luisRecognizer.onFilter(function(context, result, callback) {
  if (result.intent != 'None' && result.score < 0.8) {
    callback(null, { intent: 'None', score: 0});
  } else {
    callback(null, result);
  }
});


const qnaRecognizer = new cognitiveServices.QnAMakerRecognizer({
    knowledgeBaseId: process.env.KBID,
	  endpointHostName: process.env.HOST_NAME,
    authKey: process.env.SUBSCRIPTION_KEY,
    top: 4
});

var feedbackTool = new feedbackTool.FeedbackTool();
bot.library(feedbackTool.createLibrary());

const qnaMakerDialog = new cognitiveServices.QnAMakerDialog({
    recognizers: [qnaRecognizer],
    defaultMessage: DefaultMessageQNA,
    qnaThreshold: qnaThreshold,
    feedbackLib:feedbackTool
});


  var intentsDialog = new builder.IntentDialog({ recognizers: [luisRecognizer, qnaMakerDialog ] });
bot.dialog('/', intentsDialog);

and based on luis results iam calling dailogs as

 intentsDialog.matches("someIntent", [someIntent.getDialog()]);
intentsDialog.matches("anotherIntent", [anotherIntent.getDialog()]);

intentsDialog.matches('qna', [
    function (session, args, next) {
        //problem 1
        qnaMakerDialog.invokeAnswer(session, args, qnaThreshold, defaultMessageQNA)
    }
]);


intentsDialog.onDefault( [
    function (session) {
       //problem 2
       session.send('Sorry, I don\'t know that.');
    }
]);

This code gives right results for a valid QNA and redirects to appropriate dialog based on luis intent.

But I am facing 2 challenges in the above code:

  1. when intentsDialog matches qna, and qna doesnt have a straight ans and gives options to select. In this case i'm unable to capture user selected option and send it to qna active learning code.( Im overriding qnaMakerDialog.defaultWaitNextMessage for storing new questions to KB )
  2. When intentsDialog doesnt match qna and luis, even in this scenario i want that data to be send to qna active learning part but unable to send it.

Is there any other way like without using IntentDialog and forwarding context to qna. Thanks in advance.

1

1 Answers

0
votes

For your first question, I think the root cause could be that you haven't set the appropriate value to threshold.

Please refer to the source code at https://github.com/Microsoft/BotBuilder-CognitiveServices/blob/master/Node/lib/QnAMakerDialog.js#L74:

if (qnaMakerResult.score >= threshold && qnaMakerResult.answers.length > 0) {
            if (this.isConfidentAnswer(qnaMakerResult) || this.qnaMakerTools == null) {
                this.respondFromQnAMakerResult(session, qnaMakerResult);
                this.defaultWaitNextMessage(session, qnaMakerResult);
            }
            else {
                this.qnaFeedbackStep(session, qnaMakerResult);
            }
        }
        else {
            session.send(noMatchMessage);
            this.defaultWaitNextMessage(session, qnaMakerResult);
        }

the default value for threshold is 0.3, so your question may steps into else condition, you can set lower threshold to let your request steps into this.qnaFeedbackStep(session, qnaMakerResult);.

BTW, active learning is not available for QnA marker, you can monitor the issue at https://github.com/Microsoft/BotBuilder/issues/4884 for any progress.

For your second question, you certainly can use UniversalBot with normal dialog to implememnt LUIS & QnA marker bot. Please consider following code snippet:

var luisAppUrl = '<luisAppUrl >';

var luisRecognizer = new builder.LuisRecognizer(luisAppUrl)
bot.recognizer(luisRecognizer);

var recognizer = new cognitiveservices.QnAMakerRecognizer({
    knowledgeBaseId: '<knowledgeBaseId>',
    authKey: '<authKey>',
    endpointHostName: "https://<your host name>.azurewebsites.net/qnamaker",
    top: 3,
});

var basicQnAMakerDialog = new cognitiveservices.QnAMakerDialog({
    recognizers: [recognizer],
    defaultMessage: 'No match! Try changing the query terms!',
    qnaThreshold: 0.1,
    feedbackLib: customQnAMakerTools,
});

bot.dialog('kb', basicQnAMakerDialog);
bot.dialog('QnADetect',[(session,args,next)=>{
    session.replaceDialog('kb', args)
}]).triggerAction({
    matches: 'qna'
 })