Skip to main content

$rag.query.generateAnswerAsync

The method creates a request for response generation in the knowledge base.

caution

The method is available only in the ECMAScript 6 runtime and is asynchronous.

Syntax

The method accepts the following arguments:

ArgumentTypeDescriptionRequired
secretNameStringName of the knowledge base secret.Yes
queryStringText of the user query.Yes
historyArrayHistory of the dialog with the bot. You can pass the history so that the knowledge base takes the context into account. Get the history using $rag.getChatHistory.No
settingsObject

Query processing settings. By default, the settings from the Jay Knowledge Hub project are used.

The settings format matches the format of the identically named object in the POST /api/knowledge-hub/async/query request in the Jay Knowledge Hub API.
No
timeoutNumber

Timeout in milliseconds for the method execution. If the timeout is exceeded, an error will occur.

By default, the timeout is not set.
No

Specify the arguments in order:

await $rag.query.generateAnswerAsync("MyKnowledgeHub", "What does the Example service do?", undefined, undefined, 5000);

Return value

The method returns an object with information about the created request.

{
"id": 12345,
"request": "What does the Example service do?",
"status": "READY_TO_PROCESS",
"createdAt": "2024-12-03T14:50:13.088492634Z",
"response": null,
"updatedAt": "2024-12-03T14:50:13.088497397Z",
"comment": null
}

The object has the same format as the response to the POST /api/knowledge-hub/async/query request in the Jay Knowledge Hub API.

How to use

state: Answer
intent!: /question
scriptEs6:
// The bot gets the dialog history
const history = await $rag.getChatHistory();
// The bot creates a request in the knowledge base
const ragRequest = await $rag.query.generateAnswerAsync("MyKnowledgeHub", $request.query, history);
$session.currentId = ragRequest.id;

In this state, the bot creates a request and saves its identifier. You can use this identifier in the $rag.query.getAnswer and $rag.query.cancelProcessing methods.