Skip to content

eShopLite - Semantic Search is a reference .NET application implementing an eCommerce site with Search features using Keyword Search and Semantic Search with Azure AI Search

License

Notifications You must be signed in to change notification settings

Azure-Samples/eShopLite-SemanticSearch-AzureAISearch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

12 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

License: MIT Twitter: elbruno GitHub: elbruno

Description

eShopLite - Semantic Search - Azure AI Search is a reference .NET application implementing an eCommerce site with Search features using Keyword Search with SQL queries, and Semantic Search with Vector Database and Azure AI Search.

Features

GitHub CodeSpaces: This project is designed to be opened in GitHub Codespaces as an easy way for anyone to deploy the solution entirely in the browser.

This is the eShopLite Aplication running, performing a Keyword Search:

eShopLite Aplication running doing search using keyworkd search

This is the eShopLite Aplication running, performing a Semantic Search:

eShopLite Aplication running doing search using keyworkd search

The Aspire Dashboard to check the running services:

Aspire Dashboard to check the running services

The Azure Resource Group with all the deployed services:

Azure Resource Group with all the deployed services

Architecture diagram

Architecture diagram

Getting Started

The solution is in the ./src folder, the main solution is eShopLite-Aspire-AzureAISearch.sln.

Deploying

Once you've opened the project in Codespaces, or locally, you can deploy it to Azure.

From a Terminal window, open the folder with the clone of this repo and run the following commands.

  1. Login to Azure:

    azd auth login
  2. Provision and deploy all the resources:

    azd up

    It will prompt you to provide an azd environment name (like "eShopLite-AzureAISearch"), select a subscription from your Azure account, and select a location where Azure AI Search and the OpenAI models gpt-4o-mini and ADA-002 are available (like "eastus2").

  3. When azd has finished deploying, you'll see the list of resources created in Azure and a set of URIs in the command output.

  4. Visit the store URI, and you should see the eShop Lite app! ๐ŸŽ‰

  5. This is an example of the command output:

Deploy Azure Complete

  1. Coming Soon! You can check this video with a 5 minutes overview of the deploy process from codespaces: Deploy Your eShopLite - Semantic Search - Azure AI Search to Azure in Minutes!.

Note: The deploy files are located in the ./src/eShopAppHost/infra/ folder. They are generated by the Aspire AppHost project.

GitHub CodeSpaces

  • Create a new Codespace using the Code button at the top of the repository.

    create Codespace

  • The Codespace creation process can take a couple of minutes.

  • Once the Codespace is loaded, it should have all the necessary requirements to deploy the solution.

Run Locally

To run the project locally, you'll need to make sure the following tools are installed:

Run the solution

Follow these steps to run the project, locally or in CodeSpaces:

  • Navigate to the Aspire Host folder project using the command:

    cd ./src/eShopAppHost/
  • If you are running the project in Codespaces, you need to run this command:

    dotnet dev-certs https --trust
  • By default the AppHost project creates the necessary resources on Azure. Check the .NET Aspire Azure Resources creation section to learn how to configure the project to create Azure resources.

  • Run the project:

    dotnet run

Check the Video Resources for a step-by-step on how to run this project.

.NET Aspire Azure Resources creation

When utilizing Azure resources in your local development environment, you need to:

  • Authenticate to the Azure Tenant where the resources will be created. Run the following command to connect with your Azure tenant:

    az login 
  • Provide the necessary Configuration values are specified under the Azure section in the eShopAppHost project:

    • CredentialSource: Delegates to the AzureCliCredential.
    • SubscriptionId: The Azure subscription ID.
    • AllowResourceGroupCreation: A boolean value that indicates whether to create a new resource group.
    • ResourceGroup: The name of the resource group to use.
    • Location: The Azure region to use.

Consider the following example for the appsettings.json file in the eShopAppHost project configuration:

{
  "Azure": {
    "CredentialSource": "AzureCli",
    "SubscriptionId": "<Your subscription id>",
    "AllowResourceGroupCreation": true,
    "ResourceGroup": "<Valid resource group name>",
    "Location": "<Valid Azure location>"
  }
}

Check .NET Aspire Azure hosting integrations for more information on how .NET Aspire create the necessary cloud resources for local development.

Analyze the Vector Store in Azure AI Search

To create and fill with data the Vector Store in Azure AI Search, you need to perform a Semantic Search in the application.

perform a Semantic Search in the application

The first search will fill the Vector Store with all the store products.

The first search will fill the Vector Store with all the store products.

When you perform a new Semantic Search, the elapsed time will be must faster than the 1st one.

the elapsed time will be must faster than the 1st one

And the trace will show:

  • The search request from store to products
  • products calling the Azure OpenAI embedding model to generate an embedding with the search criteria
  • products calling the Azure AI Search to query the vector store using the search criteria
  • products calling the Azure OpenAI chat model to generate a user friendly response

Complete trace for a standard semantic search

You can also open the Azure AI Search resource in the Azure portal, and check the created index products with the data and fields.

Azure AI Search resource in the Azure portal, and check the created index products with the data and fields

Local development using an existing services

In order to use existing Azure AI Search Services and existing Azure OpenAI models, like gpt-4o-mini and text-embedding-ada-002, you need to make changes in 2 projects:

Aspire AppHost

Open the program.cs in .\src\eShopAppHost\, and comment the main aspire lines, and uncomment the lines to only create and run the sqldb, the api project and the front end.

Comment the aspire lines and uncomment the last lines

Products

Edit and define specific connection strings in the Products project.

Add a user secret running the commands:

cd src/Products
dotnet user-secrets set "ConnectionStrings:openaidev" "Endpoint=https://<endpoint>.openai.azure.com/;Key=<Azure OpenAI Service key>;"
dotnet user-secrets set "ConnectionStrings:azureaisearchdev" "Endpoint=https://<endpoint>.search.windows.net/;Key=<Azure AI Search key>;"

Update the code to use connection strings which names are azureaisearchdev and openaidev. Change this:

// To reuse existing Azure AI Search resources, this to "azureaisearchdev", and check the documentation on how to reuse the resources
var azureAiSearchName = "azureaisearch";
builder.AddAzureSearchClient(azureAiSearchName);

// To reuse existing Azure OpenAI resources, this to "openaidev", and check the documentation on how to reuse the resources
var azureOpenAiClientName = "openai";
builder.AddAzureOpenAIClient(azureOpenAiClientName);

to this:

// To reuse existing Azure AI Search resources, this to "azureaisearchdev", and check the documentation on how to reuse the resources
var azureAiSearchName = "azureaisearchdev";
builder.AddAzureSearchClient(azureAiSearchName);

// To reuse existing Azure OpenAI resources, this to "openaidev", and check the documentation on how to reuse the resources
var azureOpenAiClientName = "openaidev";
builder.AddAzureOpenAIClient(azureOpenAiClientName);

Telemetry with .NET Aspire and Azure Application Insights

The eShopLite solution leverages the Aspire Dashboard and Azure Application Insights to provide comprehensive telemetry and monitoring capabilities

The .NET Aspire Dashboard offers a centralized view of the application's performance, health, and usage metrics. It integrates seamlessly with the Azure OpenAI services, allowing developers to monitor the performance of the gpt-4o-mini and text-embedding-ada-002 models. The dashboard provides real-time insights into the application's behavior, helping to identify and resolve issues quickly.

Aspire Dashboard

Azure Application Insights complements the Aspire Dashboard by offering deep diagnostic capabilities and advanced analytics. It collects detailed telemetry data, including request rates, response times, and failure rates, enabling developers to understand how the application is performing under different conditions. Application Insights also provides powerful querying and visualization tools, making it easier to analyze trends and detect anomalies.

Azure Application Insights

By combining the Aspire Dashboard with Azure Application Insights, the eShopLite solution ensures robust monitoring and diagnostics, enhancing the overall reliability and performance of the application.

Guidance

Costs

For Azure OpenAI Services, pricing varies per region and usage, so it isn't possible to predict exact costs for your usage. Same applies to Azure AI Search. The majority of the Azure resources used in this infrastructure are on usage-based pricing tiers. However, Azure Container Registry has a fixed cost per registry per day.

You can try the Azure pricing calculator for the resources:

  • Azure OpenAI Service: S0 tier, gpt-4o-mini and text-embedding-ada-002 models. Pricing is based on token count. Pricing
  • Azure Container App: Consumption tier with 0.5 CPU, 1GiB memory/storage. Pricing is based on resource allocation, and each month allows for a certain amount of free usage. Pricing
  • Azure Container Registry: Basic tier. Pricing
  • Log analytics: Pay-as-you-go tier. Costs based on data ingested. Pricing
  • Azure AI Search: Basic tier. You can edit the bicep files to change for the free tier.
  • Azure Application Insights pricing is based on a Pay-As-You-Go model. Pricing.

โš ๏ธ To avoid unnecessary costs, remember to take down your app if it's no longer in use, either by deleting the resource group in the Portal or running azd down.

Security Guidelines

Samples in this templates uses Azure OpenAI Services with ApiKey and Managed Identity for authenticating to the Azure OpenAI service.

The Main Sample uses Managed Identity](https://learn.microsoft.com/entra/identity/managed-identities-azure-resources/overview) for authenticating to the Azure OpenAI service.

Additionally, we have added a GitHub Action that scans the infrastructure-as-code files and generates a report containing any detected issues. To ensure continued best practices in your own repository, we recommend that anyone creating solutions based on our templates ensure that the Github secret scanning setting is enabled.

You may want to consider additional security measures, such as:

Resources

Video Recordings

Coming Soon >> Run eShopLite Semantic Search - Azure AI Search in Minutes with .NET Aspire & GitHub Codespaces ๐Ÿš€

Run eShopLite Semantic Search in Minutes with .NET Aspire & GitHub Codespaces ๐Ÿš€

About

eShopLite - Semantic Search is a reference .NET application implementing an eCommerce site with Search features using Keyword Search and Semantic Search with Azure AI Search

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks