Skip to main content

$rag.query.getAnswer

The method returns the status of a response generation request.

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
queryIdNumber

Identifier of the request for response generation.

Use the identifier returned by the $rag.query.generateAnswerAsync method.
Yes
timeoutNumber

Time in milliseconds during which the knowledge base tracks the status of the request.

If the status does not change during this time, the knowledge base returns the current status.

Default value: 3000.
No

You can pass arguments to the method in different ways.

Specify the arguments in order:

await $rag.query.getAnswer("MyKnowledgeHub", 12345, 5000);

Return value

The method returns an object with information about the response generation request. If the request has the FINISHED status, the response field contains the answer to the user question.

{
"id": 12345,
"request": "What does the Example service do?",
"status": "FINISHED",
"createdAt": "2024-12-03T15:02:08.385742Z",
"response": "The Example service processes user requests …",
"updatedAt": "2024-12-03T15:02:14.255934Z",
"comment": null
}

The object has the same format as the response to the GET /api/knowledge-hub/query/{queryId} request in the Tovie Data Agent API.

How to use

state: Answer
intent!: /question
scriptEs6:
const ragRequest = await $rag.query.generateAnswerAsync("MyKnowledgeHub", $request.query);

var statusRequest = await $rag.query.getAnswer("MyKnowledgeHub", ragRequest.id, 5000);
$reactions.answer("Request status: " + statusRequest.status)

In this state:

  1. The bot creates a request and saves its identifier.
  2. The bot gets the request status by this identifier and sends the status to the user.