Skip to main content

$rag.chat.processQueryAsync

The method creates a request for response generation in the knowledge base. The history in the knowledge base chat is taken into account for the response.

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
chatIdNumber

Chat identifier.

Use the identifier returned by the $rag.chat.create method.
Yes
queryStringText of the user query.Yes
settingsObject

Query processing settings. By default, the settings from the chat are used.

The settings format matches the format of the identically named object in the POST /api/knowledge-hub/async/chat/{chatId}/query request in the Tovie Data Agent 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

You can pass arguments to the method in different ways.

Specify the arguments in order:

await $rag.chat.processQueryAsync("MyKnowledgeHub", 12345, "What does the Example service do?", undefined, 5000);

Return value

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

{
"id": 11111,
"chatId": 12345,
"request": "What does the Example service do?",
"status": "READY_TO_PROCESS",
"createdAt": "2024-12-03T17:05:22.928610258Z",
"response": null,
"updatedAt": "2024-12-03T17:05:22.928613255Z",
"comment": null
}

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

How to use

state: Answer
intent!: /question
scriptEs6:
$client.chat = $client.chat || await $rag.chat.create("MyKnowledgeHub", "My chat");

const ragRequest = await $rag.chat.processQueryAsync("MyKnowledgeHub", $client.chat.id, $request.query);
$session.currentId = ragRequest.id

In this state:

  1. If there is no chat yet, the bot creates a chat.
  2. The bot creates a request and saves its identifier.

You can use this identifier in the $rag.chat.getQueryAnswer and $rag.chat.cancelRecordProcessing methods.