Skip to content

Commit

Permalink
Make QnA Maker Active Learnings Thresholds user settable (#2508)
Browse files Browse the repository at this point in the history
* Make QnA Maker Active Learnings Threasholds user settable

* space

* Make QnA Maker Active Learnings Threasholds user settable

* space

* add strong type and access modifiers

Co-authored-by: Somi Reddy Satti <[email protected]>
Co-authored-by: Chris Mullins <[email protected]>
  • Loading branch information
3 people authored Aug 6, 2020
1 parent 6172deb commit 1f42b94
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions libraries/botbuilder-ai/src/qnaMakerDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { RankerTypes } from './qnamaker-interfaces/rankerTypes';
import { QnAMaker, QnAMakerResult } from './';
import { FeedbackRecord, FeedbackRecords, QnAMakerMetadata } from './qnamaker-interfaces';
import { QnACardBuilder } from './qnaCardBuilder';
import { ActiveLearningUtils } from './qnamaker-utils/activeLearningUtils';

const V4_API_REGEX = /^https:\/\/.*\.azurewebsites\.net\/qnamaker\/?/i;

Expand Down Expand Up @@ -95,7 +96,6 @@ export class QnAMakerDialog extends WaterfallDialog {
// Dialog options parameters
private defaultCardNoMatchResponse: string = `Thanks for the feedback.`;
private defaultNoAnswer: string = `No QnAMaker answers found.`;
private maximumScoreForLowScoreVariation: number = 0.95;

private knowledgeBaseId: any;
private hostName: any;
Expand Down Expand Up @@ -254,7 +254,7 @@ export class QnAMakerDialog extends WaterfallDialog {

step.values[this.qnAData] = response.answers;

if (qnaResponse.answers.length > 0 && qnaResponse.answers[0].score <= this.maximumScoreForLowScoreVariation) {
if (qnaResponse.answers.length > 0 && qnaResponse.answers[0].score <= ActiveLearningUtils.MaximumScoreForLowScoreVariation / 100) {
qnaResponse.answers = qna.getLowScoreVariation(qnaResponse.answers);

if (isActiveLearningEnabled && qnaResponse.answers && qnaResponse.answers.length > 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@

import { QnAMakerResult } from '../qnamaker-interfaces/qnamakerResult';

/** Minimum Score For Low Score Variation. */
const MinimumScoreForLowScoreVariation = 20;

/** Previous Low Score Variation Multiplier. */
const PreviousLowScoreVariationMultiplier = 0.7;

/** Max Low Score Variation Multiplier. */
const MaxLowScoreVariationMultiplier = 1.0;

/** Maximum Score For Low Score Variation. */
const MaximumScoreForLowScoreVariation = 95.0;

/**
* Generate Answer api utils class.
*
* @remarks
* This class is helper class for generate answer api, which is used to make queries to a single QnA Maker knowledge base and return the result.
*/
export class ActiveLearningUtils {
export class ActiveLearningUtils {
/** Minimum Score For Low Score Variation. */
public static MinimumScoreForLowScoreVariation : number = 20;

/** Maximum Score For Low Score Variation. */
public static MaximumScoreForLowScoreVariation : number = 95.0;

/**
* Returns list of qnaSearch results which have low score variation.
* @param {QnAMakerResult[]} qnaSearchResults A list of results returned from the QnA getAnswer call.
Expand All @@ -44,14 +44,14 @@ export class ActiveLearningUtils {
let filteredQnaSearchResult = [];
let topAnswerScore = qnaSearchResults[0].score * 100;

if (topAnswerScore > MaximumScoreForLowScoreVariation) {
if (topAnswerScore > ActiveLearningUtils.MaximumScoreForLowScoreVariation) {
filteredQnaSearchResult.push(qnaSearchResults[0]);
return filteredQnaSearchResult;
}

let prevScore = topAnswerScore;

if (topAnswerScore > MinimumScoreForLowScoreVariation) {
if (topAnswerScore > ActiveLearningUtils.MinimumScoreForLowScoreVariation) {
filteredQnaSearchResult.push(qnaSearchResults[0]);

for (let i = 1; i < qnaSearchResults.length; i++) {
Expand Down

0 comments on commit 1f42b94

Please sign in to comment.