$caila.cdqaQuery
This method retrieves excerpts from a document uploaded to a CDQA module in the knowledge base.
Syntax
The method accepts the following arguments:
Argument | Type | Required | Description |
---|---|---|---|
query | String | Yes | Query text. |
moduleName | String | Yes | CDQA module name, such as CDQA.Our courses . |
threshold | Number | No | The threshold which determines the minimum required confidence in the correctness of CDQA responses. Its value should be between 0 (not included) and 1 (included). The default value is 0.5. |
classifierToken | String | No | The NLP Direct API key. The default value is the API key of the current project. You should only pass this argument if the bot and the CDQA module are in different projects. |
$caila.cdqaQuery("What is CDQA?", "CDQA.Knowledge base", 0.3);
The method returns an object with the following properties:
Property | Type | Description |
---|---|---|
predicted | String | The CDQA response with the highest score higher than the threshold . |
variants | Array of strings | A list of CDQA responses with a score higher than the threshold . |
raw | Object | The full CDQA response body. It contains a list of all responses with metadata, as well as the excerpt from which they were retrieved. |
tip
If the CDQA query didn’t return any suitable response, the
predicted
value will be null
, and variants
will be an empty array.{
"predicted": "a question answering system based on machine learning",
"variants": [
"a question answering system based on machine learning"
],
"raw": {
"output": [
{
"extracted_texts_list": [
{
"texts": [
{
"start_index": 47, // The position within `source_text` where the response begins
"end_index": 100, // The position within `source_text` where the response ends
"confidence": 0.65422564744949341, // The value of confidence in response correctness
"text": "a question answering system based on machine learning"
},
{
"start_index": 10,
"end_index": 42,
"confidence": 0.081722691655159,
"text": "Closed Domain Question Answering"
}
],
"source_text": "The CDQA (Closed Domain Question Answering) is a question answering system based on machine learning.",
"source_text_score": 0.265350878238678
}
]
}
]
}
}
How to use
Add the $caila.cdqaQuery
method to the global state for handling unrecognized requests
to enable the bot to use CDQA responses.
state: NoMatch
event!: noMatch
script:
var result = $caila.cdqaQuery($request.query, "CDQA.Our courses", 0.5);
if (result.predicted) {
$reactions.answer(result.predicted);
} else {
$reactions.answer("I didn’t find the answer in my documents. Ask something else!");
}