About Me

My photo
I am an MCSE in Data Management and Analytics, specializing in MS SQL Server, and an MCP in Azure. With over 19+ years of experience in the IT industry, I bring expertise in data management, Azure Cloud, Data Center Migration, Infrastructure Architecture planning, as well as Virtualization and automation. I have a deep passion for driving innovation through infrastructure automation, particularly using Terraform for efficient provisioning. If you're looking for guidance on automating your infrastructure or have questions about Azure, SQL Server, or cloud migration, feel free to reach out. I often write to capture my own experiences and insights for future reference, but I hope that sharing these experiences through my blog will help others on their journey as well. Thank you for reading!

Enriching Customer Reviews Using Azure AI Search: A Step-by-Step Guide with Azure Storage and Skillset

 






Enriching Customer Reviews Using Azure AI Search: A Step-by-Step Guide with Azure Storage and Skillset


Introduction:

In today's fast-paced business environment, gaining insights from unstructured data such as customer reviews can be a game-changer. Azure AI Search offers an easy-to-implement, scalable solution for transforming raw data into meaningful information. In this blog, we will go through a detailed step-by-step guide to building an Azure AI Search solution, including setting up a storage account, creating a container, and uploading a JSON file to Azure Blob Storage.

We will also show how to use Azure AI Search skillsets to perform Sentiment Analysis and Key Phrase Extraction on customer reviews.


Table of Contents:

  1. Introduction to Azure AI Search
  2. Step 1: Create an Azure Storage Account
  3. Step 2: Create a Container and Upload JSON Data
  4. Step 3: Create Azure AI Search Service
  5. Step 4: Create an Index in Azure AI Search
  6. Step 5: Create a Data Source in Azure Blob Storage
  7. Step 6: Define a Skillset for Sentiment Analysis and Key Phrase Extraction
  8. Step 7: Create and Run an Indexer
  9. Step 8: Query the Enriched Index
  10. Conclusion

1. Introduction to Azure AI Search

Azure AI Search allows you to index large datasets and apply AI-powered enrichments. With this service, you can build scalable and intelligent search solutions that provide actionable insights from your data.

In this example, we will take a dataset of customer reviews stored in Azure Blob Storage and use Sentiment Analysis and Key Phrase Extraction skills to enrich the data.


2. Step 1: Create an Azure Storage Account

To start, you need a storage account where we will store the customer reviews in JSON format.

Azure Portal Steps:

  1. Go to Azure Portal and search for Storage Account.
  2. Click on Create, choose your subscription and resource group, and give your storage account a name (e.g., customerreviewsstorage).
  3. Choose a region and set Performance to Standard and Replication to Locally Redundant Storage (LRS).
  4. Click Review + Create, then click Create.

Azure CLI Command:

bash

az storage account create --name customerreviewsstorage --resource-group <your-resource-group> --location eastus --sku Standard_LRS

3. Step 2: Create a Container and Upload JSON Data

Once your storage account is created, you need to create a container and upload the customer review data in JSON format.

Azure Portal Steps:

  1. Navigate to your newly created storage account.
  2. Go to Containers and click + Container to create a new container. Name it customer-reviews and set the public access level to Private.
  3. Once the container is created, click on the container and select Upload to upload the JSON file.

Example JSON Data (Customer Reviews):

json

[ { "customerId": "12345", "review": "The delivery was fast and the service was excellent!", "date": "2024-09-30" }, { "customerId": "67890", "review": "The product was not as described, and delivery was delayed.", "date": "2024-09-29" } ]

Azure CLI Commands:

To create a container and upload the JSON file using Azure CLI, use the following commands:

bash

# Create a container in your storage account az storage container create --name customer-reviews --account-name customerreviewsstorage # Upload the JSON file to the container az storage blob upload --container-name customer-reviews --name reviews.json --file ./reviews.json --account-name customerreviewsstorage

4. Step 3: Create Azure AI Search Service

Next, we’ll create an Azure AI Search service.

Azure Portal Steps:

  1. Search for Cognitive Search in the Azure Portal.
  2. Click Create, select your resource group, choose a region, and set the Pricing Tier to Standard.
  3. Click Review + Create to create the service.

Azure CLI Command:

bash

az search service create --name <your-search-service-name> --resource-group <your-resource-group> --sku standard

5. Step 4: Create an Index in Azure AI Search

Now, let’s define an index that will store the enriched customer review data.

Azure Portal Steps:

  1. In your Azure AI Search dashboard, go to Indexes and click Create Index.
  2. Define the index fields as follows:
    • customerId (String, key field)
    • review (String, searchable)
    • date (DateTime, sortable and filterable)

Index Definition (JSON):

json

{ "name": "customer-reviews-index", "fields": [ { "name": "customerId", "type": "Edm.String", "key": true }, { "name": "review", "type": "Edm.String", "searchable": true }, { "name": "date", "type": "Edm.DateTimeOffset", "sortable": true, "filterable": true } ] }

6. Step 5: Create a Data Source in Azure Blob Storage

We will now create a Data Source that connects to the Azure Blob Storage where our customer review JSON file is stored.

Azure Portal Steps:

  1. Go to Data Sources in the Azure AI Search dashboard.
  2. Click Create Data Source, select Azure Blob Storage, and provide your storage account and container details.

Azure CLI Command:

bash

az search datasource create --name customer-reviews-datasource --service-name <your-search-service-name> --container-name customer-reviews --storage-account customerreviewsstorage

7. Step 6: Define a Skillset for Sentiment Analysis and Key Phrase Extraction

We will now create a Skillset that applies Sentiment Analysis and Key Phrase Extraction to our customer reviews.

Azure Portal Steps:

  1. Go to Skillsets and click Create Skillset.
  2. Add two skills:
    • Sentiment Analysis: Analyzes the sentiment of each review.
    • Key Phrase Extraction: Extracts key phrases from the review text.

Skillset Definition (JSON):

json

{ "name": "customer-reviews-skillset", "skills": [ { "@odata.type": "#Microsoft.Skills.Text.SentimentSkill", "name": "sentiment-analysis-skill", "context": "/document/review", "outputs": [ { "name": "score", "targetName": "sentimentScore" } ] }, { "@odata.type": "#Microsoft.Skills.Text.KeyPhraseExtractionSkill", "name": "keyphrase-extraction-skill", "context": "/document/review", "outputs": [ { "name": "keyPhrases", "targetName": "keyPhrases" } ] } ] }

8. Step 7: Create and Run an Indexer

The Indexer will extract data from Blob Storage, apply the skillset, and store the enriched data in the index.

Azure Portal Steps:

  1. Go to Indexers and click Create Indexer.
  2. Select the data source, index, and skillset created in the previous steps.
  3. Set a schedule or run the indexer manually.

Indexer Definition (JSON):

json

{ "name": "customer-reviews-indexer", "dataSourceName": "customer-reviews-datasource", "targetIndexName": "customer-reviews-index", "skillsetName": "customer-reviews-skillset", "schedule": { "interval": "PT2H" } }

Azure CLI Command:

bash

az search indexer create --name customer-reviews-indexer --service-name <your-search-service-name> --datasource-name customer-reviews-datasource --target-index customer-reviews-index --skillset-name customer-reviews-skillset

9. Step 8: Query the Enriched Index

Once the indexer runs, the customer reviews will be enriched with sentiment scores and key phrases. You can now query the index using the Azure AI Search REST API.

Query Example (REST API):

bash

POST https://<your-search-service-name>.search.windows.net/indexes/customer-reviews-index/docs/search?api-version=2021-04-30-Preview Content-Type: application/json api-key: <your-api-key> { "search": "*", "filter": "sentimentScore gt 0.9", "select": "customerId, review, sentimentScore, keyPhrases" }

This query will return all customer reviews with a sentimentScore greater than 0.9.


Conclusion:

In this blog, we walked through the complete process of setting up a search solution using Azure AI Search. We created a storage account, added customer reviews in JSON format, and enriched them with Sentiment Analysis and Key Phrase Extraction using Azure AI Search’s Skillset feature.

By following these steps, you can build a powerful search and insight-driven solution for your data. Explore further by adding more skills, such as language detection or custom AI models, to gain even deeper insights!

Feel free to try it out and expand on this solution to meet your specific business needs.

No comments: