Find everything with AI in Azure Cognitive Search

The blog post is about Azure Cognitive Search, a cloud service for creating rich search experiences. The author explains what it is, how it works, and how to use it with different data sources. He also shows how to query the index using various tools.

Microsoft keeps upgrading there services in Azure. And it has not stopped to amaze me. Let's take a look at Azure Search. Not the old one ;-) the new evolved one. Azure Cognitive Search (ACS).

Microsoft has upgraded its old service, Azure Search, with some new cool AI capabilities, also called AI skills.

- Key Phrase Extraction
- Locations
- Persons
- Organizations
- Sentiment Analysis
- Language Detection
- Face Detection

I didn't have the time to try them all out. I tried a few of them. They are very cool and work amazingly well. There are however a few "gotchas" that you must know. But first setup an Azure Cognitive Search environment.

Go to the Azure Portal and setup a Search Service

Next, select a pricing tier. Yes as you can see, it can be quite expensive if you have a lot of data :-(. I selected the basic tier because I want to search through an old pile of PDF documents that are together more than 50mb (free tier).

Leave everything else to default and click Create.

Once the service has been made open it.
Click on the Import data button to start creating indexers and indexes to your data. You can connect many different data stores to your ACS instance. See the picture below.

I used an Azure SQL database for my example. If you don't have one around. Try the free sample database AdventureWorks in Azure SQL Server. AdventureWorks sample databases - SQL Server | Microsoft Learn

Once you have selected a data source you can select the cool parts.
The Cognitive Skills.
If you want to test it properly, I recommend that you create an AI service resource. (see image) But be aware of the pricingPricing - AI Services All-In-One | Microsoft Azure
If you choose the Free option, your indexer is very limited and you can only find a few examples back in your search results.

Here you can find some detailed information on how an indexer works (Indexer overview - Azure Cognitive Search | Microsoft Learn).

In the next tab were are able to add enrichments. These enrichments are basically the add-ons that the new Azure Cognitive Search can provide on your documents, texts, images, etc. Click on the Skills to add them to the service. The Field name represents the name in which the results will be shown.

For this, it uses the AI Skills mentioned above.  AI enrichment concepts - Azure Cognitive Search | Microsoft Learn

  • Apply translation and language detection for multi-lingual search
  • Apply entity recognition to extract people's names, places, and other entities from large chunks of text
  • Apply key phrase extraction to identify and output important terms
  • Apply Optical Character Recognition (OCR) to recognize printed and handwritten text in binary files
  • Apply image analysis to describe image content, and output the descriptions as searchable text fields

Let's hook up some code

string indexName = "azuresql-index";
string searchServiceEndPoint = "https://<<SERVICENAME>>.search.windows.net";
string adminApiKey = "<<YOUR KEY>>";

var indexClient = new SearchIndexClient(new Uri(searchServiceEndPoint), new AzureKeyCredential(adminApiKey));
var searchClient = indexClient.GetSearchClient(indexName);

var response = await _searchClient.SearchAsync<Product>(searchText: SearchModel?.SearchParam);
 
var results = response.Value.GetResultsAsync();

await foreach (var page in results.AsPages())
{
  var pageList = page.Values;
  Products = pageList.Select(x => x.Document).ToList();
}

Let's try the automatic translation

So after indexing and using the search it automatically found the text mentioning "Bike" and saw that it was not English, but Thai. Now I used the English word "Bike" and in the Thai text, it found Bike. Awesome!.

Let's try another example.

In the example above you can see an example of the "Key Phrase Extraction" function. The indexer will automatically recognize the importance of the search phrase in certain documents that I have uploaded to my blob storage. So it's not just a simple word search for every document, in which the search phrase has been mentioned.

Azure Cognitive Search is a gateway, to company data, for Azure OpenAI services.

Besides the fact that ACS can help you document all kinds of data stores, it can also connect to Azure OpenAI services. Azure OpenAI Service – Advanced Language Models | Microsoft Azure. When connected you can use all kinds of Azure OpenAI services that help you find the information that you need or help you with your work based on company information that has been indexed by ACS. For example, you can create a chatbot, which is created based on the gpt-35-turbo model.

So let's test this by adding a document to my blob storage.
Inside that document, we put the following text.
Allard is 36 years old and lives in Zeewolde. In his free time, he loves to spend time on the computer trying new stuff out. His best friend is his son Logan. Logan and Allard love to play on the Xbox together.

When uploaded to our blobstorage and the document is fully indexed by ACS we can ask our Chat GPT about Allard since our AI model is connected to our search instance.

How about that? This can be really helpful inside your organization if you are looking for something inside that enormous amount of company data. But we are just scratching the service here. In the next blog, we are gonna dive deeper into Vector search.

References

Introduction to Azure Cognitive Search - Azure Cognitive Search
Azure Cognitive Search is a fully managed cloud search service from Microsoft. Learn about use cases, the development workflow, comparisons to other Microsoft search products, and how to get started.
Built-in skills - Azure Cognitive Search
Data extraction, natural language, and image processing skills add semantics and structure to raw content in an Azure Cognitive Search enrichment pipeline.
AI enrichment concepts - Azure Cognitive Search
Content extraction, natural language processing (NLP), and image processing can create searchable content in Azure Cognitive Search indexes.
Indexer overview - Azure Cognitive Search
Crawl Azure SQL Database, SQL Managed Instance, Azure Cosmos DB, or Azure storage to extract searchable data and populate an Azure Cognitive Search index.
Revolutionize your Enterprise Data with ChatGPT: Next-gen Apps w/ Azure OpenAI and Cognitive Search
Read about combining large language models and your own data to create new app experiences.