Skip to main content

Create a chatbot

Nuclia is a RAG-based search engine that generates answers based on a set of documents. That is essentially waht is needed to create a chatbot.

The main difference between basic question answering and a chatbot is that a chatbot is able to maintain a conversation with the user. This is achieved by keeping track of the context of the conversation.

Nuclia /ask endpoint is stateless, and does not keep track of the conversation. To create a chatbot, you need to keep track of the conversation on your side.

To inject the context in the /ask call, you can use the context parameter. It is a list of objects that represent the context of the conversation. Each object has an author and a text field. You need to pass bothe the user's questions (author: "USER") and the Nuclia's answers (author: "NUCLIA").

By setting the rephrase parameter to true, Nuclia will rephrase the last question according the context in order to retrieve accurate data. In our example below, the user asks "What did she invent?" and the context allows to understand that "she" refers to Hedy Lamarr.

Here is an example of a call to the /ask endpoint with conversation context:

curl --request POST 'https://<zone>.nuclia.cloud/api/v1/kb/<your-knowledge-box-id>/ask' \
--header 'X-NUCLIA-SERVICEACCOUNT: Bearer YOUR_API_KEY' \
--header 'content-type: application/json' \
--data '{
"query": "What did she invent?",
"context": [
{
"author": "USER",
"text": "Who is Hedy Lamarr?"
},
{
"author": "NUCLIA",
"text": "Hedy Lamarr was an actor, inventor, and amateur engineer."
}
],
"rephrase": true
}'