page_type | languages | products | urlFragment | name | description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
sample |
|
|
ai-samples |
Build Copilot app using Azure Cosmos DB for NoSQL |
Build a Copilot app using Azure Cosmos DB for NoSQL, Azure OpenAI Service, Azure App Service and Semantic Kernel |
Build a Copilot app using Azure Cosmos DB for NoSQL, Azure OpenAI Service, Azure App Service and Semantic Kernel
This sample application shows how to build a multi-tenant, multi-user, Generative-AI RAG Pattern application using Azure Cosmos DB for NoSQL with its new vector database capabilities with Azure OpenAI Service on Azure App Service. This sample shows both using Native SDKs as well as Semantic Kernel integration. The sample provides practical guidance on many concepts you will need to design and build these types of applications.
This template, the application code and configuration it contains, has been built to showcase Microsoft Azure specific services and tools. We strongly advise our customers not to make this code part of their production environments without implementing or enabling additional security features.
This application demonstrates the following concepts and how to implement them:
- How to build a highly scalable, multi-tenant & user, Generative-AI chat application using Azure Cosmos DB for NoSQL.
- Generating completions and embeddings using Azure OpenAI Service.
- Managing a context window (chat history) for natural conversational interactions with an LLM.
- Manage per-request token consumption and payload sizes for Azure OpenAI Service requests.
- Building a semantic cache using Azure Cosmos DB for NoSQL vector search for improved performance and cost.
- Using the Semantic Kernel SDK for completion and embeddings generation.
- Implementing RAG Pattern using vector search in Azure Cosmos DB for NoSQL on custom data to augment generated responses from an LLM.
-
Azure subscription.
-
Subscription access to Azure OpenAI service. Start here to Request Access to Azure OpenAI Service. If you have access, see below for ensuring enough quota to deploy.
-
Enroll in the Azure Cosmos DB for NoSQL Vector Search Preview (See below for more details)
-
.NET 8 or above. Download
-
Visual Studio, VS Code, GitHub Codespaces or another editor to edit or view the source for this sample.
This lab utilizes a preview feature, Vector search for Azure Cosmos DB for NoSQL which requires preview feature registration. Follow the below steps to register. You must be enrolled before you can deploy this solution:
- Navigate to your Azure Cosmos DB for NoSQL resource page.
- Select the "Features" pane under the "Settings" menu item.
- Select for “Vector Search in Azure Cosmos DB for NoSQL”.
- Read the description to confirm you want to enroll in the preview.
- Select "Enable" to enroll in the Vector Search preview.
For this sample to deploy successfully, there needs to be enough Azure OpenAI quota for the models used by this sample within your subscription. This sample deploys a new Azure OpenAI account with two models, gpt-4o with 10K tokens per minute and text-3-large with 5k tokens per minute. For more information on how to check your model quota and change it, see Manage Azure OpenAI Service Quota
This solution deploys user-assigned managed identities and defines then applies Azure Cosmos DB RBAC permissions to this identity. At a minimum you will need the following Azure RBAC roles assigned to your identity in your Azure subscription or Subscription Owner access which will give you both of the following.
You can run this template virtually by using GitHub Codespaces. The button will open a web-based VS Code instance in your browser:
-
Open the template (this may take several minutes):
-
Open a terminal window
-
Continue with the deploying steps
If you're not using one of the above options for opening the project, then you'll need to:
-
Make sure the following tools are installed:
- .NET 8
- Git
- Azure Developer CLI (azd)
- VS Code or Visual Studio
- If using VS Code, install the C# Dev Kit
-
Download the project code:
azd init -t cosmosdb-nosql-copilot
-
If you're using Visual Studio, open the src/cosmos-copilot.sln solution file. If you're using VS Code, open the src folder.
-
Continue with the deploying steps.
A related option is VS Code Dev Containers, which will open the project in your local VS Code using the Dev Containers extension:
-
Start Docker Desktop (install it if not already installed)
-
Open the project:
-
In the VS Code window that opens, once the project files show up (this may take several minutes), open a terminal window.
-
Continue with the deploying steps
-
Open a terminal and navigate to where you would like to clone this solution
-
Run the following command to download the solution locally to your machine:
azd init -t AzureCosmosDB/cosmosdb-nosql-copilot
-
From the terminal, navigate to the /infra directory in this solution.
-
Log in to AZD.
azd auth login
-
Provision the Azure services, build your local solution container, and deploy the application.
azd up
When you deploy this solution it automatically injects endpoints and configuration values into the secrets.json file used by .NET applications.
To modify values for the Quickstarts, locate the value of UserSecretsId
in the csproj file in the /src folder of this sample and save the value.
<PropertyGroup>
<UserSecretsId>your-guid-here</UserSecretsId>
</PropertyGroup>
Locate the secrets.json file and open with a text editor.
- Windows:
C:\Users\<YourUserName>\AppData\Roaming\Microsoft\UserSecrets\<UserSecretsId>\secrets.json
- macOS/Linux:
~/.microsoft/usersecrets/<UserSecretsId>/secrets.json
Follow the Quickstarts in this solution to go through the concepts for building RAG Pattern apps and the features in this sample and how to implement them yourself.
Please see Quickstarts
-
Open a terminal and navigate to the /infra directory in this solution.
-
Type azd down
azd down
This template uses gpt-4o and text-embedding-3-large models which may not be available in all Azure regions. Check for up-to-date region availability and select a region during deployment accordingly
- We recommend using `eastus2', 'eastus', 'japaneast', 'uksouth', 'northeurope', or 'westus3'
You can estimate the cost of this project's architecture with Azure's pricing calculator
As an example in US dollars, here's how the sample is currently built:
Average Monthly Cost:
- Azure Cosmos DB Serverless ($0.25 USD per 1M RU/s): $0.25
- Azure App Service (B1 Plan): $12.41
- Azure OpenAI (GPT-4o 1M input/output tokens): $20 (Sample uses 10K tokens)
- Azure OpenAI (text-3-large): < $0.01 (Sample uses 5K tokens)
To learn more about the services and features demonstrated in this sample, see the following: