Developers

GenerateAnswer

generateAnswer

Use this method to return an AI-generated response to a user query, based on the search results matching that query.

Note

GenAI must be enabled in the Settings > General Settings screen of your Search instance. Otherwise, a 403 error will be returned.

Usage

client.generateAnswer(userQuestion: String, questionTrackingCode: String, options: Object);

userQuestion

userQuestion is the query submitted by the user and is used to prompt the AI or LLM Inbenta set up for your solution.

questionTrackingCode

questionTrackingCode is the log ID of the user question that is used to track the user question. To obtain this logID, use trackUserQuestion().

Options

This method has no optional parameters.

Response data format

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.

Example

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
}