Cognitive Search - Azure Search with AI
Today, at Microsoft //build conference we announced Cognitive Search. You may wonder what is Cognitive Search. To put it as simple as possible: it’s Azure Search powered by Cognitive Services (Azure Machine Learning APIs). You remember when you wanted to run some intelligence over your data with Cognitive Services? You had to handle creating, e.g., Text Analytics API, then writing code that would take your data from database, issue request to API (remember to use proper key!), serialize, deserialize data and put result in your database?
Now, with Cognitive Search, you can achieve that by checking one checkbox. You just need to pick a field on which you want to run analytics, and which cognitive services or skills (1 cognitive service usually contain multiple skills) to run. As for now we support 6 skills:
- Key phrases
- People
- Places
- Organizations
- Language
- OCR (Optical Character Recognition)
We output results directly to your search index.
Creating Intelligent Search Index
To take advantage of Cognitive Search you need to create Azure Search service in South-Central US or in West Europe. More regions coming soon!
To create search index powered by cognitive services you need to use ‘import data’ flow. Go to your Azure Search Service and click on ‘Import data’ command:
Then pick your data source (MSSQL, CosmosDB, blob storage etc.). I will choose sample data source that contains real estate data:
Now, you need to pick a field on which you want to run analytics. I will choose description. You also need to choose which cognitive services (skills) you want to run, and provide output field names (fields to which we will output cognitive services analysis result):
In the next step you need to configure your index. Usually you want to make fields retrievable, searchable, and filterable. You may also consider making them facetable if you want to aggregate results. This is my sample configuration:
In the last step you just need to configure indexer – a tool that synchronizes your data source with your search index. In my case I will choose to do synchronization only once, as my sample data source will never change.
After indexer finish you can browse your data, and cognitive services results in search explorer.
You can also generate more usable search UI for your data with AzSearch.js.
Generating UI to search data with AzSearch.js
If you don’t like browsing your data with search explorer in Azure Portal that returns raw JSON, you can use AzSearch.js to quickly generate UI over your data.
The easiest way to get started is to use AzSearch.js generator. Before you start, enable CORS on your index:
Once you get your query key and index definition JSON paste it into generator together with your search service name, and click 'Generate'. An html page with simple search interface will be created.
This site is super easy to customize. Providing html template for results change JSON into nicely formatted search results:
All what I did was to create HTML template:
And add it to already present addResults
function call:
I also created resultsProcessor
to do some custom transformations. I.e., join few fields into one, truncate description to 200 characters, and convert key phrases from array into string separated by commas:
You can do similar customization with suggestions. You can also add highlights to your results and much more. Everything is described in AzSearch.js README. We also have starter app written with TypeScript and React based on sample real estate data, which takes advantage of more advanced features of AzSearch.js. If you have any questions or suggestions regarding AzSearch.js let me know on Twitter!
Summary
Cognitive Search takes analyzing data with Azure Search to the next level. It takes away the burden of writing your own infrastructure for running AI-based analysis. For more advanced analysis, including OCR on your images, check out our docs. I am super excited to see it in action, and for the next improvements that we are working on. Let us know what do you think!
*This blog post was written in Boeing 787 during my flight from Toronto to São Paulo, when I was on my way to QCon conference.