├── .env.sample
├── .github
├── CODE_OF_CONDUCT.md
├── ISSUE_TEMPLATE.md
└── PULL_REQUEST_TEMPLATE.md
├── .gitignore
├── CHANGELOG.md
├── CONTRIBUTING.md
├── Chat.cs
├── Deploy.cs
├── LICENSE.md
├── Plugins.cs
├── Program.cs
├── README.md
├── _assets
└── azure-sql-sk-bot.png
├── azure-sql-sk.csproj
└── sql
├── 010-database.sql
├── 020-security.sql
├── 030-create-table.sql
├── 040-get_embedding.sql
├── 050-find_similar_session.sql
└── 100-sample-data.sql
/.env.sample:
--------------------------------------------------------------------------------
1 | OPENAI_URL="https://.openai.azure.com/"
2 | OPENAI_KEY=""
3 | OPENAI_EMBEDDING_DEPLOYMENT_NAME="text-embedding-3-small"
4 | OPENAI_CHAT_DEPLOYMENT_NAME="gpt-4"
5 |
6 | MSSQL_CONNECTION_STRING="Server=.database.windows.net;Database=;Authentication=Active Directory Default;Connection Timeout=90;"
7 | MSSQL_TABLE_NAME="ChatMemories"
8 |
--------------------------------------------------------------------------------
/.github/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Microsoft Open Source Code of Conduct
2 |
3 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
4 |
5 | Resources:
6 |
7 | - [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/)
8 | - [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
9 | - Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns
10 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 |
4 | > Please provide us with the following information:
5 | > ---------------------------------------------------------------
6 |
7 | ### This issue is for a: (mark with an `x`)
8 | ```
9 | - [ ] bug report -> please search issues before submitting
10 | - [ ] feature request
11 | - [ ] documentation issue or request
12 | - [ ] regression (a behavior that used to work and stopped in a new release)
13 | ```
14 |
15 | ### Minimal steps to reproduce
16 | >
17 |
18 | ### Any log messages given by the failure
19 | >
20 |
21 | ### Expected/desired behavior
22 | >
23 |
24 | ### OS and Version?
25 | > Windows 7, 8 or 10. Linux (which distribution). macOS (Yosemite? El Capitan? Sierra?)
26 |
27 | ### Versions
28 | >
29 |
30 | ### Mention any other details that might be useful
31 |
32 | > ---------------------------------------------------------------
33 | > Thanks! We'll be in touch soon.
34 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ## Purpose
2 |
3 | * ...
4 |
5 | ## Does this introduce a breaking change?
6 |
7 | ```
8 | [ ] Yes
9 | [ ] No
10 | ```
11 |
12 | ## Pull Request Type
13 | What kind of change does this Pull Request introduce?
14 |
15 |
16 | ```
17 | [ ] Bugfix
18 | [ ] Feature
19 | [ ] Code style update (formatting, local variables)
20 | [ ] Refactoring (no functional changes, no api changes)
21 | [ ] Documentation content changes
22 | [ ] Other... Please describe:
23 | ```
24 |
25 | ## How to Test
26 | * Get the code
27 |
28 | ```
29 | git clone [repo-address]
30 | cd [repo-name]
31 | git checkout [branch-name]
32 | npm install
33 | ```
34 |
35 | * Test the code
36 |
37 | ```
38 | ```
39 |
40 | ## What to Check
41 | Verify that the following are valid
42 | * ...
43 |
44 | ## Other Information
45 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Mono auto generated files
17 | mono_crash.*
18 |
19 | # Build results
20 | [Dd]ebug/
21 | [Dd]ebugPublic/
22 | [Rr]elease/
23 | [Rr]eleases/
24 | x64/
25 | x86/
26 | [Ww][Ii][Nn]32/
27 | [Aa][Rr][Mm]/
28 | [Aa][Rr][Mm]64/
29 | bld/
30 | [Bb]in/
31 | [Oo]bj/
32 | [Ll]og/
33 | [Ll]ogs/
34 |
35 | # Visual Studio 2015/2017 cache/options directory
36 | .vs/
37 | # Uncomment if you have tasks that create the project's static files in wwwroot
38 | #wwwroot/
39 |
40 | # Visual Studio 2017 auto generated files
41 | Generated\ Files/
42 |
43 | # MSTest test Results
44 | [Tt]est[Rr]esult*/
45 | [Bb]uild[Ll]og.*
46 |
47 | # NUnit
48 | *.VisualState.xml
49 | TestResult.xml
50 | nunit-*.xml
51 |
52 | # Build Results of an ATL Project
53 | [Dd]ebugPS/
54 | [Rr]eleasePS/
55 | dlldata.c
56 |
57 | # Benchmark Results
58 | BenchmarkDotNet.Artifacts/
59 |
60 | # .NET Core
61 | project.lock.json
62 | project.fragment.lock.json
63 | artifacts/
64 |
65 | # ASP.NET Scaffolding
66 | ScaffoldingReadMe.txt
67 |
68 | # StyleCop
69 | StyleCopReport.xml
70 |
71 | # Files built by Visual Studio
72 | *_i.c
73 | *_p.c
74 | *_h.h
75 | *.ilk
76 | *.meta
77 | *.obj
78 | *.iobj
79 | *.pch
80 | *.pdb
81 | *.ipdb
82 | *.pgc
83 | *.pgd
84 | *.rsp
85 | *.sbr
86 | *.tlb
87 | *.tli
88 | *.tlh
89 | *.tmp
90 | *.tmp_proj
91 | *_wpftmp.csproj
92 | *.log
93 | *.tlog
94 | *.vspscc
95 | *.vssscc
96 | .builds
97 | *.pidb
98 | *.svclog
99 | *.scc
100 |
101 | # Chutzpah Test files
102 | _Chutzpah*
103 |
104 | # Visual C++ cache files
105 | ipch/
106 | *.aps
107 | *.ncb
108 | *.opendb
109 | *.opensdf
110 | *.sdf
111 | *.cachefile
112 | *.VC.db
113 | *.VC.VC.opendb
114 |
115 | # Visual Studio profiler
116 | *.psess
117 | *.vsp
118 | *.vspx
119 | *.sap
120 |
121 | # Visual Studio Trace Files
122 | *.e2e
123 |
124 | # TFS 2012 Local Workspace
125 | $tf/
126 |
127 | # Guidance Automation Toolkit
128 | *.gpState
129 |
130 | # ReSharper is a .NET coding add-in
131 | _ReSharper*/
132 | *.[Rr]e[Ss]harper
133 | *.DotSettings.user
134 |
135 | # TeamCity is a build add-in
136 | _TeamCity*
137 |
138 | # DotCover is a Code Coverage Tool
139 | *.dotCover
140 |
141 | # AxoCover is a Code Coverage Tool
142 | .axoCover/*
143 | !.axoCover/settings.json
144 |
145 | # Coverlet is a free, cross platform Code Coverage Tool
146 | coverage*.json
147 | coverage*.xml
148 | coverage*.info
149 |
150 | # Visual Studio code coverage results
151 | *.coverage
152 | *.coveragexml
153 |
154 | # NCrunch
155 | _NCrunch_*
156 | .*crunch*.local.xml
157 | nCrunchTemp_*
158 |
159 | # MightyMoose
160 | *.mm.*
161 | AutoTest.Net/
162 |
163 | # Web workbench (sass)
164 | .sass-cache/
165 |
166 | # Installshield output folder
167 | [Ee]xpress/
168 |
169 | # DocProject is a documentation generator add-in
170 | DocProject/buildhelp/
171 | DocProject/Help/*.HxT
172 | DocProject/Help/*.HxC
173 | DocProject/Help/*.hhc
174 | DocProject/Help/*.hhk
175 | DocProject/Help/*.hhp
176 | DocProject/Help/Html2
177 | DocProject/Help/html
178 |
179 | # Click-Once directory
180 | publish/
181 |
182 | # Publish Web Output
183 | *.[Pp]ublish.xml
184 | *.azurePubxml
185 | # Note: Comment the next line if you want to checkin your web deploy settings,
186 | # but database connection strings (with potential passwords) will be unencrypted
187 | *.pubxml
188 | *.publishproj
189 |
190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
191 | # checkin your Azure Web App publish settings, but sensitive information contained
192 | # in these scripts will be unencrypted
193 | PublishScripts/
194 |
195 | # NuGet Packages
196 | *.nupkg
197 | # NuGet Symbol Packages
198 | *.snupkg
199 | # The packages folder can be ignored because of Package Restore
200 | **/[Pp]ackages/*
201 | # except build/, which is used as an MSBuild target.
202 | !**/[Pp]ackages/build/
203 | # Uncomment if necessary however generally it will be regenerated when needed
204 | #!**/[Pp]ackages/repositories.config
205 | # NuGet v3's project.json files produces more ignorable files
206 | *.nuget.props
207 | *.nuget.targets
208 |
209 | # Microsoft Azure Build Output
210 | csx/
211 | *.build.csdef
212 |
213 | # Microsoft Azure Emulator
214 | ecf/
215 | rcf/
216 |
217 | # Windows Store app package directories and files
218 | AppPackages/
219 | BundleArtifacts/
220 | Package.StoreAssociation.xml
221 | _pkginfo.txt
222 | *.appx
223 | *.appxbundle
224 | *.appxupload
225 |
226 | # Visual Studio cache files
227 | # files ending in .cache can be ignored
228 | *.[Cc]ache
229 | # but keep track of directories ending in .cache
230 | !?*.[Cc]ache/
231 |
232 | # Others
233 | ClientBin/
234 | ~$*
235 | *~
236 | *.dbmdl
237 | *.dbproj.schemaview
238 | *.jfm
239 | *.pfx
240 | *.publishsettings
241 | orleans.codegen.cs
242 |
243 | # Including strong name files can present a security risk
244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
245 | #*.snk
246 |
247 | # Since there are multiple workflows, uncomment next line to ignore bower_components
248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
249 | #bower_components/
250 |
251 | # RIA/Silverlight projects
252 | Generated_Code/
253 |
254 | # Backup & report files from converting an old project file
255 | # to a newer Visual Studio version. Backup files are not needed,
256 | # because we have git ;-)
257 | _UpgradeReport_Files/
258 | Backup*/
259 | UpgradeLog*.XML
260 | UpgradeLog*.htm
261 | ServiceFabricBackup/
262 | *.rptproj.bak
263 |
264 | # SQL Server files
265 | *.mdf
266 | *.ldf
267 | *.ndf
268 |
269 | # Business Intelligence projects
270 | *.rdl.data
271 | *.bim.layout
272 | *.bim_*.settings
273 | *.rptproj.rsuser
274 | *- [Bb]ackup.rdl
275 | *- [Bb]ackup ([0-9]).rdl
276 | *- [Bb]ackup ([0-9][0-9]).rdl
277 |
278 | # Microsoft Fakes
279 | FakesAssemblies/
280 |
281 | # GhostDoc plugin setting file
282 | *.GhostDoc.xml
283 |
284 | # Node.js Tools for Visual Studio
285 | .ntvs_analysis.dat
286 | node_modules/
287 |
288 | # Visual Studio 6 build log
289 | *.plg
290 |
291 | # Visual Studio 6 workspace options file
292 | *.opt
293 |
294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
295 | *.vbw
296 |
297 | # Visual Studio 6 auto-generated project file (contains which files were open etc.)
298 | *.vbp
299 |
300 | # Visual Studio 6 workspace and project file (working project files containing files to include in project)
301 | *.dsw
302 | *.dsp
303 |
304 | # Visual Studio 6 technical files
305 | *.ncb
306 | *.aps
307 |
308 | # Visual Studio LightSwitch build output
309 | **/*.HTMLClient/GeneratedArtifacts
310 | **/*.DesktopClient/GeneratedArtifacts
311 | **/*.DesktopClient/ModelManifest.xml
312 | **/*.Server/GeneratedArtifacts
313 | **/*.Server/ModelManifest.xml
314 | _Pvt_Extensions
315 |
316 | # Paket dependency manager
317 | .paket/paket.exe
318 | paket-files/
319 |
320 | # FAKE - F# Make
321 | .fake/
322 |
323 | # CodeRush personal settings
324 | .cr/personal
325 |
326 | # Python Tools for Visual Studio (PTVS)
327 | __pycache__/
328 | *.pyc
329 |
330 | # Cake - Uncomment if you are using it
331 | # tools/**
332 | # !tools/packages.config
333 |
334 | # Tabs Studio
335 | *.tss
336 |
337 | # Telerik's JustMock configuration file
338 | *.jmconfig
339 |
340 | # BizTalk build output
341 | *.btp.cs
342 | *.btm.cs
343 | *.odx.cs
344 | *.xsd.cs
345 |
346 | # OpenCover UI analysis results
347 | OpenCover/
348 |
349 | # Azure Stream Analytics local run output
350 | ASALocalRun/
351 |
352 | # MSBuild Binary and Structured Log
353 | *.binlog
354 |
355 | # NVidia Nsight GPU debugger configuration file
356 | *.nvuser
357 |
358 | # MFractors (Xamarin productivity tool) working folder
359 | .mfractor/
360 |
361 | # Local History for Visual Studio
362 | .localhistory/
363 |
364 | # Visual Studio History (VSHistory) files
365 | .vshistory/
366 |
367 | # BeatPulse healthcheck temp database
368 | healthchecksdb
369 |
370 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
371 | MigrationBackup/
372 |
373 | # Ionide (cross platform F# VS Code tools) working folder
374 | .ionide/
375 |
376 | # Fody - auto-generated XML schema
377 | FodyWeavers.xsd
378 |
379 | # VS Code files for those working on multiple tools
380 | .vscode/*
381 | !.vscode/settings.json
382 | !.vscode/tasks.json
383 | !.vscode/launch.json
384 | !.vscode/extensions.json
385 | *.code-workspace
386 |
387 | # Local History for Visual Studio Code
388 | .history/
389 |
390 | # Windows Installer files from build outputs
391 | *.cab
392 | *.msi
393 | *.msix
394 | *.msm
395 | *.msp
396 |
397 | # JetBrains Rider
398 | *.sln.iml
399 |
400 | # Custom
401 | .env
402 | prompts.txt
403 | *.local.sql
404 | *.env
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ## [project-title] Changelog
2 |
3 |
4 | # x.y.z (yyyy-mm-dd)
5 |
6 | *Features*
7 | * ...
8 |
9 | *Bug Fixes*
10 | * ...
11 |
12 | *Breaking Changes*
13 | * ...
14 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing to [project-title]
2 |
3 | This project welcomes contributions and suggestions. Most contributions require you to agree to a
4 | Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
5 | the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
6 |
7 | When you submit a pull request, a CLA bot will automatically determine whether you need to provide
8 | a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
9 | provided by the bot. You will only need to do this once across all repos using our CLA.
10 |
11 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
12 | For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
13 | contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
14 |
15 | - [Code of Conduct](#coc)
16 | - [Issues and Bugs](#issue)
17 | - [Feature Requests](#feature)
18 | - [Submission Guidelines](#submit)
19 |
20 | ## Code of Conduct
21 | Help us keep this project open and inclusive. Please read and follow our [Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
22 |
23 | ## Found an Issue?
24 | If you find a bug in the source code or a mistake in the documentation, you can help us by
25 | [submitting an issue](#submit-issue) to the GitHub Repository. Even better, you can
26 | [submit a Pull Request](#submit-pr) with a fix.
27 |
28 | ## Want a Feature?
29 | You can *request* a new feature by [submitting an issue](#submit-issue) to the GitHub
30 | Repository. If you would like to *implement* a new feature, please submit an issue with
31 | a proposal for your work first, to be sure that we can use it.
32 |
33 | * **Small Features** can be crafted and directly [submitted as a Pull Request](#submit-pr).
34 |
35 | ## Submission Guidelines
36 |
37 | ### Submitting an Issue
38 | Before you submit an issue, search the archive, maybe your question was already answered.
39 |
40 | If your issue appears to be a bug, and hasn't been reported, open a new issue.
41 | Help us to maximize the effort we can spend fixing issues and adding new
42 | features, by not reporting duplicate issues. Providing the following information will increase the
43 | chances of your issue being dealt with quickly:
44 |
45 | * **Overview of the Issue** - if an error is being thrown a non-minified stack trace helps
46 | * **Version** - what version is affected (e.g. 0.1.2)
47 | * **Motivation for or Use Case** - explain what are you trying to do and why the current behavior is a bug for you
48 | * **Browsers and Operating System** - is this a problem with all browsers?
49 | * **Reproduce the Error** - provide a live example or a unambiguous set of steps
50 | * **Related Issues** - has a similar issue been reported before?
51 | * **Suggest a Fix** - if you can't fix the bug yourself, perhaps you can point to what might be
52 | causing the problem (line of code or commit)
53 |
54 | You can file new issues by providing the above information at the corresponding repository's issues link: https://github.com/[organization-name]/[repository-name]/issues/new].
55 |
56 | ### Submitting a Pull Request (PR)
57 | Before you submit your Pull Request (PR) consider the following guidelines:
58 |
59 | * Search the repository (https://github.com/[organization-name]/[repository-name]/pulls) for an open or closed PR
60 | that relates to your submission. You don't want to duplicate effort.
61 |
62 | * Make your changes in a new git fork:
63 |
64 | * Commit your changes using a descriptive commit message
65 | * Push your fork to GitHub:
66 | * In GitHub, create a pull request
67 | * If we suggest changes then:
68 | * Make the required updates.
69 | * Rebase your fork and force push to your GitHub repository (this will update your Pull Request):
70 |
71 | ```shell
72 | git rebase master -i
73 | git push -f
74 | ```
75 |
76 | That's it! Thank you for your contribution!
77 |
--------------------------------------------------------------------------------
/Chat.cs:
--------------------------------------------------------------------------------
1 | using System.Text;
2 | using Microsoft.Extensions.DependencyInjection;
3 | using Microsoft.Extensions.Logging;
4 | using Microsoft.SemanticKernel;
5 | using Microsoft.SemanticKernel.ChatCompletion;
6 | using Microsoft.SemanticKernel.Connectors.AzureOpenAI;
7 | using Microsoft.SemanticKernel.Connectors.SqlServer;
8 | using Microsoft.SemanticKernel.Memory;
9 | using Microsoft.Extensions.Logging.Console;
10 | using DotNetEnv;
11 | using Microsoft.IdentityModel.Protocols;
12 | using Microsoft.SemanticKernel.Connectors.OpenAI;
13 | using System.Text.Json;
14 |
15 | #pragma warning disable SKEXP0001, SKEXP0010, SKEXP0020
16 |
17 | namespace azure_sql_sk;
18 |
19 | public class ChatBot
20 | {
21 | private readonly string azureOpenAIEndpoint;
22 | private readonly string azureOpenAIApiKey;
23 | private readonly string embeddingModelDeploymentName;
24 | private readonly string chatModelDeploymentName;
25 | private readonly string sqlConnectionString;
26 | private readonly string sqlTableName;
27 |
28 | public ChatBot(string envFile)
29 | {
30 | Env.Load(envFile);
31 | azureOpenAIEndpoint = Env.GetString("OPENAI_URL");
32 | azureOpenAIApiKey = Env.GetString("OPENAI_KEY");
33 | embeddingModelDeploymentName = Env.GetString("OPENAI_EMBEDDING_DEPLOYMENT_NAME");
34 | chatModelDeploymentName = Env.GetString("OPENAI_CHAT_DEPLOYMENT_NAME");
35 | sqlConnectionString = Env.GetString("MSSQL_CONNECTION_STRING");
36 | sqlTableName = Env.GetString("MSSQL_TABLE_NAME") ?? "ChatMemories";
37 | }
38 | public async Task RunAsync()
39 | {
40 | Console.WriteLine("Initializing the kernel...");
41 | //Console.WriteLine($"azureOpenAIEndpoint: {azureOpenAIEndpoint}, embeddingModelDeploymentName: {embeddingModelDeploymentName}, chatModelDeploymentName: {chatModelDeploymentName}, sqlTableName: {sqlTableName}");
42 | var sc = new ServiceCollection();
43 | sc.AddAzureOpenAIChatCompletion(chatModelDeploymentName, azureOpenAIEndpoint, azureOpenAIApiKey);
44 | sc.AddKernel();
45 | sc.AddLogging(b => b.AddSimpleConsole(o => { o.ColorBehavior = LoggerColorBehavior.Enabled; }).SetMinimumLevel(LogLevel.Debug));
46 | var services = sc.BuildServiceProvider();
47 | var logger = services.GetRequiredService>();
48 | var openAIPromptExecutionSettings = new AzureOpenAIPromptExecutionSettings()
49 | {
50 | FunctionChoiceBehavior = FunctionChoiceBehavior.Auto()
51 | };
52 |
53 | Console.WriteLine("Initializing plugins...");
54 | var kernel = services.GetRequiredService();
55 | kernel.Plugins.AddFromObject(new SearchSessionPlugin(kernel, logger, sqlConnectionString));
56 | var ai = kernel.GetRequiredService();
57 |
58 | Console.WriteLine("Initializing long-term memory...");
59 | var memory = new MemoryBuilder()
60 | .WithSqlServerMemoryStore(sqlConnectionString)
61 | .WithTextEmbeddingGeneration(
62 | (loggerFactory, httpClient) =>
63 | {
64 | return new AzureOpenAITextEmbeddingGenerationService(
65 | embeddingModelDeploymentName,
66 | azureOpenAIEndpoint,
67 | azureOpenAIApiKey,
68 | modelId: null,
69 | httpClient: httpClient,
70 | loggerFactory: loggerFactory,
71 | dimensions: 1536
72 | );
73 | }
74 | )
75 | .Build();
76 |
77 | await memory.SaveInformationAsync(sqlTableName, "With the new connector Microsoft.SemanticKernel.Connectors.SqlServer it is possible to efficiently store and retrieve memories thanks to the newly added vector support", "semantic-kernel-mssql");
78 | await memory.SaveInformationAsync(sqlTableName, "At the moment Microsoft.SemanticKernel.Connectors.SqlServer can be used only with Azure SQL", "semantic-kernel-azuresql");
79 | await memory.SaveInformationAsync(sqlTableName, "Azure SQL support for vectors is in Public Preview.", "azuresql-vector-eap");
80 |
81 | Console.WriteLine("Ready to chat! Hit 'ctrl-c' to quit.");
82 | var chat = new ChatHistory("You are an AI assistant that helps developers find information on Microsoft technologies. If users ask about topics you don't know, answer that you don't know. Be concise when answering.");
83 | var builder = new StringBuilder();
84 | while (true)
85 | {
86 | Console.Write($"\n(H: {chat.Count}) Question: ");
87 | var question = Console.ReadLine()!;
88 |
89 | if (string.IsNullOrWhiteSpace(question))
90 | continue;
91 |
92 | switch (question)
93 | {
94 | case "/c":
95 | Console.Clear();
96 | continue;
97 | case "/ch":
98 | chat.RemoveRange(1, chat.Count - 1);
99 | Console.WriteLine("Chat history cleared.");
100 | continue;
101 |
102 | case "/h":
103 | foreach (var message in chat)
104 | {
105 | Console.WriteLine($"> ---------- {message.Role} ----------");
106 | Console.WriteLine($"> MESSAGE > {message.Content}");
107 | Console.WriteLine($"> METADATA > {JsonSerializer.Serialize(message.Metadata)}");
108 | Console.WriteLine($"> ------------------------------------");
109 | }
110 | continue;
111 | }
112 |
113 | logger.LogDebug("Searching information from the memory...");
114 | builder.Clear();
115 | await foreach (var result in memory.SearchAsync(sqlTableName, question, limit: 3, minRelevanceScore: 0.4))
116 | {
117 | builder.AppendLine(result.Metadata.Text);
118 | }
119 | if (builder.Length > 0)
120 | {
121 | logger.LogDebug("Found information from the memory:" + Environment.NewLine + builder.ToString());
122 |
123 | builder.Insert(0, "Here's some additional information you can use to answer the question: ");
124 |
125 | chat.AddSystemMessage(builder.ToString());
126 | }
127 |
128 | builder.Clear();
129 | chat.AddUserMessage(question);
130 | var firstLine = true;
131 | await foreach (var message in ai.GetStreamingChatMessageContentsAsync(chat, openAIPromptExecutionSettings, kernel))
132 | {
133 | if (firstLine)
134 | {
135 | Console.WriteLine($"\n[H: {chat.Count}] Answer: ");
136 | firstLine = false;
137 | }
138 | Console.Write(message);
139 | builder.Append(message.Content);
140 | }
141 | Console.WriteLine();
142 | chat.AddAssistantMessage(builder.ToString());
143 |
144 | Console.WriteLine();
145 | }
146 | }
147 | }
148 |
149 |
--------------------------------------------------------------------------------
/Deploy.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using DbUp;
5 | using DbUp.ScriptProviders;
6 | using Microsoft.Data.SqlClient;
7 | using DotNetEnv;
8 |
9 | namespace azure_sql_sk;
10 |
11 | class DatabaseUtils
12 | {
13 | static public void Deploy(string envFile)
14 | {
15 | Env.Load(envFile);
16 |
17 | string azureOpenAIEndpoint = Env.GetString("OPENAI_URL");
18 | string azureOpenAIApiKey = Env.GetString("OPENAI_KEY");
19 | string embeddingModelDeploymentName = Env.GetString("OPENAI_EMBEDDING_DEPLOYMENT_NAME");
20 | string sqlConnectionString = Env.GetString("MSSQL_CONNECTION_STRING");
21 |
22 | if (string.IsNullOrEmpty(sqlConnectionString)) {
23 | throw new ApplicationException("MSSQL environment variable not set or empty.");
24 | }
25 |
26 | var csb = new SqlConnectionStringBuilder(sqlConnectionString);
27 | Console.WriteLine($"Deploying database: {csb.InitialCatalog}");
28 |
29 | Console.WriteLine("Testing connection...");
30 | var conn = new SqlConnection(csb.ToString());
31 | conn.Open();
32 | conn.Close();
33 |
34 | FileSystemScriptOptions options = new() {
35 | IncludeSubDirectories = false,
36 | Extensions = ["*.sql"],
37 | Filter = (file) => !file.EndsWith(".local.sql"),
38 | Encoding = Encoding.UTF8
39 | };
40 |
41 | Dictionary variables = new() {
42 | {"OPENAI_URL", azureOpenAIEndpoint},
43 | {"OPENAI_KEY", azureOpenAIApiKey},
44 | {"OPENAI_EMBEDDING_DEPLOYMENT_NAME", embeddingModelDeploymentName}
45 | };
46 |
47 | Console.WriteLine("Starting deployment...");
48 | var dbup = DeployChanges.To
49 | .SqlDatabase(csb.ConnectionString)
50 | .WithVariables(variables)
51 | .WithScriptsFromFileSystem("sql", options)
52 | .JournalToSqlTable("dbo", "$__dbup_journal")
53 | .LogToConsole()
54 | .Build();
55 |
56 | var result = dbup.PerformUpgrade();
57 |
58 | if (!result.Successful)
59 | {
60 | throw result.Error;
61 | }
62 | }
63 | }
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) Microsoft Corporation.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE
--------------------------------------------------------------------------------
/Plugins.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel;
2 | using Microsoft.SemanticKernel;
3 | using System.Data;
4 | using Microsoft.Data.SqlClient;
5 | using Dapper;
6 | using Microsoft.Extensions.Logging;
7 | using Microsoft.SemanticKernel.ChatCompletion;
8 | using Microsoft.SemanticKernel.Connectors.OpenAI;
9 |
10 | namespace azure_sql_sk;
11 |
12 | public class Session {
13 | public required string Id { get; set; }
14 | public required string Title { get; set; }
15 | public string? Abstract { get; set; }
16 | public string? ExternalId { get; set; }
17 | public string? Speakers { get; set; }
18 | public decimal Distance { get; set; }
19 | public decimal CosineSimilarity { get; set; }
20 | }
21 |
22 | public class SearchSessionPlugin(Kernel kernel, ILogger logger, string connectionString)
23 | {
24 | private readonly ILogger logger = logger;
25 | private readonly Kernel kernel = kernel;
26 | private readonly string connectionString = connectionString;
27 |
28 | [KernelFunction("query_database")]
29 | [Description("""
30 | Query the database to return data for the given query, if there are no other plugins that can be used to answer the query. This function only return data from the SQL Konferenz 2024 conference.
31 | The high-level schema of the database is the following:
32 |
33 | TABLE: [web].[sessions]
34 | COLUMNS:
35 | [id]: internal id of the sessions,
36 | [title]: session's title
37 | [abstract]: session's abstract
38 | [external_id]: session id provided by conference organizers
39 | [speakers]: list of speakers of the session
40 | [track]: track of the session
41 | [language]: language of the session
42 | [level]: values can be 100, 200, 300, 400, 500. 500 is the most advanced, 100 is the most basic
43 | """)]
44 | public async Task> QueryDatabase(string query)
45 | {
46 | logger.LogInformation($"Querying the database for '{query}'");
47 |
48 | var ai = kernel.GetRequiredService();
49 | var chat = new ChatHistory(@"You create T-SQL queries based on the given user request and the provided schema. Just return T-SQL query to be executed. Do not return other text or explanation. Don't use markdown or any wrappers.
50 | The database schema is the following:
51 |
52 | // this table contains the sessions at the SQL Konferenz 2024 conference
53 | CREATE TABLE [web].[sessions]
54 | (
55 | [id] INT DEFAULT (NEXT VALUE FOR [web].[global_id]) NOT NULL,
56 | [title] NVARCHAR (200) NOT NULL,
57 | [abstract] NVARCHAR (MAX) NOT NULL,
58 | [external_id] VARCHAR (100) NOT NULL,
59 | [details] JSON NULL
60 | );
61 |
62 | the [details] column contains JSON data with the following structure:
63 |
64 | speakers: [string1, string2, string3...] // JSON array with the speakers of the session
65 | track: string // the track of the session
66 | language: string // in which language the session is held
67 | level: int // session level
68 |
69 | make sure to use JSON_QUERY when querying or filtering a JSON array or a JSON object.
70 |
71 | JSON_QUERY must be cast to NVARCHAR(MAX) to be able to use it.
72 | parameter of OPENJSON must be to NVARCHAR(MAX) to be able to use it.
73 | ");
74 |
75 | chat.AddUserMessage(query);
76 | var response = await ai.GetChatMessageContentAsync(chat);
77 | if (response.Content == null)
78 | {
79 | logger.LogWarning("AI was not able to generate a SQL query.");
80 | return [];
81 | }
82 |
83 | string sqlQuery = response.Content.Replace("```sql", "").Replace("```", "");
84 |
85 | logger.LogInformation($"Executing the following query: {sqlQuery}");
86 |
87 | await using var connection = new SqlConnection(connectionString);
88 | var result = await connection.QueryAsync(sqlQuery);
89 |
90 | return result;
91 | }
92 |
93 | [KernelFunction("find_sessions_similar_to_topic")]
94 | [Description("Return a list of sessions at SQL Konferenz 2024 at that are similar to a specific topic or by a specific speaker name specified in the provided topic parameter. If no results are found, an empty list is returned. This function only return data from the SQL Konferenz 2024 conference.")]
95 | public async Task> GetSessionSimilarToTopic(string topic)
96 | {
97 | logger.LogInformation($"Searching for sessions related to '{topic}'");
98 |
99 | DefaultTypeMap.MatchNamesWithUnderscores = true;
100 |
101 | await using var connection = new SqlConnection(connectionString);
102 | var sessions = await connection.QueryAsync("web.find_similar_sessions",
103 | new {
104 | topic
105 | },
106 | commandType: CommandType.StoredProcedure
107 | );
108 |
109 | return sessions;
110 | }
111 | }
--------------------------------------------------------------------------------
/Program.cs:
--------------------------------------------------------------------------------
1 | using System.CommandLine;
2 | using azure_sql_sk;
3 |
4 | var rootCommand = new RootCommand();
5 |
6 | var envFileOption = new Option(
7 | name: "--env-file",
8 | description: "The .env file to load environment variables from.",
9 | getDefaultValue: () => ".env");
10 | envFileOption.AddAlias("-e");
11 |
12 | var deployDbCommand = new Command("deploy", "Deploy the database");
13 | deployDbCommand.AddOption(envFileOption);
14 | deployDbCommand.SetHandler(DatabaseUtils.Deploy, envFileOption);
15 | rootCommand.Add(deployDbCommand);
16 |
17 | var chatCommand = new Command("chat", "Run the chatbot");
18 | chatCommand.AddOption(envFileOption);
19 | chatCommand.SetHandler(async (envFileOptionValue) =>
20 | {
21 | var chatBot = new ChatBot(envFileOptionValue);
22 | await chatBot.RunAsync();
23 | },
24 | envFileOption);
25 | rootCommand.Add(chatCommand);
26 |
27 | await rootCommand.InvokeAsync(args);
28 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Azure SQL Chat with your data
2 |
3 | This is a simple example of a chatbot that uses Azure SQL to store and retrieve data using both RAG and Natural-Language-to-SQL (NL2QL) to allow chat on both structured and non-structured data. The bot is built using the Microsoft Semantic Kernel Framework and the newly added support for vectors in Azure SQL.
4 |
5 | 📺 This repo has been discussed on #DataExposed too: [Building the ultimate chatbot on your own data with Azure SQL and Semantic Kernel](https://www.youtube.com/watch?v=HAu2APLuj_8&list=PLlrxD0HtieHieV7Jls72yFPSKyGqycbZR)
6 |
7 | > [!NOTE]
8 | > If you are looking for the sample using *insurance* data, please use the [`insurance-chatbot-demo` branch](https://github.com/Azure-Samples/azure-sql-db-chat-sk/tree/insurance-chatbot-demo).
9 |
10 | ## Architecture
11 |
12 | 
13 |
14 | ## Solution
15 |
16 | The solution is composed of three main Azure components:
17 |
18 | - [Azure SQL Database](https://learn.microsoft.com/en-us/azure/azure-sql/database/sql-database-paas-overview?view=azuresql): The database that stores the data.
19 | - [Azure Open AI](https://learn.microsoft.com/azure/ai-services/openai/): The language model that generates the text and the embeddings.
20 | - [Semantic Kernel](https://learn.microsoft.com/en-us/semantic-kernel/overview/): The library used to orchestrate calls to LLM to do RAG and NL2SQL and to store long-term memories in the database.
21 |
22 | ### Azure Open AI
23 |
24 | Make sure to have two models deployed, one for generating embeddings (*text-embedding-3-small* model recommended) and one for handling the chat completion (*gpt-4 turbo* recommended). You can use the Azure OpenAI service to deploy the models. Make sure to have the endpoint and the API key ready. The two models are assumed to be deployed with the following names:
25 |
26 | - Embedding model: `text-embedding-3-small`
27 | - Chat model: `gpt-4`
28 |
29 | ### Configure environment
30 |
31 | Create a `.env` file starting from the `.env.sample` file:
32 |
33 | - `OPENAI_URL`: specify the URL of your Azure OpenAI endpoint, eg: 'https://my-open-ai.openai.azure.com/'
34 | - `OPENAI_KEY`: specify the API key of your Azure OpenAI endpoint
35 | - `OPENAI_MODEL`: specify the deployment name of your Azure OpenAI embedding endpoint, eg: 'text-embedding-3-small'
36 |
37 | - `MSSQL`: the connection string to the Azure SQL database where you want to deploy the database objects and sample data
38 | - `MSSQL_TABLE_NAME`: the name of the table where the chatbot will store long-term memories
39 |
40 | ### Database
41 |
42 | > [!NOTE]
43 | > Vector Functions are in Public Preview. Learn the details about vectors in Azure SQL here: https://aka.ms/azure-sql-vector-public-preview
44 |
45 | To deploy the database, you can just use the `deploy` option of the chatbot application. Make sure you have created the `.env` file as explained in the previoud section, and then run the following command:
46 |
47 | ```bash
48 | dotnet run deploy
49 | ```
50 |
51 | That will connect to Azure SQL and deploy the needed database objects and some sample data.
52 |
53 | ## Application
54 |
55 | To run the application, make sure you have created the `.env` file and deployed the database as explained in the previous section, and then run the following command:
56 |
57 | ```bash
58 | dotnet run chat
59 | ```
60 |
61 | The chatbot will start and you can start chatting with it. Use the `/ch` command to clear the chat history and `/h` to see the chat history. End the chat with `ctrl-c`.
62 |
63 | The prompt will look like this:
64 |
65 | ```bash
66 | (H: 1) Question:
67 | ```
68 |
69 | `H` indicates the chat memory size. The chatbot will remember the last `H` interactions.
70 |
71 | You can now start to chat with your own data. Have fun!
72 |
73 | ## F.A.Q.
74 |
75 | ### How can I quickly generate the embeddings for my data already stored in Azure SQL?
76 |
77 | Take a look at the Azure SQL Vectorizer repository:
78 |
79 | https://github.com/Azure-Samples/azure-sql-db-vectorizer
80 |
81 | It does exactly what you are looking for.
82 |
--------------------------------------------------------------------------------
/_assets/azure-sql-sk-bot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Azure-Samples/azure-sql-db-chat-sk/48aafe3208cf1ebc366c34f08f33a3ee215fa935/_assets/azure-sql-sk-bot.png
--------------------------------------------------------------------------------
/azure-sql-sk.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net9.0
6 | azure_sql_sk
7 | enable
8 | enable
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/sql/010-database.sql:
--------------------------------------------------------------------------------
1 | /* Nothing to do here, just a placeholder */
--------------------------------------------------------------------------------
/sql/020-security.sql:
--------------------------------------------------------------------------------
1 | if not exists(select * from sys.symmetric_keys where [name] = '##MS_DatabaseMasterKey##')
2 | begin
3 | create master key encryption by password = N'V3RYStr0NGP@ssw0rd!';
4 | end
5 | go
6 |
7 | if exists(select * from sys.[database_scoped_credentials] where name = '$OPENAI_URL$')
8 | begin
9 | drop database scoped credential [$OPENAI_URL$];
10 | end
11 | go
12 |
13 | create database scoped credential [$OPENAI_URL$]
14 | with identity = 'HTTPEndpointHeaders', secret = '{"api-key":"$OPENAI_KEY$"}';
15 | go
16 |
17 | if schema_id('web') is null begin
18 | exec('create schema [web] authorization [dbo]');
19 | end
20 | go
21 |
22 |
--------------------------------------------------------------------------------
/sql/030-create-table.sql:
--------------------------------------------------------------------------------
1 | /*
2 | DROP TABLE [web].[sessions_details_embeddings]
3 | DROP TABLE [web].[sessions]
4 | */
5 |
6 | CREATE SEQUENCE [web].[global_id]
7 | AS [int]
8 | START WITH 1
9 | INCREMENT BY 1
10 | GO
11 |
12 | CREATE TABLE [web].[sessions]
13 | (
14 | [id] INT DEFAULT (NEXT VALUE FOR [web].[global_id]) NOT NULL,
15 | [title] NVARCHAR (200) NOT NULL,
16 | [abstract] NVARCHAR (MAX) NOT NULL,
17 | [external_id] VARCHAR (100) COLLATE Latin1_General_100_BIN2 NOT NULL,
18 | [details] JSON NULL,
19 |
20 | PRIMARY KEY CLUSTERED ([id] ASC),
21 | UNIQUE NONCLUSTERED ([title] ASC)
22 | );
23 | GO
24 |
25 | CREATE TABLE [web].[sessions_details_embeddings]
26 | (
27 | [id] INT DEFAULT (NEXT VALUE FOR [web].[global_id]) NOT NULL,
28 | [session_id] INT NOT NULL,
29 | [details_vector_text3] VECTOR(1536) NOT NULL
30 | )
31 | GO
32 | CREATE CLUSTERED INDEX [ixc] ON [web].[sessions_details_embeddings]([session_id] ASC)
33 | GO
34 | CREATE NONCLUSTERED INDEX [ix__review_id] ON [web].[sessions_details_embeddings] ([session_id] ASC, [id] ASC)
35 | GO
36 | ALTER TABLE [web].[sessions_details_embeddings] ADD CONSTRAINT pk__sessions_details_embeddings PRIMARY KEY NONCLUSTERED ([id] ASC)
37 | GO
38 |
39 | CREATE TABLE [web].[sessions_abstracts_embeddings]
40 | (
41 | [id] INT DEFAULT (NEXT VALUE FOR [web].[global_id]) NOT NULL,
42 | [session_id] INT NOT NULL,
43 | [abstract_vector_text3] vector(1536) not null
44 | )
45 | GO
46 | CREATE CLUSTERED INDEX [ixc] ON [web].[sessions_abstracts_embeddings]([session_id] ASC)
47 | GO
48 | CREATE NONCLUSTERED INDEX [ix__review_id] ON [web].[sessions_abstracts_embeddings] ([session_id] ASC, [id] ASC)
49 | GO
50 | ALTER TABLE [web].[sessions_abstracts_embeddings] ADD CONSTRAINT pk__sessions_abstracts_embeddings PRIMARY KEY NONCLUSTERED ([id] ASC)
51 | GO
52 |
--------------------------------------------------------------------------------
/sql/040-get_embedding.sql:
--------------------------------------------------------------------------------
1 | create or alter procedure [web].[get_embedding]
2 | @inputText nvarchar(max),
3 | @embedding vector(1536) output
4 | as
5 | begin try
6 | declare @retval int;
7 | declare @payload nvarchar(max) = json_object('input': @inputText);
8 | declare @response nvarchar(max)
9 | exec @retval = sp_invoke_external_rest_endpoint
10 | @url = '$OPENAI_URL$/openai/deployments/$OPENAI_EMBEDDING_DEPLOYMENT_NAME$/embeddings?api-version=2023-03-15-preview',
11 | @method = 'POST',
12 | @credential = [$OPENAI_URL$],
13 | @payload = @payload,
14 | @response = @response output;
15 | end try
16 | begin catch
17 | select
18 | 'SQL' as error_source,
19 | error_number() as error_code,
20 | error_message() as error_message
21 | return;
22 | end catch
23 |
24 | if (@retval != 0) begin
25 | select
26 | 'OPENAI' as error_source,
27 | json_value(@response, '$.result.error.code') as error_code,
28 | json_value(@response, '$.result.error.message') as error_message,
29 | @response as error_response
30 | return;
31 | end;
32 |
33 | declare @re nvarchar(max) = json_query(@response, '$.result.data[0].embedding')
34 | set @embedding = cast(@re as vector(1536));
35 |
36 | return @retval
37 | go
--------------------------------------------------------------------------------
/sql/050-find_similar_session.sql:
--------------------------------------------------------------------------------
1 | create or alter procedure web.find_similar_sessions @topic nvarchar(max)
2 | as
3 |
4 | declare @e vector(1536);
5 | exec [web].[get_embedding] @topic, @e output;
6 |
7 | with similar as
8 | (
9 | select top(10)
10 | s.id,
11 | s.title,
12 | s.abstract,
13 | s.external_id,
14 | json_value(s.details, '$.speakers[0]') as speakers,
15 | least(
16 | vector_distance('cosine', @e, details_vector_text3),
17 | vector_distance('cosine', @e, abstract_vector_text3)
18 | ) as distance
19 | from
20 | [web].[sessions] s
21 | left join
22 | [web].[sessions_details_embeddings] e1 on s.id = e1.session_id
23 | left join
24 | [web].[sessions_abstracts_embeddings] e2 on s.id = e2.session_id
25 | order by
26 | distance
27 | )
28 | select
29 | *,
30 | 1-distance as cosine_similiarity
31 | from
32 | similar
33 | where
34 | distance <= 0.75
35 | order by
36 | distance
37 |
38 |
--------------------------------------------------------------------------------
/sql/100-sample-data.sql:
--------------------------------------------------------------------------------
1 | /*
2 | delete from [web].[sessions_abstracts_embeddings];
3 | delete from [web].[sessions_details_embeddings];
4 | delete from [web].[sessions];
5 | go
6 | */
7 |
8 | insert into
9 | [web].[sessions]
10 | select
11 | *
12 | from
13 | openjson(
14 | '[{
15 | "id": 9,
16 | "title": "Azure SQL and SQL Server: All Things Developers",
17 | "abstract": "Over the past two decades, SQL Server has undergone a remarkable evolution, emerging as the most widely deployed database in the world. A great number of new features have been announced for Azure SQL and SQL Server to support developers in being more efficient and productive when creating new solutions and applications or when modernizing existing ones. In this session, we go over all the lastest released features such as JSON, Data API builder, calling REST endpoints, Azure function integrations and much more, so that you''ll learn how to take advantage of them right away.",
18 | "external_id": "683984",
19 | "details": {"speakers":["Davide Mauri"],"track":"Data Engineering","language":"English","level":300}
20 | }]') with (
21 | id int '$.id',
22 | title nvarchar(200) '$.title',
23 | abstract nvarchar(max) '$.abstract',
24 | external_id varchar(100) '$.external_id',
25 | details nvarchar(max) '$.details' as json
26 | )
27 | go
28 |
29 | insert into
30 | [web].[sessions]
31 | select
32 | *
33 | from
34 | openjson(
35 | '[{
36 | "id": 2,
37 | "title": "Erkläre meiner techniknahen Frau Fabric und seine Fähigkeit, Daten sofort zu analysieren",
38 | "abstract": "Das Erlernen einer neuen Technologie wie Fabric ähnelt dem Erlernen einer neuen Sprache. Es gibt unbekannte Wörter, Grammatik und Konzepte, aber vieles ist ähnlich zu dem, was du bereits kennst. Wenn du dich im Umfeld von Microsoft Data befindest, bin ich mir sicher, dass du gefragt wurdest: Was ist Microsoft Fabric? Und Wofür können wir es verwenden? So haben meine techniknahe Ehefrau und ich diese Fragen geklärt und die Sprachbarriere überwunden :-) Wir werden auch zeigen, wie du Echtzeitanalysen über dein Smart Home in Microsoft Fabric abfragen kannst. Also, wenn du keine Ahnung hast, was Fabric ist, oder wenn du Fabric jemandem erklären musst, der keine Ahnung hat, könnten diese 10 Minuten nützlich für dich sein. Explaining Fabric and its ability to analyse data instantly to my tech-adjacent wife Learning a new technology like Fabric is similar learning a new language. There are unfamiliar words, grammar, and concepts but a lot is similar to what you already know. If you are around Microsoft Data I am certain that you will have been asked. What is Microsoft Fabric ? And What can we use it for? This is how my tech-adjacent wife, and I resolved those questions and broke down the language barrier :-) We will also show how you can query Real-Time Analytics about your smart home in Microsoft Fabric. So if you have no idea what Fabric is or you have to explain Fabric to someone who has no idea maybe these 10 minutes may be useful for you.",
39 | "external_id": "456",
40 | "details": {"speakers":["Rob Sewell"],"track":"Analytics & Data Science","language":"German","level":100}
41 | }]') with (
42 | id int '$.id',
43 | title nvarchar(200) '$.title',
44 | abstract nvarchar(max) '$.abstract',
45 | external_id varchar(100) '$.external_id',
46 | details nvarchar(max) '$.details' as json
47 | )
48 | go
49 |
50 | declare @a as nvarchar(max);
51 | declare @e as vector(1536);
52 | select @a = abstract from [web].[sessions] where id = 9;
53 | exec web.get_embedding @a, @e output;
54 | insert into [web].[sessions_abstracts_embeddings] ([session_id], abstract_vector_text3) values (9, @e);
55 | go
56 |
57 | declare @d as nvarchar(max);
58 | declare @e as vector(1536);
59 | select @d = cast(details as nvarchar(max)) from [web].[sessions] where id = 9;
60 | exec web.get_embedding @d, @e output;
61 | insert into [web].[sessions_details_embeddings] ([session_id], details_vector_text3) values (9, @e);
62 | go
63 |
--------------------------------------------------------------------------------