简体   繁体   中英

Integrating Azure Search with Virtual Assistant Template bot

I currently have a fully functioning Virtual Assistant Template-based chatbot with a skill attached to it. My goal is for the skill to work as a search function that can find resources in a CosmosDB and pull them back for the user to use. After doing some research I believe the best way to do this would be to use Azure search to retrieve said info. From what I've seen in the Virtual Assistant Template documentation integration with Azure Search should definitely be possible... I just haven't found any examples or tutorials on how to do so. If anyone knows how to create an azure search resource and integrate it into a bot, or knows of a resource that tells you how to do so, please let me know!

For your scenario, an outline of what to do is:

  1. Create an Azure search service
  2. In that create an indexer that will point to your Cosmos DB data source. Here is documentation specific to how you can crawl through your data in Cosmos DB: https://docs.microsoft.com/en-us/azure/search/search-howto-index-cosmosdb
  3. Once your indexer runs and has crawled through your data, it should be available for searching, from the app in your search index.

There isn't an end to end tutorial about integrating with a bot, but here is an Azure search tutorial that shows an complete scenario of crawling through a SQL database and then searching using full-text search. https://docs.microsoft.com/en-us/azure/search/search-indexer-tutorial

You should be able to follow most of the guidance there, except replace the parts about SQL indexer with details from Cosmos DB indexer in the link above.

I want to do a similar search (only in AzureBlob instead of Cosmos DB). I am using sdk v4 for my bot framework and Visual Studio 2019. I'm trying to call the service through the code below:

    public ISearchIndexClient CreateSearchIndexClient()
    {
        string searchServiceName = "MySearchServiceName";
        string queryApiKey = "MySearchServiceKey";
        string indexName = "MyIndexName";

        SearchIndexClient indexClient = new SearchIndexClient(searchServiceName, indexName, new SearchCredentials(queryApiKey));
        return indexClient;
    }

    public async Task StartAsync(ITurnContext turnContext, string searchText){
        ISearchIndexClient infoClient = CreateSearchIndexClient();

        string indexname = infoClient.IndexName;
        DocumentSearchResult<Document> results = infoClient.Documents.Search(searchText);

        await turnContext.SendActivityAsync(MessageFactory.Text($"Here should be the results: {results} \n...and then my index: {indexname}."));
    }

It runs without errors, so one could use it. But it never shows the message at StartAsync. If anyone sees what I am missing, thank u in advance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM