|
1 | 1 | ---
|
2 |
| -title: 'C# tutorial: AI on Azure blobs' |
| 2 | +title: 'Tutorial: Skillsets using C#' |
3 | 3 | titleSuffix: Azure AI Search
|
4 |
| -description: Step through an example of text extraction and natural language processing over content in Blob storage using C# and the Azure AI Search .NET SDK. |
5 |
| -author: gmndrg |
6 |
| -ms.author: gimondra |
| 4 | +description: Use C# and the Azure SDK for .NET to create skillsets. This skillset applies AI transformations and analyses to create searchable content from images and unstructured text. |
| 5 | + |
| 6 | +author: HeidiSteen |
| 7 | +ms.author: heidist |
7 | 8 | manager: nitinme
|
8 | 9 |
|
9 | 10 | ms.service: cognitive-search
|
10 | 11 | ms.topic: tutorial
|
11 |
| -ms.date: 09/13/2023 |
| 12 | +ms.date: 03/06/2024 |
12 | 13 | ms.custom:
|
13 | 14 | - devx-track-csharp
|
14 | 15 | - devx-track-dotnet
|
15 | 16 | - ignite-2023
|
16 | 17 | ---
|
17 | 18 |
|
18 |
| -# Tutorial: Use .NET and AI to generate searchable content from Azure blobs |
| 19 | +# C# Tutorial: Use skillsets to generate searchable content in Azure AI Search |
| 20 | + |
| 21 | +In this tutorial, learn how to use the [Azure SDK for .NET](https://www.nuget.org/packages/Azure.Search.Documents/) to create an [AI enrichment pipeline](cognitive-search-concept-intro.md) for content extraction and transformations during indexing. |
19 | 22 |
|
20 |
| -If you have unstructured text or images in Azure Blob Storage, an [AI enrichment pipeline](cognitive-search-concept-intro.md) in Azure AI Search can extract information and create new content for full-text search or knowledge mining scenarios. |
| 23 | +Skillsets add AI processing to raw content, making that content more uniform and searchable. Once you know how skillsets work, you can support a broad range of transformations: from image analysis, to natural language processing, to customized processing that you provide externally. |
21 | 24 |
|
22 |
| -In this C# tutorial, you learn how to: |
| 25 | +This tutorial helps you learn how to: |
23 | 26 |
|
24 | 27 | > [!div class="checklist"]
|
25 |
| -> * Set up a development environment. |
26 |
| -> * Define a pipeline that uses OCR, language detection, entity recognition, and key phrase extraction. |
27 |
| -> * Execute the pipeline to invoke transformations, and to create and load a search index. |
28 |
| -> * Explore results using full text search and a rich query syntax. |
| 28 | +> + Define objects in an enrichment pipeline |
| 29 | +> + Build a skillset that invokes OCR, language detection, entity recognition, and key phrase extraction |
| 30 | +> + Execute the pipeline to invoke transformations, and to create and load a search index |
| 31 | +> + Check the results using full text search |
29 | 32 |
|
30 | 33 | If you don't have an Azure subscription, open a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
|
31 | 34 |
|
32 | 35 | ## Overview
|
33 | 36 |
|
34 |
| -This tutorial uses C# and the [**Azure.Search.Documents** client library](/dotnet/api/overview/azure/search.documents-readme) to create a data source, index, indexer, and skillset. |
| 37 | +This tutorial uses C# and the [**Azure.Search.Documents**](/dotnet/api/overview/azure/search.documents-readme) client library to create a data source, index, indexer, and skillset. |
35 | 38 |
|
36 |
| -The indexer connects to sample data in a blob container that's specified in the data source object, and sends all enriched content to a search index. |
| 39 | +The [indexer](search-indexer-overview.md) drives each step in the pipeline, starting with content extraction of sample data (unstructured text and images) in a blob container on Azure Storage. |
37 | 40 |
|
38 |
| -The skillset is attached to the indexer. It uses built-in skills from Microsoft to find and extract information. Steps in the pipeline include Optical Character Recognition (OCR) on images, language detection on text, key phrase extraction, and entity recognition (organizations). New information created by the pipeline is stored in new fields in an index. Once the index is populated, you can use the fields in queries, facets, and filters. |
| 41 | +Once content is extracted, the [skillset](cognitive-search-working-with-skillsets.md) executes built-in skills from Microsoft to find and extract information. These skills include Optical Character Recognition (OCR) on images, language detection on text, key phrase extraction, and entity recognition (organizations). New information created by the skillset is sent to fields in an [index](search-what-is-an-index.md). Once the index is populated, you can use the fields in queries, facets, and filters. |
39 | 42 |
|
40 | 43 | ## Prerequisites
|
41 | 44 |
|
42 |
| -* [Visual Studio](https://visualstudio.microsoft.com/downloads/) |
43 |
| -* [Azure.Search.Documents 11.x NuGet package](https://www.nuget.org/packages/Azure.Search.Documents) |
44 |
| -* [Azure Storage](https://azure.microsoft.com/services/storage/) |
45 |
| -* [Azure AI Search](https://azure.microsoft.com/services/search/) |
46 |
| -* [Sample data](https://github.com/Azure-Samples/azure-search-sample-data/tree/main/ai-enrichment-mixed-media) |
47 |
| - |
48 |
| -> [!Note] |
49 |
| -> You can use the free search service for this tutorial. A free search service limits you to three indexes, three indexers, and three data sources. This tutorial creates one of each. Before starting, make sure you have room on your service to accept the new resources. |
50 |
| -
|
51 |
| -## Download files |
52 |
| - |
53 |
| -The sample data consists of 14 files of mixed content type that you will upload to Azure Blob Storage in a later step. |
54 |
| - |
55 |
| -1. Get the files from [azure-search-sample-data/ai-enrichment-mixed-media/](https://github.com/Azure-Samples/azure-search-sample-data/tree/main/ai-enrichment-mixed-media) and copy them to your local computer. |
56 |
| - |
57 |
| -1. Next, get the source code for this tutorial. Source code is in the **tutorial-ai-enrichment/v11** folder in the [azure-search-dotnet-samples](https://github.com/Azure-Samples/azure-search-dotnet-samples) repository. |
58 |
| - |
59 |
| -## 1 - Create services |
60 |
| - |
61 |
| -This tutorial uses Azure AI Search for indexing and queries, Azure AI services on the backend for AI enrichment, and Azure Blob Storage to provide the data. This tutorial stays under the free allocation of 20 transactions per indexer per day on Azure AI services, so the only services you need to create are search and storage. |
62 |
| - |
63 |
| -If possible, create both in the same region and resource group for proximity and manageability. In practice, your Azure Storage account can be in any region. |
64 |
| - |
65 |
| -### Start with Azure Storage |
| 45 | ++ [Visual Studio](https://visualstudio.microsoft.com/downloads/) |
66 | 46 |
|
67 |
| -1. Sign in to the [Azure portal](https://portal.azure.com) and click **+ Create Resource**. |
| 47 | ++ [Azure.Search.Documents 11.x NuGet package](https://www.nuget.org/packages/Azure.Search.Documents) |
68 | 48 |
|
69 |
| -1. Search for *storage account* and select Microsoft's Storage Account offering. |
| 49 | ++ [Azure Storage](/azure/storage/common/storage-account-create) |
70 | 50 |
|
71 |
| -  |
| 51 | ++ [Azure AI Search](search-create-app-portal.md) |
72 | 52 |
|
73 |
| -1. In the Basics tab, the following items are required. Accept the defaults for everything else. |
| 53 | ++ [Sample data files (mixed media)](https://github.com/Azure-Samples/azure-search-sample-data/tree/main/ai-enrichment-mixed-media) |
74 | 54 |
|
75 |
| - + **Resource group**. Select an existing one or create a new one, but use the same group for all services so that you can manage them collectively. |
76 |
| - |
77 |
| - + **Storage account name**. If you think you might have multiple resources of the same type, use the name to disambiguate by type and region, for example *blobstoragewestus*. |
78 |
| - |
79 |
| - + **Location**. If possible, choose the same location used for Azure AI Search and Azure AI services. A single location voids bandwidth charges. |
80 |
| - |
81 |
| - + **Account Kind**. Choose the default, *StorageV2 (general purpose v2)*. |
82 |
| - |
83 |
| -1. Select **Review + Create** to create the service. |
84 |
| - |
85 |
| -1. Once it's created, select **Go to the resource** to open the Overview page. |
| 55 | +> [!NOTE] |
| 56 | +> You can use the free search service for this tutorial. A free search service limits you to three indexes, three indexers, and three data sources. This tutorial creates one of each. Before starting, make sure you have room on your service to accept the new resources. |
86 | 57 |
|
87 |
| -1. Select **Blobs** service. |
| 58 | +### Upload sample data to Azure Storage |
88 | 59 |
|
89 |
| -1. Select **+ Container** to create a container and name it *cog-search-demo*. |
| 60 | +1. In Azure Storage, create a new container and name it *cog-search-demo*. |
90 | 61 |
|
91 |
| -1. Select *cog-search-demo* and then select **Upload** to open the folder where you saved the download files. Select all of the files. Select **Upload**. |
| 62 | +1. [Upload the sample data files](/azure/storage/blobs/storage-quickstart-blobs-portal). |
92 | 63 |
|
93 | 64 | :::image type="content" source="media/cognitive-search-tutorial-blob/sample-files.png" alt-text="Screenshot of the files in File Explorer." border="true":::
|
94 | 65 |
|
95 |
| -1. Before you leave Azure Storage, get a connection string so that you can formulate a connection in Azure AI Search. |
96 |
| - |
97 |
| - 1. Browse back to the Overview page of your storage account (we used *blobstragewestus* as an example). |
| 66 | +1. Get a storage connection string so that you can formulate a connection in Azure AI Search. |
98 | 67 |
|
99 |
| - 1. In the left navigation pane, select **Access keys** and copy one of the connection strings. |
| 68 | + 1. On the left, select **Access keys**. |
100 | 69 |
|
101 |
| - The connection string is a URL similar to the following example: |
| 70 | + 1. Copy the connection string for either key one or key two. The connection string is similar to the following example: |
102 | 71 |
|
103 | 72 | ```http
|
104 | 73 | DefaultEndpointsProtocol=https;AccountName=cogsrchdemostorage;AccountKey=<your account key>;EndpointSuffix=core.windows.net
|
105 | 74 | ```
|
106 | 75 |
|
107 |
| -1. Save the connection string to Notepad. You'll need it later when setting up the data source connection. |
108 |
| -
|
109 |
| -<!-- The next section says that a key isn't required, but the code won't run without it. Is there a way to make the key declaration work as null? It would be nice to keep the appsetting so that people know how to set it up, but at the same time, the other versions of this sample don't require a key, so this one shouldn't either. --> |
110 |
| -
|
111 | 76 | ### Azure AI services
|
112 | 77 |
|
113 |
| -AI enrichment is backed by Azure AI services, including Language service and Azure AI Vision for natural language and image processing. If your objective was to complete an actual prototype or project, you would at this point provision Azure AI services (in the same region as Azure AI Search) so that you can attach it to indexing operations. |
114 |
| -
|
115 |
| -For this exercise, however, you can skip resource provisioning because Azure AI Search can connect to Azure AI services behind the scenes and give you 20 free transactions per indexer run. Since this tutorial uses 14 transactions, the free allocation is sufficient. For larger projects, plan on provisioning Azure AI services at the pay-as-you-go S0 tier. For more information, see [Attach Azure AI services](cognitive-search-attach-cognitive-services.md). |
| 78 | +AI enrichment is backed by Azure AI services, including Language service and Azure AI Vision for natural language and image processing. For small workloads like this tutorial, you can use the free allocation of twenty transactions per indexer. For larger workloads, [attach an Azure AI Services multi-region resource to a skillset](cognitive-search-attach-cognitive-services.md) for pay-as-you-go pricing. |
116 | 79 |
|
117 | 80 | ### Azure AI Search
|
118 | 81 |
|
119 | 82 | The third component is Azure AI Search, which you can [create in the portal](search-create-service-portal.md) or [find an existing search service](https://portal.azure.com/#blade/HubsExtension/BrowseResourceBlade/resourceType/Microsoft.Search%2FsearchServices) in your subscription.
|
120 | 83 |
|
121 |
| -You can use the Free tier to complete this walkthrough. |
| 84 | +You can use the Free tier to complete this walkthrough. |
122 | 85 |
|
123 |
| -### Copy an admin api-key and URL for Azure AI Search |
| 86 | +### Copy a key and URL |
124 | 87 |
|
125 |
| -To interact with your Azure AI Search service you will need the service URL and an access key. |
| 88 | +For this tutorial, connections to Azure AI Search require an endpoint and an API key. You can get these values from the Azure portal. |
126 | 89 |
|
127 |
| -1. Sign in to the [Azure portal](https://portal.azure.com), and in your search service **Overview** page, get the name of your search service. You can confirm your service name by reviewing the endpoint URL. If your endpoint URL were `https://mydemo.search.windows.net`, your service name would be `mydemo`. |
| 90 | +1. Sign in to the [Azure portal](https://portal.azure.com), navigate to the search service **Overview** page, and copy the URL. An example endpoint might look like `https://mydemo.search.windows.net`. |
128 | 91 |
|
129 |
| -1. In **Settings** > **Keys**, get an admin key for full rights on the service. You can copy either the primary or secondary key. |
| 92 | +1. Under **Settings** > **Keys**, copy an admin key. Admin keys are used to add, modify, and delete objects. There are two interchangeable admin keys. Copy either one. |
130 | 93 |
|
131 |
| -  |
| 94 | + :::image type="content" source="media/search-get-started-rest/get-url-key.png" alt-text="Screenshot of the URL and API keys in the Azure portal."::: |
132 | 95 |
|
133 |
| -Having a valid key establishes trust, on a per request basis, between the application sending the request and the service that handles it. |
| 96 | +A valid API key establishes trust, on a per request basis, between the application sending the request and the search service handling it. |
134 | 97 |
|
135 |
| -## 2 - Set up your environment |
| 98 | +## Set up your environment |
136 | 99 |
|
137 | 100 | Begin by opening Visual Studio and creating a new Console App project that can run on .NET Core.
|
138 | 101 |
|
@@ -232,7 +195,7 @@ private static void ExitProgram(string message)
|
232 | 195 | }
|
233 | 196 | ```
|
234 | 197 |
|
235 |
| -## 3 - Create the pipeline |
| 198 | +## Create the pipeline |
236 | 199 |
|
237 | 200 | In Azure AI Search, AI processing occurs during indexing (or data ingestion). This part of the walkthrough creates four objects: data source, index definition, skillset, indexer.
|
238 | 201 |
|
@@ -777,7 +740,7 @@ When content is extracted, you can set `imageAction` to extract text from images
|
777 | 740 |
|
778 | 741 | <a name="check-indexer-status"></a>
|
779 | 742 |
|
780 |
| -## 4 - Monitor indexing |
| 743 | +## Monitor indexing |
781 | 744 |
|
782 | 745 | Once the indexer is defined, it runs automatically when you submit the request. Depending on which skills you defined, indexing can take longer than you expect. To find out whether the indexer is still running, use the `GetStatus` method.
|
783 | 746 |
|
@@ -823,7 +786,7 @@ Console.WriteLine("Check the indexer overall status...");
|
823 | 786 | CheckIndexerOverallStatus(indexerClient, demoIndexer);
|
824 | 787 | ```
|
825 | 788 |
|
826 |
| -## 5 - Search |
| 789 | +## Search |
827 | 790 |
|
828 | 791 | In Azure AI Search tutorial console apps, we typically add a 2-second delay before running queries that return results, but because enrichment takes several minutes to complete, we'll close the console app and use another approach instead.
|
829 | 792 |
|
|
0 commit comments