Getting AI-powered questions and answers
You can use the Search and Recommendation API for Sitecore Search to get AI-powered questions and answers based on a visitor's query.
An AI's ability to generate relevant questions and answers directly relies on the items indexed in the source you pass. If the indexed content doesn't match the visitor's query, the AI will not provide related responses. For instance, a visitor search for Who is the CEO of Sitecore? will give no results if the source only indexes children's books.
You'll need to use the questions
object to get questions and answers. For this object's data model, see the search.widget.items.questions
in the Search and Recommendation API reference documentation.
The questions
object has several parameters. Depending on which parameter you pass, you can get two types of results: sets of related questions and answers or one exact answer.
Getting related questions
You can use the questions.related_questions
parameter to get AI-powered question-and-answer pairs that relate to the visitor's search term. For example, you can use these questions and answers to populate a people also asked or frequently asked section.
Simple query to get related questions and answers
This is a simple example to get related questions and answers based on a keyphrase.
In this example, the visitor enters the keyphrase content hub and you want to show five related questions.
Here's a sample request:
{
"widget": {
"items": [
{
"entity": "content",
"rfk_id": "rfkid_qa",
"questions": {
"keyphrase": "content hub?",
"related_questions": {
"limit": 5
}
},
"sources": ["sourceID1", "sourceID2", ]
}
]
}
}
In the following sample response to this request, you can see the AI-generated questions What is content hub? and How can I integrate with content hub?, and the corresponding answers.
{
"dt": 1649558400,
"errors": [],
"ts": 1649558400,
"widgets": [
{
"entity": "content",
"errors": [],
"facet": [],
"limit": 5,
"offset": 0,
"related_questions": [
{
"answer": "Sitecore Content Hub is a comprehensive digital asset management system that you can use to handle a wide array of marketing content and assets efficiently. It offers a suite of tools for managing digital assets, content, products, and brands, as well as for creating publication templates and integrating with external applications.",
"context": "Sitecore Content Hub is a digital management application that provides you with a variety of features centered around digital assets and marketing content...",
"document_id": "doc123",
"extra_fields": {},
"highlight": "Content Hub",
"id": "qa123",
"question": "What is content hub?",
"type": "FAQ"
},
{
"answer": "You can perform internal and external integration with Sitecore Content Hub. You can use scripts, triggers APIs, and SDKs to integrate.",
"context": "Sitecore Content Hub integrates internal features that add greater flexibility and advanced customization. This section explains how to use custom scripts....This section explains how to use Sitecore Content Hub to integrate third-party APIs and SDKs to improve developer usability....",
"document_id": "doc124",
"extra_fields": {},
"highlight": "Content Hub integration",
"id": "qa124",
"question": "How can I integrate with Content Hub?",
"type": "FAQ"
}
// ... 3 more related questions
],
"rfk_id": "rfkid_qa",
"total_item": 5,
"type": "Questions Widget",
"used_in": "Search Page"
}
]
}
Advanced query to get related questions and answers
This is an advanced example of getting related questions and answers based on a keyphrase. Here, you also want to filter results and boost results.
In this example, the visitor enters the keyphrase books for young teens and you want to show five related questions. Additionally you want to:
-
Limit the questions and answers to blog and article content types. To do this, pass a
filter
object that uses the type attribute and use theor
filter. -
Boost questions and answers from content uploaded after Jan 1st, 2023. To do this, pass a
boost
object with agte
(greater than) filter.
Here's a sample request:
{
"widget": {
"items": [
{
"entity": "content",
"rfk_id":"rfkid_qa",
"questions": {
"keyphrase": "books for young teens",
"related_questions": {
"filter": {
"type": "or",
"filters": [
{
"name": "type",
"type": "eq",
"value": "blog"
},
{
"name": "genre",
"type": "eq",
"value": "article"
}
]
},
"limit": 10,
"offset": 0,
"rule": {
"boost": [
{
"filter": {
"type": "gte",
"name": "date_uploaded",
"value": "2023-12-15"
},
"weight": 2.5
}
]
}
}
},
"sources": ["SourceID1", "SourceID2", "SourceID3"]
}
]
}
}
Getting an exact answer
You can use the questions.exact_answer
object to get an exact answer to a question or phrase that a visitor enters. You can, for example, show the answer just underneath the search bar.
In this example, you want to provide an exact answer to the visitor query Mount Everest height.
Here's a sample request:
{
"widget": {
"items": [
{
"rfk_id": "rfkid_qa",
"entity": "content",
"questions": {
"keyphrase": "mount everest height",
"exact_answer": {
"query_types": ["statement"]
}
},
"sources": ["sourceID1", "sourceID2"]
}
]
}
}
Here's a sample response to this request:
{
"dt": 1649558400,
"errors": [],
"ts": 1649558400,
"widgets": [
{
"entity": "content",
"errors": [],
"facet": [],
"limit": 1,
"offset": 0,
"related_questions": [
{
"answer": "8,848.86 meters (29,031.7 feet) above sea level.",
"context": "The height of Mount Everest has been a subject of some variation over the years, with the most recent survey in 2020 establishing its height at 8,848.86 meters. This makes it the tallest mountain above sea level...",
"document_id": "docEverest123",
"extra_fields": {},
"highlight": "Mount Everest height",
"id": "qaEverestHeight",
"question": "What is the height of Mount Everest?",
"type": "FAQ"
}
],
"rfk_id": "rfkid_qa",
"total_item": 1,
"type": "Questions Widget",
"used_in": "Search Page"
}
]
}
To get related questions and answers and an exact answer together, pass questions.related_questions
and questions.exact_answer
in the same request. You can use the response to show both an exact answer under the search bar and a people also asked section.