{"id":26055597,"url":"https://github.com/john0isaac/rag-semantic-kernel-mongodb-vcore","last_synced_at":"2025-10-23T15:02:11.094Z","repository":{"id":222116869,"uuid":"756304363","full_name":"john0isaac/rag-semantic-kernel-mongodb-vcore","owner":"john0isaac","description":"A sample for implementing retrieval augmented generation using Azure Open AI to generate embeddings, Azure Cosmos DB for MongoDB vCore to perform vector search, and semantic kernel.","archived":false,"fork":false,"pushed_at":"2025-03-31T06:36:16.000Z","size":94468,"stargazers_count":33,"open_issues_count":2,"forks_count":62,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-31T17:17:15.765Z","etag":null,"topics":["azd-templates","azure","cosmosdb","mongodb","openai","python","quart","rag","semantic-kernel","vcore","vector-search"],"latest_commit_sha":null,"homepage":"https://techcommunity.microsoft.com/t5/educator-developer-blog/build-rag-chat-application-using-azure-openai-and-cosmos-db-for/ba-p/4055852","language":"Bicep","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/john0isaac.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-12T12:00:44.000Z","updated_at":"2025-03-13T18:52:40.000Z","dependencies_parsed_at":"2024-03-10T14:26:04.239Z","dependency_job_id":"f9680db3-565c-40da-9306-e71b40fe7116","html_url":"https://github.com/john0isaac/rag-semantic-kernel-mongodb-vcore","commit_stats":null,"previous_names":["john0isaac/rag-semantic-kernel-mongodb-vcore"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/john0isaac%2Frag-semantic-kernel-mongodb-vcore","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/john0isaac%2Frag-semantic-kernel-mongodb-vcore/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/john0isaac%2Frag-semantic-kernel-mongodb-vcore/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/john0isaac%2Frag-semantic-kernel-mongodb-vcore/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/john0isaac","download_url":"https://codeload.github.com/john0isaac/rag-semantic-kernel-mongodb-vcore/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247704571,"owners_count":20982298,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["azd-templates","azure","cosmosdb","mongodb","openai","python","quart","rag","semantic-kernel","vcore","vector-search"],"created_at":"2025-03-08T10:19:58.290Z","updated_at":"2025-10-23T15:02:06.075Z","avatar_url":"https://github.com/john0isaac.png","language":"Bicep","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\nname: RAG using Semantic Kernel with Azure OpenAI and Azure Cosmos DB for MongoDB vCore\ndescription: A Python sample for implementing retrieval augmented generation using Azure Open AI to generate embeddings, Azure Cosmos DB for MongoDB vCore to perform vector search and semantic kernel. Deployed to Azure App service using Azure Developer CLI (azd).\nlanguages:\n- azdeveloper\n- python\n- bicep\n- html\nproducts:\n- azure\n- azure-app-service\n- azure-openai\n- cosmos-db\n- mongodb-vcore\npage_type: sample\nurlFragment: rag-semantic-kernel-mongodb-vcore\n---\n\u003c!-- YAML front-matter schema: https://review.learn.microsoft.com/en-us/help/contribute/samples/process/onboarding?branch=main#supported-metadata-fields-for-readmemd --\u003e\n\n# RAG using Semantic Kernel with Azure OpenAI and Azure Cosmos DB for MongoDB vCore\n\nA Python sample for implementing retrieval augmented generation using Azure Open AI to generate embeddings, Azure Cosmos DB for MongoDB vCore to perform vector search and semantic kernel. Deployed to Azure App service using Azure Developer CLI (azd).\n\n[![Watch Live Session](https://img.youtube.com/vi/XHJj_M84X28/maxresdefault.jpg)](https://www.youtube.com/watch?v=LiS9CqR0ZSk)\n\u003e 🎥 Click this image to watch the recorded reactor workshop\n\n## How to use?\n\n1. Create the following resources on Microsoft Azure:\n\n    - Azure Cosmos DB for MongoDB vCore cluster. See the [Quick Start guide here](https://techcommunity.microsoft.com/t5/educator-developer-blog/build-rag-chat-app-using-azure-cosmos-db-for-mongodb-vcore-and/ba-p/4055852#:~:text=RAG%20Chat%20Application-,Step%201%3A%20Create%20an%20Azure%20Cosmos%20DB%20for%20MongoDB%20vCore%20Cluster,-In%20this%20step).\n    - Azure OpenAI resource with:\n        - Embedding model deployment. (ex. `text-embedding-ada-002`) See the [guide here](https://techcommunity.microsoft.com/t5/educator-developer-blog/build-rag-chat-app-using-azure-cosmos-db-for-mongodb-vcore-and/ba-p/4055852#:~:text=to%20it%20later.-,Step%202%3A%C2%A0Create%20an%20Azure%20OpenAI%20resource%20and%20Deploy%20chat%20and%20embedding%20Models,-In%20this%20step).\n        - Chat model deployment. (ex. `gpt-35-turbo`)\n\n1. 📝 Start here 👉 [rag-azure-openai-cosmosdb-notebook.ipynb](./rag-azure-openai-cosmosdb-notebook.ipynb)\n\n\nhttps://github.com/john0isaac/rag-semantic-kernel-mongodb-vcore/assets/64026625/676a0e10-876f-45e6-942d-0494ac327c75\n\n\nTest it inside codespaces 👇\n\n[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/john0isaac/rag-semantic-kernel-mongodb-vcore?devcontainer_path=.devcontainer/devcontainer.json)\n\n## Running the web app locally\n\nTo run the Quart application, follow these steps:\n\n1. **Download the project starter code locally**\n\n    ```bash\n    git clone https://github.com/john0isaac/rag-semantic-kernel-mongodb-vcore.git\n    cd rag-semantic-kernel-mongodb-vcore\n    ```\n\n1. **Install, initialize and activate a virtualenv using:**\n\n    ```bash\n    pip install virtualenv\n    python -m virtualenv .venv\n    source .venv/bin/activate\n    ```\n\n    \u003e**Note** - In Windows, the `.venv` does not have a `bin` directory. Therefore, you'd use the analogous command shown below:\n\n    ```bash\n    source .venv/Scripts/activate\n    ```\n\n1. **Install the dependencies:**\n\n    ```bash\n    pip install -r requirements-dev.txt\n    ```\n\n1. **Run the [notebook](./rag-azure-openai-cosmosdb-notebook.ipynb) to generate the .env file and test out everything first**\n\n1. **Install the app as an editable package:**\n\n    ```bash\n    pip install -e src\n    ```\n\n1. **Execute the following command in your terminal to start the quart app**\n\n    ```bash\n    export QUART_APP=src.quartapp\n    export QUART_ENV=development\n    export QUART_DEBUG=true\n    quart run --reload\n    ```\n\n    **For Windows, use [`setx`](https://learn.microsoft.com/windows-server/administration/windows-commands/setx) command shown below:**\n\n   ```powershell\n    setx QUART_APP src.quartapp\n    setx QUART_ENV development\n    setx QUART_DEBUG true\n    quart run --reload\n    ```\n\n1. **Verify on the Browser**\n\nNavigate to project homepage [http://127.0.0.1:5000/](http://127.0.0.1:5000/) or [http://localhost:5000](http://localhost:5000)\n\n\nhttps://github.com/john0isaac/rag-semantic-kernel-mongodb-vcore/assets/64026625/8a7556d6-2b54-40b5-825b-06d6efd4d1ca\n\n## Step-by-Step Deployment\n\nFollow this guide 👉 [Build RAG Chat App using Azure Cosmos DB for MongoDB vCore and Azure OpenAI: Step-by-Step Guide](https://techcommunity.microsoft.com/t5/educator-developer-blog/build-rag-chat-app-using-azure-cosmos-db-for-mongodb-vcore-and/ba-p/4055852)\n\n![architecture-thumbnail](https://github.com/john0isaac/rag-semantic-kernel-mongodb-vcore/assets/64026625/e0a4a412-55bf-4032-9cf7-82936419c746)\n\n## `azd` Deployment\n\n![architecture-thumbnail](https://github.com/john0isaac/rag-semantic-kernel-mongodb-vcore/assets/64026625/7ce8ae6e-0424-47ce-b0a3-9be072eda27f)\n\nThis repository is set up for deployment on Azure App Service (w/Azure Cosmos DB for MongoDB vCore) using the configuration files in the `infra` folder.\n\nTo deploy your own instance, follow these steps:\n\n1. Sign up for a [free Azure account](https://azure.microsoft.com/free/)\n\n1. Install the [Azure Dev CLI](https://learn.microsoft.com/azure/developer/azure-developer-cli/install-azd).\n\n1. Login to your Azure account:\n\n    ```shell\n    azd auth login\n    ```\n\n1. Initialize a new `azd` environment:\n\n    ```shell\n    azd init\n    ```\n\n    It will prompt you to provide a name (like \"quart-app\") that will later be used in the name of the deployed resources.\n\n1. Provision and deploy all the resources:\n\n    ```shell\n    azd up\n    ```\n\n    It will prompt you to login, pick a subscription, and provide a location (like \"eastus\"). Then it will provision the resources in your account and deploy the latest code. If you get an error with deployment, changing the location (like to \"centralus\") can help, as there may be availability constraints for some of the resources.\n\nWhen azd has finished deploying, you'll see an endpoint URI in the command output. Visit that URI to browse the app! 🎉\n\n\u003e [!NOTE]\n\u003e If you make any changes to the app code, you can just run this command to redeploy it:\n\u003e\n\u003e ```shell\n\u003e azd deploy\n\u003e ```\n\u003e\n\n## Add the Data\n\n1. Open the [Azure portal](https://portal.azure.com) and sign in.\n\n1. Navigate to your App Service page.\n\n    ![Azure App service screenshot with the word SSH highlighted in a red box.](https://github.com/john0isaac/rag-semantic-kernel-mongodb-vcore/assets/64026625/759db6be-604e-433c-878e-b6c3de671fd1)\n\n1. Select **SSH** from the left menu then, select **Go**.\n\n1. In the SSH terminal, run `pip install -e .` then run `python ./scripts/add_data.py`.\n\n## Add your Own Data\n\nThe Python scrips that adds the data is configured to accept any JSON file with your data but you need to specify the following parameters when you run it:\n\n- Data file path: Path to the JSON file that contains your data. `--file=\"./data/text-sample.json\"` or `-f \"./data/text-sample.json\"`\n- ID field: This is the name of the field that cosmos uses to identify your database records. `--id-field=id` or `-id id`\n- Text field: This is the name of the field that will be used to generate the vector embeddings from and stored in the database. `--text-field=content` or `-txt content`\n- Description field: This is the name of the description field that cosmos will store along with the embeddings. `--description-field=title` or `-desc title`\n\n    ```bash\n    python ./scripts/add_data.py --file=\"./data/text-sample.json\" --id-field=id --text-field=content --description-field=title\n    ```\n\n### Example for Step-by-step Manual Deployment\n\n1. Add your JSON data to the [data folder](./src/data/).\n\n1. The workflow will trigger automatically and push your data to the Azure App service.\n\n1. Open the [Azure portal](https://portal.azure.com) and sign in.\n\n1. Navigate to your App Service page.\n\n    ![Azure App service screenshot with the word SSH highlighted in a red box.](https://github.com/john0isaac/rag-semantic-kernel-mongodb-vcore/assets/64026625/759db6be-604e-433c-878e-b6c3de671fd1)\n\n1. Select **SSH** from the left menu then, select **Go**.\n\n1. In the SSH terminal, run the following command with the changed values to suit your data:\n\n    ```bash\n    pip install -e .\n    python ./scripts/add_data.py --file=\"./data/text-sample.json\" --id-field=id --text-field=content --description-field=title\n    ```\n\n### Example for `azd` Deployment\n\n1. Add your JSON data to the [data folder](./src/data/).\n\n1. Run `azd deploy` to upload the data to Azure App Service.\n\n1. Open the [Azure portal](https://portal.azure.com) and sign in.\n\n1. Navigate to your App Service page.\n\n    ![Azure App service screenshot with the word SSH highlighted in a red box.](https://github.com/john0isaac/rag-semantic-kernel-mongodb-vcore/assets/64026625/759db6be-604e-433c-878e-b6c3de671fd1)\n\n1. Select **SSH** from the left menu then, select **Go**.\n\n1. In the SSH terminal, run the following command with the changed values to suit your data:\n\n    ```bash\n    pip install -e .\n    python ./scripts/add_data.py --file=\"./data/text-sample.json\" --id-field=id --text-field=content --description-field=title\n    ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohn0isaac%2Frag-semantic-kernel-mongodb-vcore","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohn0isaac%2Frag-semantic-kernel-mongodb-vcore","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohn0isaac%2Frag-semantic-kernel-mongodb-vcore/lists"}