Skip to content

abdelghafourbamoula/rag-azure-mlops

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RAG Azure MLOps

A Retrieval-Augmented Generation (RAG) sample project using Azure OpenAI, FastAPI, and React. This repository demonstrates a workflow for uploading documents, converting them into embeddings, storing them in a vector store (ChromaDB), and answering user questions via a RAG pipeline.

Quick overview

  • Backend: FastAPI (Python) — exposes endpoints for health, upload, and query
  • RAG logic: src/rag/ implements document processing, vector store integration, and the RAG chain
  • Vector store: ChromaDB (local persistence under data/chroma_db/)
  • Frontend: React app under frontend/ (dev server on http://localhost:3000)

Project structure

rag-azure-mlops/
├── config/
│   └── settings.py             # Configuration (pydantic settings)
├── data/
│   └── chroma_db/              # ChromaDB persistence (ignored in git)
├── frontend/
│   ├── package.json
│   └── src/
│       ├── App.js              # Main React component
│       └── services/api.js     # Frontend API client
├── notebooks/
│   └── test.ipynb
├── requirements.txt            # Python dependencies
├── src/
│   ├── api/
│   │   └── main.py             # FastAPI entrypoint
│   └── rag/
│       ├── document_processor.py
│       ├── rag_chain.py
│       └── vector_store.py
├── tests/
│   └── test_rag.py
├── .env                        # Local environment variables (not committed)
├── .gitignore
└── README.md

Azure cloud architecture

The following diagram shows a minimal Azure-based deployment for this RAG MLOps sample. It uses Azure Container Apps (or Container Instances) for the application layer, an Azure Storage Account for documents and vector persistence (ChromaDB), Azure OpenAI for LLM inference, and Azure monitoring tooling for observability.

Azure RAG MLOps Architecture

If you want to regenerate the diagram locally the repository includes a small diagrams script at docs/architechture.py which uses the diagrams Python package. The script outputs docs/architecture_minimal.png when run. Example:

# from the repo root
python docs\architechture.py
# or run the diagrams CLI if you have it installed

Notes:

  • The diagram in docs/architechture.png is a minimal, illustrative architecture — adapt for production (VNet, private endpoints, managed identity, key vault access policies, storage lifecycle rules).
  • Recommended production changes: use managed identities, restrict Key Vault access, store vector DB in a managed store or dedicated service, and enable private networking between components.

Prerequisites

  • Python 3.8+
  • Node.js 14+
  • An Azure OpenAI resource (API key, endpoint, deployment names)

Backend setup

  1. Create and activate a virtual environment
python -m venv .venv
.venv\Scripts\activate
  1. Install dependencies
pip install -r requirements.txt
  1. Create a .env file in the repo root (example):
# Azure OpenAI
AZURE_OPENAI_API_KEY=your_azure_openai_api_key
AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com/
AZURE_OPENAI_DEPLOYMENT_NAME=gpt-4
AZURE_OPENAI_EMBEDDING_DEPLOYMENT=text-embedding-ada-002
AZURE_OPENAI_API_VERSION=2024-02-15-preview

# Vector DB
CHROMA_PERSIST_DIRECTORY=./data/chroma_db

# App
CHUNK_SIZE=1000
CHUNK_OVERLAP=200
TOP_K_RESULTS=5
LOG_LEVEL=INFO

# CORS - comma separated
CORS_ALLOW_ORIGINS=http://localhost:3000,http://127.0.0.1:3000

NOTE: If your app uses graphviz for rendering diagrams, install the Graphviz system binaries and add the dot executable to your PATH on Windows.

Run (development)

Start backend:

.venv\Scripts\activate
uvicorn src.api.main:app --reload

Start frontend:

cd frontend
npm install
npm start

Frontend: http://localhost:3000 Backend: http://localhost:8000 (OpenAPI docs at /docs)

Notes & troubleshooting

  • CORS: The backend reads CORS_ALLOW_ORIGINS from .env and converts comma-separated values to a list. For production, restrict origins.
  • LangChain/Chroma: You may see deprecation warnings for langchain.Chroma. Consider migrating to langchain-chroma if required by your runtime.
  • Graphviz: If you see ExecutableNotFound: failed to execute WindowsPath('dot'), install Graphviz and add the bin folder to PATH.

Tests

Run tests:

.venv\Scripts\activate
pytest -q

Contributing

Open issues or PRs. Add tests for new features and keep changes small.

License

MIT


If you want this README shortened, add badges, or include CI examples (GitHub Actions), tell me which parts to expand or remove and I will update it.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published