Custom Data with Azure OpenAI using Cognitive Search
Tags: beginners
Published: 2024-02-01 09:51:58

**Abstract**
Azure Open AI is a set of AI services provided by Azure that allows developers to build intelligent applications using pre-built AI models, APIs, and tools. These services include computer vision, natural language processing, speech recognition, and more.
Azure Blob is a cloud-based object storage solution provided by Microsoft Azure. It allows users to store and access large amounts of unstructured data such as text, images, videos, and audio files from anywhere in the world.
By integrating Azure Blob with Azure Open AI, developers can build powerful AI applications that can analyze, and process large amounts of unstructured data stored in Blob storage. For example, developers can use Azure Cognitive Services API s to perform image recognition on images stored in Blob storage or use Azure Machine Learning to train machine learning models on data stored in Blob storage.
Overall, the combination of Azure Blob and Azure Open AI provides developers with a powerful platform for building intelligent applications that can analyze and process large amounts of unstructured data.

**Introduction**
Azure Blob is a scalable and highly available object storage service provided by Microsoft Azure. It allows users to store massive amounts of unstructured data such as images, videos, documents, and other types of files. With Azure Open AI, users can leverage the power of artificial intelligence to gain insights into their data and make informed decisions. .NET i s a cross-platform framework that can be used to develop applications for various platforms including Windows, Linux, a nd macOS. In this context, using .NET with Azure Blob and Azure Open AI can provide a powerful platform for storing an d analyzing large amounts of data. This can help businesses make smarter decisions, improve customer experiences, a nd gain a competitive advantage. In this article, we will explore how to use .NET with Azure Blob and Azure Open AI to manage and analyses your data.
.NET with OpenAI can be to build intelligent applications that leverage the power of artificial intelligence. OpenAI is an AI research laboratory that aims to create safe and beneficial AI systems that can help solve some of the world's biggest challenges. OpenAI provides a range of powerful AI models and APIs that can be used to add intelligent capabilities to you r .NET applications.

**Custom data (azure blob) with Open AI Overview **


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/poslnbqvup9810zsrczu.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vejs6u9clrk7d4vuiose.png)

OpenAI is a tool that helps you explore and analyse large sets of text data. It can be used to analyse custom data stored in Azure Blob storage, provided that the data is in a format that can be read by the tool.
Azure Cognitive Search is a cloud-based search service that allows you to build intelligent search experiences into your applications and websites. It supports indexing and searching over a variety of data sources, including Azure Blob Storage.

Steps to combine Azure Blob with OpenAI
Step 1: Open Azure Portal and Create a new Resource group.
Step 2: Create an Azure Blob storage resource.
Step 3: Create an Azure Cognitive Search resource.
Step 4: Create an Azure OpenAI resource.
Azure OpenAI Service provides REST API access to OpenAI's powerful language models including the GPT-4, GPT-35-Turbo, and Embeddings model series. You will use it to create large language models inside it.
Step 5: Created list as below for azure storage, open AI, cognitive search 
Step 6: Go to OpenAI studio 
Step 7: Create new deployment to go to the deployments tab.

Perform the following tasks: Create deployment 
	

    -Select a Model. gpt-35-turbo is a large language model that 
     can function as our ChatGPT.
    -Select the Model version. The only supported version with the 
     bring-your-own-model feature is 0301.
    -Enter a Deployment name. Any unique name shall work.
    -Select Create.

Step 8: Bring your own Data to Azure OpenAI.
Now, you need to bring it all together just like Lego pieces that we need to glue together to build our solution.
You are using the previously created resources to configure this feature.

     -Inside your Deployments tab, select the previously created 
      deployment followed by selecting Open in Playground. (The 
      Playground is a place on Azure OpenAI where you can 
      experiment with different generative models.)
     -Enter any text you want in the Chat session tab to evaluate 
      your deployed model.
     -Now, let's add your own data to make the model more rounded 
      and enable it to respond to specific questions related to 
      the data.
     -Select Add your data from the Assistant setup tab. Add your 
      data tab, select + Add a data source.
     -Data source tab, select Upload files as your data source 
      followed by performing the following tasks:
     -Upload file here or you can upload it to actual azure 
      storage location.
     -Data management tab, select the Search type followed by 
      selecting Next. The Simple type will work for you.
Note: Semantic search will give you better search results, but it has limited availability.
     -Review and finish tab, review all the properties then, 
      select Save and close.
     -Now go to chat window again search for to a specific text in 
      the data source you uploaded.

Step 9: Deploy to a Website or Power Virtual Agent.

     -Azure OpenAI enables you with a click of a button to deploy 
      your grounded large language model to a website or power 
      virtual agent.
     -Chat playground, select Deploy to followed by selecting A 
      new web app.to create a website that anyone can interact 
      with.

**Azure Cognitive **
Azure Cognitive Search is a search-as-a-service cloud solution that gives developers APIs and tools for adding a rich search experience over private, heterogeneous content in web, mobile, and enterprise applications.
It can be easily integrated with .NET applications using the Open AI .NET SDK. The SDK provides a set of APIs that developers can use to easily create, configure, and manage search indexes and data sources within their .NET applications.
Azure Cognitive Search has two primary workloads i.e. Indexing and Querying -

     -Indexing - This is the process of loading your data into the 
      search service and making it searchable. Inbound text is 
      processed into tokens and stored in inverted indexes, and 
      inbound vectors are stored in vector indexes. 
     -Querying happens once your index is populated with 
      searchable text. When client apps send queries to your 
      search service, it will handle the response. The query 
      execution happens over a search index.
To get started with Azure Cognitive Search and Open AI .NET SDK, you can follow these steps:
      -Create an Azure Cognitive Search service in your Azure 
       account.
      -Install the Open AI .NET SDK and add the required NuGet 
       packages to your .NET project.
      -Create a search index and define the fields to be indexed.
      -Create a data source and define the connection string and 
       credentials for your data source.
      -Use the Open AI .NET SDK to upload data to your search 
       index.
      -Use the search API to query your search index and retrieve 
       relevant results.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k5hi5nx8btsllc3rk9gr.png)

**C# Code snippet for Azure Cognitive Search **

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8zgiaq03q0pmhnokevfp.png)



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1k5bu8wl8y9x10bgcd6q.png)

**Benefits of combining azure OpenAI with Azure blob**

-Faster time-to-market: The combination of Azure Open AI and Azure Blob enables developers to quickly build and deploy AI applications that can process large amounts of data. This can help organizations bring new products and services to market faster.
-Cost savings: By using Azure Blob for storage and Azure Open AI for AI processing, organizations can avoid the costs associated with managing on-premises hardware and software. Azure Blob's pay-as-you-go pricing model means that organizations only pay for what they use.
-Scalability: Azure Blob provides highly scalable storage, while Azure Open AI provides highly scalable AI processing. This means that organizations can store and process large amounts of data without worrying about capacity limitations.
-Improved data insights: By using Azure Open AI to analyze data stored in Azure Blob, organizations can gain valuable insights into customer behavior, market trends, and other important business metrics. This can help organizations make data-driven decisions and improve business outcomes.
-Security: Azure Blob provides built-in security features, such as access controls and encryption, to protect data stored in the cloud. Azure Open AI provides security features to protect AI models and algorithms. This combination of security features helps to ensure that data is kept safe throughout the AI processing pipeline.

_Overall, combining Azure Open AI with Azure Blob can help organizations to build powerful AI applications that can analyse large amounts of data, while providing scalability, cost savings, and improved data insights._

**Reference**
1.https://learn.microsoft.com/en-us/azure/ai-services/openai/use-your-data-quickstart?tabs=commandline%2Cpython&pivots=programming-language-studio
2.https://learn.microsoft.com/en-us/azure/ai-services/openai/concepts/use-your-data?tabs=ai-search
3.https://learn.microsoft.com/en-us/azure/search/cognitive-search-tutorial-blob-dotnet