QnAMaker Class

  • java.lang.Object
    • com.microsoft.bot.ai.qna.QnAMaker

Implements

public class QnAMaker
implements QnAMakerClient, TelemetryQnAMaker

Provides access to a QnA Maker knowledge base.

Field Summary

Modifier and Type Field and Description
static final java.lang.String QNA_MAKER_NAME

The name of the QnAMaker class.

static final java.lang.String QNA_MAKER_TRACE_LABEL

The label used when logging QnA Maker trace.

static final java.lang.String QNA_MAKER_TRACE_TYPE

The type used when logging QnA Maker trace.

Constructor Summary

Constructor Description
QnAMaker(QnAMakerEndpoint withEndpoint, QnAMakerOptions options)

Initializes a new instance of the QnAMaker class.

QnAMaker(QnAMakerEndpoint withEndpoint, QnAMakerOptions options, BotTelemetryClient withTelemetryClient, Boolean withLogPersonalInformation)

Initializes a new instance of the QnAMaker class.

Method Summary

Modifier and Type Method and Description
java.util.concurrent.CompletableFuture<java.lang.Void> callTrain(FeedbackRecords feedbackRecords)

Send feedback to the knowledge base.

protected java.util.concurrent.CompletableFuture<Pair<java.util.Map<java.lang.String,java.lang.String>,java.util.Map<java.lang.String,java.lang.Double>>> fillQnAEvent(QueryResult[] queryResults, TurnContext turnContext, Map<String,String> telemetryProperties, Map<String,Double> telemetryMetrics)

Fills the event properties and metrics for the QnaMessage event for telemetry.

java.util.concurrent.CompletableFuture<QueryResult[]> getAnswers(TurnContext turnContext, QnAMakerOptions options)

Generates an answer from the knowledge base.

java.util.concurrent.CompletableFuture<QueryResult[]> getAnswers(TurnContext turnContext, QnAMakerOptions options, Map<String,String> telemetryProperties, Map<String,Double> telemetryMetrics)

Generates an answer from the knowledge base.

java.util.concurrent.CompletableFuture<QueryResults> getAnswersRaw(TurnContext turnContext, QnAMakerOptions options, Map<String,String> telemetryProperties, Map<String,Double> telemetryMetrics)

Generates an answer from the knowledge base.

java.lang.Boolean getLogPersonalInformation()

Gets a value indicating whether determines whether to log personal information that came from the user.

QueryResult[] getLowScoreVariation(QueryResult[] queryResult)

Filters the ambiguous question for active learning.

BotTelemetryClient getTelemetryClient()

Gets the currently configured BotTelemetryClient.

protected java.util.concurrent.CompletableFuture<java.lang.Void> onQnaResults(QueryResult[] queryResults, TurnContext turnContext, Map<String,String> telemetryProperties, Map<String,Double> telemetryMetrics)

Executed when a result is returned from QnA Maker.

Methods inherited from java.lang.Object

java.lang.Object.clone java.lang.Object.equals java.lang.Object.finalize java.lang.Object.getClass java.lang.Object.hashCode java.lang.Object.notify java.lang.Object.notifyAll java.lang.Object.toString java.lang.Object.wait java.lang.Object.wait java.lang.Object.wait

Field Details

QNA_MAKER_NAME

public static final String QNA_MAKER_NAME

The name of the QnAMaker class.

QNA_MAKER_TRACE_LABEL

public static final String QNA_MAKER_TRACE_LABEL

The label used when logging QnA Maker trace.

QNA_MAKER_TRACE_TYPE

public static final String QNA_MAKER_TRACE_TYPE

The type used when logging QnA Maker trace.

Constructor Details

QnAMaker

public QnAMaker(QnAMakerEndpoint withEndpoint, QnAMakerOptions options)

Initializes a new instance of the QnAMaker class.

Parameters:

withEndpoint - The endpoint of the knowledge base to query.
options - The options for the QnA Maker knowledge base.

QnAMaker

public QnAMaker(QnAMakerEndpoint withEndpoint, QnAMakerOptions options, BotTelemetryClient withTelemetryClient, Boolean withLogPersonalInformation)

Initializes a new instance of the QnAMaker class.

Parameters:

withEndpoint - The endpoint of the knowledge base to query.
options - The options for the QnA Maker knowledge base.
withTelemetryClient - The IBotTelemetryClient used for logging telemetry events.
withLogPersonalInformation - Set to true to include personally identifiable information in telemetry events.

Method Details

callTrain

public CompletableFuture callTrain(FeedbackRecords feedbackRecords)

Send feedback to the knowledge base.

Parameters:

feedbackRecords - Feedback records.

Returns:

Representing the asynchronous operation.

Throws:

java.io.IOException - Throws an IOException if there is any.

fillQnAEvent

protected CompletableFuture,Map>> fillQnAEvent(QueryResult[] queryResults, TurnContext turnContext, Map telemetryProperties, Map telemetryMetrics)

Fills the event properties and metrics for the QnaMessage event for telemetry. These properties are logged when the QnA GetAnswers method is called.

Parameters:

queryResults - QnA service results.
turnContext - Context object containing information for a single turn of conversation with a user.
telemetryProperties - Properties to add/override for the event.
telemetryMetrics - Metrics to add/override for the event.

Returns:

A tuple of Properties and Metrics that will be sent to the IBotTelemetryClient. TrackEvent method for the QnAMessage event. The properties and metrics returned the standard properties logged with any properties passed from the GetAnswersAsync method.

Throws:

java.io.IOException - Throws an IOException if there is any.

getAnswers

public CompletableFuture getAnswers(TurnContext turnContext, QnAMakerOptions options)

Generates an answer from the knowledge base.

Parameters:

turnContext - The Turn Context that contains the user question to be queried against your knowledge base.
options - The options for the QnA Maker knowledge base. If null, constructor option is used for this instance.

Returns:

A list of answers for the user query, sorted in decreasing order of ranking score.

getAnswers

public CompletableFuture getAnswers(TurnContext turnContext, QnAMakerOptions options, Map telemetryProperties, Map telemetryMetrics)

Generates an answer from the knowledge base.

Parameters:

turnContext - The Turn Context that contains the user question to be queried against your knowledge base.
options - The options for the QnA Maker knowledge base. If null, constructor option is used for this instance.
telemetryProperties - Additional properties to be logged to telemetry with the QnaMessage event.
telemetryMetrics - Additional metrics to be logged to telemetry with the QnaMessage event.

Returns:

A list of answers for the user query, sorted in decreasing order of ranking score.

getAnswersRaw

public CompletableFuture getAnswersRaw(TurnContext turnContext, QnAMakerOptions options, Map telemetryProperties, Map telemetryMetrics)

Generates an answer from the knowledge base.

Parameters:

turnContext - The Turn Context that contains the user question to be queried against your knowledge base.
options - The options for the QnA Maker knowledge base. If null, constructor option is used for this instance.
telemetryProperties - Additional properties to be logged to telemetry with the QnaMessage event.
telemetryMetrics - Additional metrics to be logged to telemetry with the QnaMessage event.

Returns:

A list of answers for the user query, sorted in decreasing order of ranking score.

getLogPersonalInformation

public Boolean getLogPersonalInformation()

Gets a value indicating whether determines whether to log personal information that came from the user.

Returns:

If true, will log personal information into the IBotTelemetryClient.TrackEvent method; otherwise the properties will be filtered.

getLowScoreVariation

public QueryResult[] getLowScoreVariation(QueryResult[] queryResult)

Filters the ambiguous question for active learning.

Parameters:

queryResult - User query output.

Returns:

Filtered array of ambiguous question.

getTelemetryClient

public BotTelemetryClient getTelemetryClient()

Gets the currently configured BotTelemetryClient.

Returns:

BotTelemetryClient being used to log events.

onQnaResults

protected CompletableFuture onQnaResults(QueryResult[] queryResults, TurnContext turnContext, Map telemetryProperties, Map telemetryMetrics)

Executed when a result is returned from QnA Maker.

Parameters:

queryResults - An array of QueryResult
turnContext - The TurnContext
telemetryProperties - Additional properties to be logged to telemetry with the LuisResult event.
telemetryMetrics - Additional metrics to be logged to telemetry with the LuisResult event.

Returns:

A Task representing the work to be executed.

Throws:

java.io.IOException - Throws an IOException if there is any.

Applies to