RAG apps need more than vector search. They need openness, portability, and real cloud scale. Azure DocumentDB (with MongoDB compatibility) is built on an open-source 99.03% MongoDB wire-protocol compatibility. Run it in Azure as a fully managed service or use the same engine across clouds and on-premises with no app changes. Integrated vector search comes included, alongside automatic scaling, enterprise security, and native Azure integration. One database. Open by design. Built for mission-critical AI applications.
Scenario
Imagine you are building your company’s RAG chat application using Microsoft Foundry - Azure OpenAI and orchestrating the flow with LangChain. The chat experience works, but now it needs to be grounded in your company’s data. You generate embeddings and want to store and query them without adding another database or complex sync pipeline. Instead of stitching services together, you use Azure DocumentDB (with MongoDB compatibility) with built-in vector search to store your JSON data and embeddings in one place. You deploy the app to Azure App Service and quickly compare vector search alone versus a full RAG pipeline, sharing it with your team for testing.
What will you learn?
In this blog, you'll learn to:
- Create an Azure DocumentDB (with MongoDB compatibility) resource.
- Create an embeddings and a chat deployment in Microsoft Foundry Azure OpenAI portal.
- Create an Azure App Service website with continuous deployment from GitHub.
- Configure Azure App Service application settings to enable communication between Azure resources.
- Configure GitHub workflow to work successfully.
What is the main objective?
Build AI Powered RAG Application using LangChain, Microsoft Foundry Azure OpenAI, and Azure DocumentDB (with MongoDB compatibility): Step-by-Step Guide
Prerequisites
- An Azure subscription.
- If you don’t already have one, you can sign up for an Azure free account.
- For students, you can use the free Azure for Students offer which doesn’t require a credit card only your school email.
- A GitHub account.
Summary of the steps:
- Step 1: Create an Azure DocumentDB (with MongoDB compatibility) resource
- Step 2: Create a Microsoft Foundry - Azure OpenAI resource and Deploy chat and embedding Models
- Step 3: Create an Azure App Service and Deploy the RAG Chat Application
Step 1: Create an Azure DocumentDB (with MongoDB compatibility) resource
In this step, you'll:
- Open the Azure Portal.
- Create an Azure DocumentDB (with MongoDB compatibility) resource.
Open the Azure Portal
1. Visit the Azure Portal https://portal.azure.com in your browser and sign in.
Now you are inside the Azure portal!
Create a new Azure DocumentDB (with MongoDB compatibility) resource
In this step, you create an Azure DocumentDB (with MongoDB compatibility) resource to store your data, vector embedding, and perform vector search.
1. Type documentdb in the search bar at the top of the portal page and select Azure DocumentDB (with MongoDB compatibility) from the available options.
2. Select Create from the toolbar to start provisioning your new cluster.
3. Add the following information to create a resource:
| What | Value |
| Subscription | Use your preferred subscription. It's advised to use the same subscription across all the resources that communicate with each other on Azure. |
| Resource group | Select Create new to create a new resource group. Enter a unique name for the resource group. |
| Cluster name | Enter a globally unique name. |
| Location | Select a region close to you for the best response time. For example, Select UK South. |
| MongoDB version | Select the latest available version of MongoDB |
4. Select Configure to configure your cluster tier.
5. Add the following information to configure the cluster tier. You can scale it up later:
| What | Value |
| Cluster tier | Select M25 tier, 2 (Burstable) vCores. |
| Storage |
Select 32 GiB. |
6. Select Save.
7. Enter the cluster Admin Username and Password and store them in a secure location.
8. Select Next to configure the networking settings.
9. Select Allow Public Access from Azure services and resources within the Azure to this cluster.
10. Select Add current IP address to the firewall rules to allow local access to the cluster.
11. Select Review + create.
12. Confirm your configuration settings and select Create to start provisioning the resource.
Note: The cluster creation can take up to 10 minutes. It's recommended to move on with the rest of the steps and get back to it later.
Step 2: Create a Microsoft Foundry - Azure OpenAI resource and Deploy chat and embedding Models
In this step, you'll:
- Create a Microsoft Foundry Azure OpenAI resource.
- Create chat and embedding model deployments.
Create an Azure OpenAI resource
In this step, you create an Azure OpenAI Service resource that enables you to interact with different large language models (LLMs).
1. Type openai in the search bar at the top of the portal page and select Azure OpenAI from the available options.
2. Select Create from the toolbar then select Azure OpenAI to provision a new Azure OpenAI resource.
3. Add the following information to create a resource:
| What | Value |
| Subscription | Use the same subscription you used to apply for Azure OpenAI access. |
| Resource group | Use the resource group you created in the previous step. |
| Region | Select a region close to you for the best response time. For example, Select UK South. |
| Name | Enter a globally unique name. |
| Pricing tier |
Select S0. Currently, this is the only available pricing tier.
|
4. Now that the basic information is added, select Next to confirm your details and proceed to the next page.
5. Select Next to confirm your network details.
6. Select Next to confirm your tag details.
7. Confirm your configuration settings and select Create to start provisioning the resource. Wait for the deployment to finish.
8. After the deployment finishes, select Go to resource to inspect your created resource. Here, you can manage your resource and find important information like the endpoint URL and API keys.
Create chat and embedding model deployments
In this step, you create an Azure OpenAI embedding model deployment and a chat model deployment. Creating a deployment on your previously provisioned resource allows you to generate text embeddings (i.e. numerical representation for text) and have a natural language conversation with your data.
1. Select Go to Foundry portal from the toolbar to open the studio.
2. Select Deployments from the Shared resources left side menu to go to the deployments tab.
3. Select + Deploy model from the toolbar then select Deploy base model from the options. A Deploy model window opens.
4. Type gpt-4o-mini to search for the model then select it then select Use model.
5. Select Continue with existing setup to proceed to next step.
6. Refresh page and repeat previous steps to select the model then select Confirm.
7. Review selected options then select Deploy.
8. Select + Deploy model from the toolbar then select Deploy base model from the options. A Deploy model window opens.
9. Type text-embedding-3-small to search for the model then select it then select Confirm.
10. Review selected options then select Deploy.
Step 3: Create an Azure App Service and Deploy the RAG Chat Application
In this step, you'll:
- Fork the sample repository on GitHub.
- Create an Azure App Service resource with a deployment from GitHub.
- Modify Azure App Service Application settings in the Azure portal.
- Configure the workflow to deploy your application from GitHub.
- Test the website before and after adding the data.
Fork the Sample Repository on GitHub
In this step, you create a copy from the source code on your GitHub account to be able to edit it and use it later.
1. Visit the sample github.com/Azure-Samples/Cosmic-Food-RAG-app in your browser and sign in.
2. Select Fork from the top of the sample page.
3. Select an owner for the fork then, select Create fork.
Create an Azure App Service resource with a deployment from GitHub
In this step, you create an Azure App service resource and connect it with your GitHub account to deploy a Python application.
1. Type app service in the search bar at the top of the portal page and select App Services from the available options.
2. Select Create Web App from the toolbar to start provisioning a new web application.
3. Add the following information to fill in the basic configuration of the application:
| What | Value |
| Subscription | Use the same subscription you used to apply for Azure OpenAI access. |
| Resource group | Use the same resource group you created before. |
| Name | Enter a unique name for your website. For example, cosmic-food-rag. |
| Publish? | Select Code. This option specifies whether your deployment consists of code or a container. |
| Runtime stack | Select Python 3.12. |
| Operating System | Select Linux. |
| Region | Select UK South. This is the region where the rest of the resources you created reside. |
4. Add the following information to create the app service plan. You can scale it up later:
| What | Value |
| Linux Plan | Select a pre-existing plan or create a new plan. |
| Pricing Plan |
Select Basic B1. |
5. Select Deployment from the toolbar to move to the deployment configuration tab.
6. Add the following information to enable continuous deployment from GitHub:
| What | Value |
| Continuous deployment | Select Enable. |
| GitHub account | Select your GitHub account. |
| Organization | Select your organization. If you are using your personal account then select it. |
| Repository | Select Cosmic-Food-RAG-app. |
| Branch | Select main. |
7. Select Review + create.
8. Confirm your configuration settings and select Create to start provisioning the resource. Wait for the deployment to finish.
9. After the deployment finishes, select Go to resource to inspect your created resource. Here, you can manage your resource and find important information like the application settings and logs.
Modify Azure App service Application settings in the Azure portal
In this step, you configure the Application settings to make the website able to communicate with other cloud resources.
| What | Value |
|
OPENAI_API_VERSION |
2024-10-21 |
| AZURE_OPENAI_CHAT_DEPLOYMENT_NAME |
gpt-4o-mini |
|
AZURE_OPENAI_CHAT_MODEL_NAME |
gpt-4o-mini |
| AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT_NAME |
text-embedding-3-small |
|
AZURE_OPENAI_EMBEDDINGS_MODEL_NAME |
text-embedding-3-small |
|
AZURE_OPENAI_EMBEDDINGS_DIMENSIONS |
1536 |
| AZURE_OPENAI_DEPLOYMENT_NAME | <azureOpenAiResourceName> |
| AZURE_OPENAI_ENDPOINT | https://<azureOpenAiResourceName>.openai.azure.com/ |
| AZURE_OPENAI_API_KEY | <azureOpenAiResourceKey> |
|
AZURE_COSMOS_USERNAME | <documentUsername> |
|
AZURE_COSMOS_PASSWORD | <documentPassword> |
|
AZURE_COSMOS_CONNECTION_STRING |
mongodb+srv://<user>:<password>@<clusterName>.global.mongocluster.cosmos.azure.com/?tls=true&authMechanism=SCRAM-SHA-256&retrywrites=false&maxIdleTimeMS=120000 |
|
AZURE_COSMOS_DATABASE_NAME | <documentDatabaseName> ex.
CosmicDB |
|
AZURE_COSMOS_COLLECTION_NAME | <documentContainerName> ex.
CosmicFoodCollection |
|
AZURE_COSMOS_INDEX_NAME | <documentIndexName> ex.
CosmicIndex |
4. Select Apply to save your newly added environment variables.
5. Select Configuration then Stack settings to edit the application startup command.
6. Type entrypoint.sh in the startup command field then select Apply.
Configure the Workflow to deploy your application from GitHub
In this step, you modify the GitHub deployment workflow to point to the folder that contains the application.3. Open the file and select the pen icon to edit it.
4. Modify line 41 from . to src/.
5. Remove the optional Local Build Section since the application already has tests that cover this part.
6. Add this section to Install Node 22 and build the static frontend.
7. Select Commit changes, and review your commit message and description. Select Commit changes.
The final workflow file should look like this:
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions
# More info on Python, GitHub Actions, and Azure App Service: https://aka.ms/python-webapps-actions
name: Build and deploy Python app to Azure Web App - cosmic-food-rag
on:
push:
branches:
- main
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read #This is required for actions/checkout
steps:
- uses: actions/checkout@v4
- name: Set up Node 22
uses: actions/setup-node@v6
with:
node-version: 22
- name: Install Node Packages & Build Static Site
run: cd frontend && npm install && npm run build
# By default, when you enable GitHub CI/CD integration through the Azure portal, the platform automatically sets the SCM_DO_BUILD_DURING_DEPLOYMENT application setting to true. This triggers the use of Oryx, a build engine that handles application compilation and dependency installation (e.g., pip install) directly on the platform during deployment. Hence, we exclude the antenv virtual environment directory from the deployment artifact to reduce the payload size.
- name: Upload artifact for deployment jobs
uses: actions/upload-artifact@v4
with:
name: python-app
path: |
src/
!antenv/
# 🚫 Opting Out of Oryx Build
# If you prefer to disable the Oryx build process during deployment, follow these steps:
# 1. Remove the SCM_DO_BUILD_DURING_DEPLOYMENT app setting from your Azure App Service Environment variables.
# 2. Refer to sample workflows for alternative deployment strategies: https://github.com/Azure/actions-workflow-samples/tree/master/AppService
deploy:
runs-on: ubuntu-latest
needs: build
permissions:
id-token: write #This is required for requesting the JWT
contents: read #This is required for actions/checkout
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v4
with:
name: python-app
- name: Login to Azure
uses: azure/login@v2
with:
client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_5672547ED09F46D59DD431ACF5A29F28 }}
tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_0059913572C8467882D3999D0E0DD5B8 }}
subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_7C42E3352C5D47F084CB0CD14F549D27 }}
- name: 'Deploy to Azure Web App'
uses: azure/webapps-deploy@v3
id: deploy-to-webapp
with:
app-name: 'cosmic-food-rag'
slot-name: 'Production'
8. Select Actions to review the workflow run status.
Test the website before and After adding the data
In this step, you test the application before adding the data, add the data, and test again.2. Select any of the suggested messages or type your own and it should respond with No results found.
3. Navigate to your Azure App Service resource page and select SSH then select Go to open a new SSH page.4. In the SSH terminal, run these commands:
|
|
5. Navigate back to the live website and type in the chat message Do you have any vegan food dishes? and it should respond with the correct answer now.
Congratulations!! You successfully built the full application.
Clean Up
Once you finish experimenting on Microsoft Azure you might want to delete the resources to not consume any more money from your subscription.
You can delete the resource group and it will delete everything inside it or delete the resources one by one that's totally up to you.
Conclusion
Congratulations! You've learned how to create an Azure DocumentDB (with MongoDB compatibility) cluster, how to create a Microsoft Foundry - Azure OpenAI resource, how to deploy an embedding model and a chat model from the Foundry portal, how to create an Azure App Service and configure continuous deployment with GitHub, and how to modify application settings to enable the communication across Azure resources. By using these technologies, you can build a RAG chat application with the option to perform vector search too over your own data and provide grounded (relevant) responses.
Next steps
Documentation
- Azure OpenAI in Microsoft Foundry models
- Understand embeddings in Azure OpenAI in Microsoft Foundry Models (classic)
- Azure DocumentDB (with MongoDB compatibility) documentation
- Integrated vector store in Azure DocumentDB
- LangChain Python documentation
Training Content
Found this useful? Share it with others and follow me to get updates on:
- Twitter (twitter.com/john00isaac)
- LinkedIn (linkedin.com/in/john0isaac)
Feel free to share your comments and/or inquiries in the comment section below..See you in future demos!