Skip to main content

$rag.chat.retrieveChunksFromChat

The method returns chunks relevant to the user’s query from a knowledge base chat.

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
chatIdInteger

Chat identifier.

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

Chunk search 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/chat/{chatId}/retrieve 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

Specify the arguments in order:

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

Return value

The method returns an object with a list of chunks. They are sorted in descending order of relevance.

{
"chunks": [
{
"score": 0.7486038,
"content": "The Example service processes user requests …",
"docId": "Documentation.pdf",
"metadata": null
},
{
"score": 0.7337575,
"content": "The Example service can handle high loads …",
"docId": "Services.pdf",
"metadata": null
}
]
}

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

How to use

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

const chunks = await $rag.chat.retrieveChunksFromChat("MyKnowledgeHub", $client.chat.id, $request.query);
$reactions.answer(chunks.chunks[0].content);

In this state:

  1. If there is no chat yet, the bot creates a chat.
  2. The bot sends the most relevant chunk to the user.