Azure Cognitive Search AKA Azure Search is a cloud search service that used for build web, mobile or enterprise applications. If your Azure blob storage files want to index, you need to use Azure Search. You can use Azure Search for your chatbot to get the relevant information quickly by using Azure SDK (.NET, Python, Java, and JavaScript).
How to create index in Azure Search
Azure provided several methods to index your stored files using Azure Search.
· Azure portal
· C#
· Java
· JavaScript
· Python
· REST
Easiest way to do it by using portal. But it is your choice to choose the best way to create the index for your chatbot.
How to implement in chatbot
If you create your chatbot using botframework SDK, you need to learn about component dialogs. In component dialog you can specify the steps and with in one step you can insert your azure search SDK to query the file. Then you can get your information to attach for the bot response.
As example after you import the component dialog into your chatbot script, then inside the component dialog you can add the waterfall dialog which bind the steps.
class <class name> extends ComponentDialog {
constructor(<parameters>) {
super(<super class name>);
this.addDialog(
new WaterfallDialog(<waterfall dialog string name>, [
this.<step name>.bind(this),
this. <step name>.bind(this),
])
);
this.initialDialogId = <waterfall dialog string name>;
}
After that with in one step you can insert your azure search step. May be before this step you may need to store some values to filter the file using Azure Search. For that you can ask some of the questions from your bot and then store that information.
async <step name>(<filter parameters>) {
const indexName1 = <Azure Index Name>;
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
const client = new SearchClient(
endpoint,
indexName1,
new AzureKeyCredential(apiKey)
);
const searchResult = await client.search("*", {
select: [<Searchable entities >],
filter: <filter condition>,
});
for await (const result of searchResult.results) {
<array variable>.push(result.document.<entity name>);
}
return <array variable>;
}
留言