microsoft / botbuilder-js

Welcome to the Bot Framework SDK for JavaScript repository, which is the home for the libraries and packages that enable developers to build sophisticated bot applications using JavaScript.
https://github.com/Microsoft/botframework
MIT License
682 stars 278 forks source link

botbuilder-ai does not pass qnaId to the custom question answering endpoint #4242

Closed hlavacek closed 2 years ago

hlavacek commented 2 years ago

Versions

What package version of the SDK are you using: 4.1.6 What nodejs version are you using: v14.17.3 What browser version are you using: N/A What os are you using: N/A

Describe the bug

In the source code in botbuilder-ai, languageServiceUtils.ts, function queryKnowledgebaseRaw, the code does not pass properly queryOptions.qnaId to the custom question answering REST call. This gives a wrong behaviour, when using prompts in the knowledge base.

It is this source code part: https://github.com/microsoft/botbuilder-js/blob/main/libraries/botbuilder-ai/src/qnamaker-utils/languageServiceUtils.ts#L88

There the code is missing the following within the JSON.stringify call:

qnaId: queryOptions.qnaId,

The "Test" functionality in the custom question answering is passing QnaId to the REST endpoint, so there the behaviour is correct, the bug applies only when running a custom bot with botbuilder-ai (e.g. using one of the samples).

To Reproduce

Steps to reproduce the behaviour:

  1. Create a knowledge base with 3 questions, the idea is that the prompt will reference one question, but the text will be from a different one:
    • Qna ID: 1, "question 1" - answer should contain prompt: "Question 2 explanation text", reference to Qna ID 2
    • Qna ID: 2, "question 2" - answer should be "question 2 answer"
    • Qna ID: 3, "Question 2 explanation text" - answer should be "question 2 wrong answer"
  2. deploy the knowledge base and test with with local bot (not with the "Test" button in language studio, there it works correct), for example with sample
  3. use the following question flow:
    1. "question 1" - should give prompt with text "Question 2 explanation text"
    2. Click on the prompt button

Expected behaviour

Correct behaviour would be to show "Question 2 answer", as we have direct reference to "question 2" using its ID. But in local bot (or bot deployed to Azure), it will give "question 2 wrong answer", because the framework is not passing Qna ID to the REST endpoint. Custom Question Answering service will then match the response just based on the text, which will result in Qna ID = 3.

Screenshots

N/A

Additional context

N/A

anishprasad01 commented 2 years ago

Thank you for the report. I will investigate.

anishprasad01 commented 2 years ago

@hlavacek,

When you say "reference to question 2", are you referring to the "Follow-up prompts" option in the CQA portal? I'm not quite sure what it is that you're doing.

hlavacek commented 2 years ago

yes correct, in the Language studio UI it is set up via "Add Follow-up prompts" button, if you export the bot as Excel, then this is stored in the column Prompts as JSON, with an ID reference to the target question.

You select the reference question there, but you can also have the text of the prompt set to something else

anishprasad01 commented 2 years ago

I am able to reproduce this issue. The follow-up prompt is correctly triggered, but the answer to the second question is not returned, and instead the default "No answer found" message is given. I can also confirm that the C# version functions correctly.

Further investigation of the CQA JS feature in the libraries is required.

Arsh-Kashyap commented 2 years ago

Hi, I was able to repro this issue. Thanks for the clear steps. You are correct, qnaId was not being passed in payload body. I have created a PR that will fix this issue. Thanks.