{"id":13774842,"url":"https://github.com/Azure-Samples/azure-sql-db-session-recommender","last_synced_at":"2025-05-11T07:30:44.889Z","repository":{"id":201014682,"uuid":"694432089","full_name":"Azure-Samples/azure-sql-db-session-recommender","owner":"Azure-Samples","description":"Build a recommender using OpenAI, Azure Functions, Azure Static Web Apps, Azure SQL DB, Data API builder and Text Embeddings","archived":false,"fork":false,"pushed_at":"2024-03-18T01:12:31.000Z","size":589,"stargazers_count":49,"open_issues_count":1,"forks_count":42,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-09T14:12:20.808Z","etag":null,"topics":["azure-functions","azure-sql-db","azure-static-web-apps","data-api-builder","embeddings","event-driven","fullstack","jamstack","open-ai","vectors"],"latest_commit_sha":null,"homepage":"https://aka.ms/dotnetconf2023-session-finder","language":"Bicep","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Azure-Samples.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-21T01:43:08.000Z","updated_at":"2024-11-13T18:02:22.000Z","dependencies_parsed_at":"2023-10-23T20:36:43.668Z","dependency_job_id":"3657bb06-7a79-45f8-bfd3-7e39a6680bf4","html_url":"https://github.com/Azure-Samples/azure-sql-db-session-recommender","commit_stats":null,"previous_names":["azure-samples/azure-sql-db-session-recommender"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure-Samples%2Fazure-sql-db-session-recommender","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure-Samples%2Fazure-sql-db-session-recommender/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure-Samples%2Fazure-sql-db-session-recommender/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure-Samples%2Fazure-sql-db-session-recommender/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Azure-Samples","download_url":"https://codeload.github.com/Azure-Samples/azure-sql-db-session-recommender/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253533062,"owners_count":21923358,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["azure-functions","azure-sql-db","azure-static-web-apps","data-api-builder","embeddings","event-driven","fullstack","jamstack","open-ai","vectors"],"created_at":"2024-08-03T17:01:30.875Z","updated_at":"2025-05-11T07:30:44.507Z","avatar_url":"https://github.com/Azure-Samples.png","language":"Bicep","funding_links":[],"categories":["Code Samples"],"sub_categories":["Vectors"],"readme":"---\npage_type: sample\nlanguages:\n- azdeveloper\n- csharp\n- sql\n- tsql\n- javascript\n- html\n- bicep\nproducts:\n- azure-functions\n- azure-sql-database\n- static-web-apps\n- sql-server\n- azure-sql-managed-instance\n- azure-sqlserver-vm\n- dotnet\n- azure-openai\nurlFragment: azure-sql-db-session-recommender\nname: Session Recommender using Azure SQL DB, Open AI and Vector Search\ndescription: Build a session recommender using Jamstack and Event-Driven architecture, using Azure SQL DB to store and search vectors embeddings generated using OpenAI\n---\n\u003c!-- YAML front-matter schema: https://review.learn.microsoft.com/en-us/help/contribute/samples/process/onboarding?branch=main#supported-metadata-fields-for-readmemd --\u003e\n\n# Session Recommender Sample\n\n![Architecture Diagram](./_docs/session-recommender-architecture.png)\n\nA session recommender built using\n\n- [Azure Static Web Apps](https://learn.microsoft.com/en-us/azure/static-web-apps/overview)\n- [Azure OpenAI](https://learn.microsoft.com/en-us/azure/ai-services/openai/)\n- [Azure Functions](https://learn.microsoft.com/en-us/azure/azure-functions/functions-overview?pivots=programming-language-csharp)\n- [Azure SQL Database](https://www.sqlservercentral.com/articles/the-sql-developer-experience-beyond-rdbms)\n- [Data API builder](https://aka.ms/dab)\n\nFor more details on the solution check also the following articles:\n\n- [How I built a session recommender in 1 hour using Open AI](https://dev.to/azure/how-i-built-a-session-recommender-in-1-hour-using-open-ai-5419)\n- [Vector Similarity Search with Azure SQL database and OpenAI](https://devblogs.microsoft.com/azure-sql/vector-similarity-search-with-azure-sql-database-and-openai/)\n\n## Retrieval Augmented Generation (RAG)\n\nAn enhanced version of this sample, that also include Retrieval Augmented Generation (RAG), is available at this repository: https://github.com/Azure-Samples/azure-sql-db-session-recommender-v2. If you are new to similarity search and RAG, it is recommended to start with this repo and then move to the enhanced one.\n\n# Deploy the sample using the Azure Developer CLI (azd) template\n\nThe Azure Developer CLI (`azd`) is a developer-centric command-line interface (CLI) tool for creating Azure applications.\n\n## Prerequisites\n\n- Install [AZD CLI](https://learn.microsoft.com/azure/developer/azure-developer-cli/install-azd).\n- Install [.NET SDK](https://dotnet.microsoft.com/download).\n- Install [Node.js](https://nodejs.org/download/).\n- Install [SWA CLI](https://azure.github.io/static-web-apps-cli/docs/use/install#installing-the-cli).\n\n## Install AZD CLI\n\nYou need to install it before running and deploying with the Azure Developer CLI.\n\n### Windows\n\n```powershell\npowershell -ex AllSigned -c \"Invoke-RestMethod 'https://aka.ms/install-azd.ps1' | Invoke-Expression\"\n```\n\n### Linux/MacOS\n\n```bash\ncurl -fsSL https://aka.ms/install-azd.sh | bash\n```\n\nAfter logging in with the following command, you will be able to use azd cli to quickly provision and deploy the application.\n\n## Authenticate with Azure\n\nMake sure AZD CLI can access Azure resources. You can use the following command to log in to Azure:\n\n```bash\nazd auth login\n```\n\n## Initialize the template\n\nThen, execute the `azd init` command to initialize the environment (You do not need to run this command if you already have the code or have opened this in a Codespace or DevContainer).\n\n```bash\nazd init -t Azure-Samples/azure-sql-db-session-recommender\n```\n\nEnter an environment name.\n\n## Deploy the sample\n\nRun `azd up` to provision all the resources to Azure and deploy the code to those resources.\n\n```bash\nazd up \n```\n\nSelect your desired `subscription` and `location`. Then choose a resource group or create a new resource group. Wait a moment for the resource deployment to complete, click the Website endpoint and you will see the web app page.\n\n**Note**: Make sure to pick a region where all services are available like, for example, *West Europe* or *East US 2*\n\n## GitHub Actions\n\nUsing the Azure Developer CLI, you can setup your pipelines, monitor your application, test and debug locally.\n\n```bash\nazd pipeline config\n```\n\n## Test the solution\n\nAdd a new row to the `Sessions` table using the following SQL statement (you can use tools like [Azure Data Studio](https://learn.microsoft.com/en-us/azure-data-studio/quickstart-sql-database) or [SQL Server Management Studio](https://learn.microsoft.com/en-us/azure/azure-sql/database/connect-query-ssms?view=azuresql) to connect to the database. No need to install them if you don't want. In that case you can use the [SQL Editor in the Azure Portal](https://learn.microsoft.com/en-us/azure/azure-sql/database/connect-query-portal?view=azuresql)):\n\n```sql\ninsert into web.sessions \n    (title, abstract)\nvalues\n    ('Building a session recommender using OpenAI and Azure SQL', 'In this fun and demo-driven session you’ll learn how to integrate Azure SQL with OpenAI to generate text embeddings, store them in the database, index them and calculate cosine distance to build a session recommender. And once that is done, you’ll publish it as a REST and GraphQL API to be consumed by a modern JavaScript frontend. Sounds pretty cool, uh? Well, it is!')\n```\n\nimmediately the deployed Azure Function will get executed in response to the `INSERT` statement. The Azure Function will call the OpenAI service to generate the text embedding for the session title and abstract, and then store the embedding in the database, specifically in the `web.session_abstract_embeddings` table.\n\n```sql\nselect * from web.session_abstract_embeddings\n```\n\nYou can now open the URL associated with the created Static Web App to see the session recommender in action. You can get the URL from the Static Web App overview page in the Azure portal.\n\n![Website running](./_docs/session-recommender.png)\n\n## Run the solution locally\n\nThe whole solution can be executed locally, using [Static Web App CLI](https://github.com/Azure/static-web-apps-cli) and [Azure Function CLI](https://learn.microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=windows%2Cisolated-process%2Cnode-v4%2Cpython-v2%2Chttp-trigger%2Ccontainer-apps\u0026pivots=programming-language-csharp).\n\nInstall the required node packages needed by the fronted:\n\n```bash\ncd client\nnpm install\n```\n\nonce finished, create a `./func/local.settings.json` and `.env` starting from provided samples files, and fill out the settings using the correct values for your environment.\n\nFrom the sample root folder run:\n\n```bash\nswa start --app-location ./client --data-api-location ./swa-db-connections/\n```\n\n## (Optional) Use a custom authentication provider with Static Web Apps\n\nThe folder `api` contains a sample function to customize the authentication process as described in the [Custom authentication in Azure Static Web Apps](https://learn.microsoft.com/en-us/azure/static-web-apps/authentication-custom?tabs=aad%2Cinvitations#configure-a-custom-identity-provider) article. The function will add any user with a `@microsoft.com` to the `microsoft` role. Data API builder can be configured to allow acceess to a certain API only to users with a certain role, for example:\n\n```json\n\"permissions\": [\n    {\n        \"role\": \"microsoft\",\n        \"actions\": [{\n            \"action\": \"execute\"\n        }]\n    }\n]\n```\n\nThis step is optional and is provided mainly as an example on how to use custom authentication with SWA and DAB. It is not used in the solution.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAzure-Samples%2Fazure-sql-db-session-recommender","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAzure-Samples%2Fazure-sql-db-session-recommender","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAzure-Samples%2Fazure-sql-db-session-recommender/lists"}