Coder Social home page Coder Social logo

azure-samples / azure-sql-db-session-recommender-v2 Goto Github PK

View Code? Open in Web Editor NEW
22.0 11.0 12.0 1.35 MB

Build a Retrieval Augmented Generation solution using OpenAI, Azure Functions, Azure Static Web Apps, Azure SQL DB, Data API builder and Text Embeddings

Home Page: https://ai.microsofthq.vslive.com/

License: MIT License

JavaScript 0.45% HTML 1.86% TypeScript 17.90% TSQL 5.70% C# 11.61% Bicep 61.18% Shell 1.30%
azure-functions azure-sql azure-sql-database data-api-builder open-ai retrieval-augmented-generation vectors

azure-sql-db-session-recommender-v2's Introduction

page_type languages products urlFragment name description
sample
azdeveloper
csharp
sql
tsql
javascript
html
bicep
azure-functions
azure-sql-database
static-web-apps
sql-server
azure-sql-managed-instance
azure-sqlserver-vm
azure-openai
azure-sql-db-session-recommender-v2
Retrieval Augmented Generation with Azure SQL DB and OpenAI
Build a session recommender using Jamstack and Event-Driven architecture, using Azure SQL DB to store and search vectors embeddings generated using OpenAI

Session Assistant Sample - Retrieval Augmented Generation with Azure SQL DB and OpenAI

This sample demonstrates how to build a session recommender using Jamstack and Event-Driven architecture, using Azure SQL DB to store and search vectors embeddings generated using OpenAI. The solution is built using Azure Static Web Apps, Azure Functions, Azure SQL Database, and Azure OpenAI.

A fully working, production ready, version of this sample, that has been used at VS Live conferences, is available here: https://icy-beach-0b0dc380f.5.azurestaticapps.net/

Retrieval Augmented Generator flow

This repository is a evoution of the Session Recommender sample. In addition to vector search, also Retrieval Augmented Generation (RAG) is used to generate the response to the user query. If you are completely new to this topic, you may want to start there, and then come back here.

Architecture Diagram

A session recommender built using

For more details on the solution check also the following articles:

Native or Classic ?

Azure SQL database can be used to easily and quickly perform vector similarity search. There are two options for this: a native option and a classic option.

The native option uses the new Vector Functions, recently introduced in Azure SQL database. Vector Functions are a set of functions that can be used to perform vector operations directly in the database.

Note

Vector Functions are in Early Adopter Preview. Get access to the preview via https://aka.ms/azuresql-vector-eap-announcement

The classic option uses the classic T-SQL to perform vector operations, with the support for columnstore indexes for getting good performances.

Important

This branch (the main branch) uses the native vector support in Azure SQL. If you want to use the classic T-SQL, switch to the classic branch.

Deploy the sample using the Azure Developer CLI (azd) template

The Azure Developer CLI (azd) is a developer-centric command-line interface (CLI) tool for creating Azure applications.

Prerequisites

Install AZD CLI

You need to install it before running and deploying with the Azure Developer CLI.

Windows

powershell -ex AllSigned -c "Invoke-RestMethod 'https://aka.ms/install-azd.ps1' | Invoke-Expression"

Linux/MacOS

curl -fsSL https://aka.ms/install-azd.sh | bash

After logging in with the following command, you will be able to use azd cli to quickly provision and deploy the application.

Authenticate with Azure

Make sure AZD CLI can access Azure resources. You can use the following command to log in to Azure:

azd auth login

Initialize the template

Then, 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).

azd init -t Azure-Samples/azure-sql-db-session-recommender-v2

Enter an environment name.

Deploy the sample

Run azd up to provision all the resources to Azure and deploy the code to those resources.

azd up 

Select 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.

Note: Make sure to pick a region where all services are available like, for example, West Europe or East US 2

GitHub Actions

Using the Azure Developer CLI, you can setup your pipelines, monitor your application, test and debug locally.

azd pipeline config

Deploy the database

Since the database is using features that are in Private Preview, it must be deployed manually. After all resources have been deployed, get the database connection string and OpenAI endpoint and key and create a .env file from the .env.sample file. Once that is done, go into the database folder and run the following command:

dotnet run

The .NET application will create the database schema and the required objects.

Test the solution

Add a new row to the Sessions table using the following SQL statement (you can use tools like Azure Data Studio or SQL Server Management Studio 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):

insert into web.speakers
    (id, full_name, require_embeddings_update)
values
    (5000, 'John Doe', 1)
go

insert into web.sessions 
    (id, title, abstract, external_id, start_time, end_time, require_embeddings_update)
values
    (
        1000,
        '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!',
        'S1',
        '2024-06-01 10:00:00',
        '2024-06-01 11:00:00',
        1
    )
go

insert into web.sessions_speakers
    (session_id, speaker_id)
values
    (1000, 5000)
go

immediately 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.sessions_embeddings table.

select * from web.sessions_embeddings

You 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.

Website running

Run the solution locally

The whole solution can be executed locally, using Static Web App CLI and Azure Function CLI.

Install the required node packages needed by the fronted:

cd client
npm install

once 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.

Go back to the sample root folder and then run:

swa start 

and once the local Static Web App environment is running, you can connect to

http://localhost:4280/

and test the solution locally.

Fluent UI

The solution uses Fluent UI for the UI components. The Fluent UI is a collection of UX frameworks from Microsoft that provides a consistent design language for web, mobile, and desktop applications. More details about Fluent UI can be found at the following links:

Credits

Thanks a lot to Aaron Powell for having helped in building the RAG sample, doing a complete UI revamp using the Fluent UI and for the implementaiton of the ask endpoint.

azure-sql-db-session-recommender-v2's People

Contributors

jianingwang123 avatar microsoft-github-operations[bot] avatar microsoftopensource avatar yorek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

azure-sql-db-session-recommender-v2's Issues

using docker - devcontainer fails azd up with MSBuild version 17.7.4+3ebbd7c49 for .NET

Please provide us with the following information:

This issue is for a: (mark with an x)

- [X ] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

open dev ocntainer on windows azd login and then azd up

Any log messages given by the failure

Packaging services (azd package)

(x) Failed: Packaging service functionapp

ERROR: failed packaging service 'functionapp': failing invoking action 'package', dotnet >publish on project '/workspaces/azure-sql-db-session-recommender-v2->1/func/RequestHandler.csproj' failed: exit code: 1, stdout: MSBuild version 17.7.4+3ebbd7c49 >or .NET
Determining projects to restore...

/usr/share/dotnet/sdk/7.0.406/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFramewor
kInference.targets(160,5): error NETSDK1045: The current .NET SDK does not support >targeting .NET 8.0. Either target .NET 7.0 or lower, or use a version of the .NET SDK that >supports .NET 8.0. Download the .NET SDK from https://aka.ms/dotnet/download
[/workspaces/azure-sql-db-session-recommender-v2-1/func/RequestHandler.csproj]
, stderr:

ERROR: error executing step command 'package --all': failed packaging service 'functionapp': >failing invoking action 'package', dotnet publish on project '/workspaces/azure-sql-db->session-recommender-v2-1/func/RequestHandler.csproj' failed: exit code: 1, stdout: MSBuild >version 17.7.4+3ebbd7c49 for .NET
Determining projects to restore...
/usr/share/dotnet/sdk/7.0.406/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFramewor>kInference.targets(160,5): error NETSDK1045: The current .NET SDK does not support targeting >.NET 8.0. Either target .NET 7.0 or lower, or use a version of the .NET SDK that supports .NET >8.0. Download the .NET SDK from https://aka.ms/dotnet/download [/workspaces/azure-sql->db-session-recommender-v2-1/func/RequestHandler.csproj]
, stderr:
vscode ➜ /workspaces/azure-sql-db-session-recommender-v2-1 (main) $

Expected/desired behavior

OS and Version?

Windows 11 23H2

Versions

Mention any other details that might be useful


Thanks! We'll be in touch soon.

using podman dev container fails with E: Unable to locate package azure-functions-core-tools-4

Please provide us with the following information:

This issue is for a: (mark with an x)

- [X ] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

Using podman rootful or rootless or docker with repo cloned on Windows 11

Any log messages given by the failure

Expected/desired behavior

OS and Version?

Windows 11 23H2 22631.3235
PODMAN

Versions

Mention any other details that might be useful

ERROR [dev_container_auto_added_stage_label 2/2] RUN curl https://packages.microsoft.com/keys/microsoft.a  35.5s
------
 > [dev_container_auto_added_stage_label 2/2] RUN curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dear
mor > microsoft.gpg     && mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg     && sh -c 'echo "deb [arch=amd64]
 https://packages.microsoft.com/debian/$(lsb_release -rs | cut -d'.' -f 1)/prod $(lsb_release -cs) main" > /etc/apt/s
o`urces.list.d/dotnetdev.list'     && apt-get update && apt-get install -y azure-functions-core-tools-4     && apt-get
 clean -y && rm -rf /var/lib/apt/lists/*:
0.260   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
0.260                                  Dload  Upload   Total   Spent    Left  Speed
100   983  100   983    0     0    397      0  0:00:02  0:00:02 --:--:--   397
3.002 Get:1 http://deb.debian.org/debian bullseye InRelease [116 kB]
3.074 Get:2 http://deb.debian.org/debian-security bullseye-security InRelease [48.4 kB]
3.102 Get:3 http://deb.debian.org/debian bullseye-updates InRelease [44.1 kB]
3.286 Get:4 http://deb.debian.org/debian bullseye/main amd64 Packages [8068 kB]
3.765 Get:5 http://deb.debian.org/debian-security bullseye-security/main amd64 Packages [269 kB]
3.781 Get:6 http://deb.debian.org/debian bullseye-updates/main amd64 Packages [18.8 kB]
6.561 Get:7 https://dl.yarnpkg.com/debian stable InRelease [17.1 kB]
6.684 Get:8 https://dl.yarnpkg.com/debian stable/main all Packages [10.9 kB]
6.720 Get:9 https://dl.yarnpkg.com/debian stable/main amd64 Packages [10.9 kB]
33.00 Err:10 https://packages.microsoft.com/debian/11/prod bullseye InRelease
33.00   Could not wait for server fd - select (11: Resource temporarily unavailable) [IP: 13.107.213.64 443]
33.02 Fetched 8603 kB in 30s (286 kB/s)
33.02 Reading package lists...
33.89 W: Failed to fetch https://packages.microsoft.com/debian/11/prod/dists/bullseye/InRelease  Could not wait for s
erver fd - select (11: Resource temporarily unavailable) [IP: 13.107.213.64 443]
33.89 W: Some index files failed to download. They have been ignored, or old ones used instead.
33.92 Reading package lists...
34.67 Building dependency tree...
34.97 Reading state information...
35.44 E: Unable to locate package azure-functions-core-tools-4
------
Dockerfile-with-features:5
--------------------
   4 |     FROM --platform=amd64 mcr.microsoft.com/devcontainers/${IMAGE} AS dev_container_auto_added_stage_label
   5 | >>> RUN curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg \
   6 | >>>     && mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg \
   7 | >>>     && sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/debian/$(lsb_release -rs | cut -d'.' -
f 1)/prod $(lsb_release -cs) main" > /etc/apt/sources.list.d/dotnetdev.list' \
   8 | >>>     && apt-get update && apt-get install -y azure-functions-core-tools-4 \
   9 | >>>     && apt-get clean -y && rm -rf /var/lib/apt/lists/*
  10 |
--------------------
ERROR: failed to solve: process "/bin/sh -c curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor >
microsoft.gpg     && mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg     && sh -c 'echo \"deb [arch=amd64] http
s://packages.microsoft.com/debian/$(lsb_release -rs | cut -d'.' -f 1)/prod $(lsb_release -cs) main\" > /etc/apt/sourc
es.list.d/dotnetdev.list'     && apt-get update && apt-get install -y azure-functions-core-tools-4     && apt-get cle
an -y && rm -rf /var/lib/apt/lists/*" did not complete successfully: exit code: 100
[878241 ms] Error: Command failed: docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f C:\\AppData\Local\Temp\devcontainercli\container-features\0.56.2-1710777329920\Dockerfile-with-features -t vsc-azure-sql-db-session-recommender-v2-c360c9271e01c7daa29b5aa1e8d317eeae8192529bdd0c1a8ae3a4c7efeddb11 --target dev_containers_target_stage --build-arg IMAGE=dotnet:7.0-bullseye --build-context dev_containers_feature_content_source=C:\\AppData\Local\Temp\devcontainercli\container-features\0.56.2-1710777329920 --build-arg _DEV_CONTAINERS_BASE_IMAGE=dev_container_auto_added_stage_label --build-arg _DEV_CONTAINERS_IMAGE_USER=root --build-arg _DEV_CONTAINERS_FEATURE_CONTENT_SOURCE=dev_container_feature_content_temp c:\\OneDrive\Documents\GitHub\ClonedForked\azure-sql-db-session-recommender-v2\.devcontainer
[878242 ms]     at BtA (\.vscode\extensions\ms-vscode-remote.remote-containers-0.348.0\dist\spec-node\devContainersSpecCLI.js:465:1933)
[878242 ms]     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
[878242 ms]     at async K0 (\.vscode\extensions\ms-vscode-remote.remote-containers-0.348.0\dist\spec-node\devContainersSpecCLI.js:464:1841)
[878242 ms]     at async yH (\.vscode\extensions\ms-vscode-remote.remote-containers-0.348.0\dist\spec-node\devContainersSpecCLI.js:464:610)
[878242 ms]     at async StA (\.vscode\extensions\ms-vscode-remote.remote-containers-0.348.0\dist\spec-node\devContainersSpecCLI.js:481:3660)
[878243 ms]     at async ZC (\.vscode\extensions\ms-vscode-remote.remote-containers-0.348.0\dist\spec-node\devContainersSpecCLI.js:481:4775)
[878243 ms]     at async trA (\.vscode\extensions\ms-vscode-remote.remote-containers-0.348.0\dist\spec-node\devContainersSpecCLI.js:614:11269)
[878243 ms]     at async erA (\.vscode\extensions\ms-vscode-remote.remote-containers-0.348.0\dist\spec-node\devContainersSpecCLI.js:614:11010)
[878310 ms] Exit code 1
[878326 ms] Command failed: C:\Program Files\Microsoft VS Code\Code.exe \.vscode\extensions\ms-vscode-remote.remote-containers-0.348.0\dist\spec-node\devContainersSpecCLI.js up --user-data-folder AppData\Roaming\Code\User\globalStorage\ms-vscode-remote.remote-containers\data --container-session-data-folder /tmp/devcontainers-9763582c-9822-48a9-8d59-855913d3e22a1710776938680 --workspace-folder redacted\azure-sql-db-session-recommender-v2 --workspace-mount-consistency cached --id-label devcontainer.local_folder=redact3ed\azure-sql-db-session-recommender-v2 --id-label devcontainer.config_file=redactedazure-sql-db-session-recommender-v2\.devcontainer\devcontainer.json --log-level debug --log-format json --config REDACTEDClonedForked\azure-sql-db-session-recommender-v2\.devcontainer\devcontainer.json --default-user-env-probe loginInteractiveShell --mount type=volume,source=vscode,target=/vscode,external=true --mount type=bind,source=\\wsl.localhost\Ubuntu\mnt\wslg\runtime-dir\wayland-0,target=/tmp/vscode-wayland-ede0854e-023c-4954-bfb5-d9b42db9c71a.sock --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root --terminal-columns 117 --terminal-rows 21
[878326 ms] Exit code 1

Thanks! We'll be in touch soon.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.