If you’ve already implemented Search Results Page on your website, you can add AI Answers alongside it to provide your users with AI-generated answers based on your indexed content.
This tutorial explains how to add AI Answers to your existing search implementation.
Adding AI Answers to an existing Search Results Page contains the following steps:
To make sure AI Answers works, ensure your major versions meet these minimum requirements:
Visit the Search UI Library repository and the AddSearch Search API Client for JavaScript repository on GitHub for more information on the latest versions.
To display AI Answers, add its container alongside your existing containers:
<!-- Add this container among your existing containers --> <div id="ai-answers-result-container"></div>
The id you choose here will be used in the AI Answers component settings to specify where the component should be rendered.
Add configuration setting { hasAiAnswers: true } to the Search UI Library instance to enable AI Answers:
// Client Instance const addSearchClient = new AddSearchClient('YOUR_PUBLIC_SITE_KEY'); // Add 'hasAiAnswers: true' setting to enable AI Answers const conf = { hasAiAnswers: true } // Add configuration object 'conf' to Search UI instance const addSearchUi = new AddSearchUI(addSearchClient, conf);
Note: If you already have a configuration, add the hasAiAnswers setting to your existing Search UI configuration while maintaining your current settings.
Add the aiAnswersResult component:
// Instantiate AI Answers UI (place among your existing components) addSearchUi.aiAnswersResult({ containerId: 'ai-answers-result-container', mainHeadlineText: 'AI-generated answer', answerMaxHeight: 150, sourcesHeadlineText: 'Based on the following sources:', hasHideToggle: true });
The aiAnswersResult component displays the AI-generated answers in the container element. Please ensure that the containerId matches its corresponding container id.
You can customize the appearance of the AI Answers using CSS:
/* Use the corresponding container id as the selector */ #ai-answers-result-container { margin-top: 24px; }
We’re always happy to help with code or other questions you might have. Search our documentation, contact support, or connect with our sales team.