-
Notifications
You must be signed in to change notification settings - Fork 389
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
256 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
254 changes: 254 additions & 0 deletions
254
Basic_Samples/Embeddings/dotnet/csharp/Semantic_text_search_using_embeddings.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,254 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Semantic text search using embeddings\n", | ||
"\n", | ||
"We can search through all our reviews semantically in a very efficient manner and at very low cost, by embedding our search query, and then finding the most similar reviews. The dataset is created in the [Get_embeddings_from_dataset Notebook](Get_embeddings_from_dataset.ipynb)." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Installation\n", | ||
"Install the Azure Open AI SDK using the below command." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": { | ||
"dotnet_interactive": { | ||
"language": "csharp" | ||
}, | ||
"polyglot_notebook": { | ||
"kernelName": "csharp" | ||
}, | ||
"vscode": { | ||
"languageId": "polyglot-notebook" | ||
} | ||
}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/html": [ | ||
"<div><div></div><div></div><div><strong>Installed Packages</strong><ul><li><span>Azure.AI.OpenAI, 1.0.0-beta.8</span></li></ul></div></div>" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"#r \"nuget: Azure.AI.OpenAI, *-*\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": { | ||
"dotnet_interactive": { | ||
"language": "csharp" | ||
}, | ||
"polyglot_notebook": { | ||
"kernelName": "csharp" | ||
}, | ||
"vscode": { | ||
"languageId": "polyglot-notebook" | ||
} | ||
}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/html": [ | ||
"<div><div><strong>Restore sources</strong><ul><li><span>https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json</span></li></ul></div><div></div><div></div></div>" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"#i \"nuget:https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": { | ||
"dotnet_interactive": { | ||
"language": "csharp" | ||
}, | ||
"polyglot_notebook": { | ||
"kernelName": "csharp" | ||
}, | ||
"vscode": { | ||
"languageId": "polyglot-notebook" | ||
} | ||
}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/html": [ | ||
"<div><div></div><div></div><div><strong>Installed Packages</strong><ul><li><span>Microsoft.DotNet.Interactive.AIUtilities, 1.0.0-beta.23509.3</span></li></ul></div></div>" | ||
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"#r \"nuget:Microsoft.DotNet.Interactive.AIUtilities, *-*\"\n", | ||
"\n", | ||
"using Microsoft.DotNet.Interactive;\n", | ||
"using Microsoft.DotNet.Interactive.AIUtilities;" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": { | ||
"dotnet_interactive": { | ||
"language": "csharp" | ||
}, | ||
"polyglot_notebook": { | ||
"kernelName": "csharp" | ||
}, | ||
"vscode": { | ||
"languageId": "polyglot-notebook" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"var azureOpenAIKey = await Kernel.GetPasswordAsync(\"Provide your OPEN_AI_KEY\");\n", | ||
"\n", | ||
"// Your endpoint should look like the following https://YOUR_OPEN_AI_RESOURCE_NAME.openai.azure.com/\n", | ||
"var azureOpenAIEndpoint = await Kernel.GetInputAsync(\"Provide the OPEN_AI_ENDPOINT\");\n", | ||
"\n", | ||
"// Enter the deployment name you chose when you deployed the model.\n", | ||
"var deployment = await Kernel.GetInputAsync(\"Provide deployment name\");" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Import namesapaces and create an instance of `OpenAiClient` using the `azureOpenAIEndpoint` and the `azureOpenAIKey`" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": { | ||
"dotnet_interactive": { | ||
"language": "csharp" | ||
}, | ||
"polyglot_notebook": { | ||
"kernelName": "csharp" | ||
}, | ||
"vscode": { | ||
"languageId": "polyglot-notebook" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"using Azure;\n", | ||
"using Azure.AI.OpenAI;" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": { | ||
"dotnet_interactive": { | ||
"language": "csharp" | ||
}, | ||
"polyglot_notebook": { | ||
"kernelName": "csharp" | ||
}, | ||
"vscode": { | ||
"languageId": "polyglot-notebook" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"OpenAIClient client = new (new Uri(azureOpenAIEndpoint), new AzureKeyCredential(azureOpenAIKey.GetClearTextPassword()));" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Loading `Microsoft.Data.Analysis` lastest package" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"dotnet_interactive": { | ||
"language": "csharp" | ||
}, | ||
"polyglot_notebook": { | ||
"kernelName": "csharp" | ||
}, | ||
"vscode": { | ||
"languageId": "polyglot-notebook" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"#i \"nuget:https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-libraries/nuget/v3/index.json\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"dotnet_interactive": { | ||
"language": "csharp" | ||
}, | ||
"polyglot_notebook": { | ||
"kernelName": "csharp" | ||
}, | ||
"vscode": { | ||
"languageId": "polyglot-notebook" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"#r \"nuget: Microsoft.Data.Analysis, *-*\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"dotnet_interactive": { | ||
"language": "csharp" | ||
}, | ||
"polyglot_notebook": { | ||
"kernelName": "csharp" | ||
}, | ||
"vscode": { | ||
"languageId": "polyglot-notebook" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"using Microsoft.ML.Data;" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"language_info": { | ||
"name": "csharp" | ||
}, | ||
"orig_nbformat": 4 | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |