Use this method to return an AI-generated response to a user query, based on the search results matching that query.
GenAI must be enabled in the Settings > General Settings screen of your Search instance. Otherwise, a 403 error will be returned.
client.generateAnswer(userQuestion: String, questionTrackingCode: String, options: Object);
userQuestion
is the query submitted by the user and is used to prompt the AI or LLM Inbenta set up for your solution.
questionTrackingCode
is the log ID of the user question that is used to track the user question. To obtain this logID
, use trackUserQuestion()
.
This method has no optional parameters.
This method calls the Search API’s POST generate-answer
endpoint to return a {Promise<Object>}
that is fulfilled to obtain the generated answer. Please refer to the Responses section of that endpoint on the Knowledge API Routes page for the response format.
The response data is a complete JSON object.
To generate an answer, you must first obtain the logID for the user question using trackUserQuestion()
. This returns a string with the logID
value.
Use this value in the questionTrackingCode
parameter along with the matching user question to generate an answer.
client.client.generateAnswer("What time are you open?","1234")
A JSON object with the full answer is returned:
{
"answer": "We're open everyday from 8 AM to 2 PM.",
"context": [
{
"title": "Store schedule",
"answer": "Operating hours daily schedule.",
"url": "https:/www.our-store.com"
},
{
. ...
}
],
"match_type": "MATCH",
"score": 1.0,
"uid": 123
}