A complete Retrieval-Augmented Generation (RAG) chat application built with FastAPI, Next.js, Azure AI Search, and OpenAI.
- Document Upload & Processing: Support for PDF, DOCX, TXT, and CSV files
- Intelligent Chat Interface: Ask questions about your documents using OpenAI GPT models
- Vector Search: Powered by Azure AI Search with hybrid search (text + vector)
- Source Citations: Get relevant document citations with every AI response
- Scalable Architecture: Containerized deployment on Azure Container Apps and Static Web Apps
βββββββββββββββββββββββ ββββββββββββββββββββββββ βββββββββββββββββββββββ
β Next.js Frontend βββββΆβ FastAPI Backend βββββΆβ Azure AI Search β
β (Azure Static Apps) β β (Azure Container App)β β (Vector Search) β
βββββββββββββββββββββββ ββββββββββββββββββββββββ βββββββββββββββββββββββ
β β
βΌ βΌ
ββββββββββββββββββββββββ βββββββββββββββββββββββ
β OpenAI API β β Azure Storage β
β (GPT + Embeddings) β β (Document Store) β
ββββββββββββββββββββββββ βββββββββββββββββββββββ
- FastAPI: High-performance Python web framework
- Azure AI Search: Hybrid vector search with semantic ranking
- OpenAI: GPT-4 for chat and text-embedding-3-small for embeddings
- LangChain: Document processing and RAG pipeline
- Azure Storage: Document storage
- Next.js 14: React framework with App Router
- TypeScript: Type-safe development
- Tailwind CSS: Utility-first CSS framework
- Lucide React: Beautiful icons
- Azure Container Apps: Serverless backend hosting
- Azure Static Web Apps: Frontend hosting with GitHub integration
- Docker: Containerization
- GitHub Actions: CI/CD pipeline
- Node.js 18+
- Python 3.11+
- Docker
- Azure CLI
- Terraform
- OpenAI API Key
- Azure Subscription
git clone https://github.com/AndreLiar/Azure-Rag_Chat.git
cd Azure-Rag_ChatBackend (.env):
cd backend
cp .env.example .env
# Edit .env with your credentialsFrontend:
cd frontend
# Environment variables are configured via next.config.jsStart Backend:
cd backend
pip install -r requirements.txt
python -m uvicorn main:app --reloadStart Frontend:
cd frontend
npm install
npm run devVisit: http://localhost:3000
# Build and run both services
docker-compose up --build- Deploy Infrastructure:
cd infra
terraform init
terraform apply- Configure GitHub Secrets:
# Required for CI/CD
AZURE_CREDENTIALS
OPENAI_API_KEY
AZURE_SEARCH_ENDPOINT
AZURE_SEARCH_KEY
AZURE_STORAGE_ACCOUNT_NAME
AZURE_STATIC_WEB_APPS_API_TOKEN- Push to GitHub:
git add .
git commit -m "Initial deployment"
git push origin mainThe CI/CD pipeline will automatically:
- Build and test both applications
- Create Docker images
- Deploy backend to Azure Container Apps
- Deploy frontend to Azure Static Web Apps
Once the backend is running, visit:
- Swagger UI:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc
POST /upload- Upload and process documentsPOST /chat- Chat with your documentsGET /documents- List uploaded documentsDELETE /documents/{id}- Delete a document
- Document Upload: Users upload documents (PDF, DOCX, TXT, CSV)
- Processing: Documents are split into chunks and embedded using OpenAI
- Indexing: Chunks are stored in Azure AI Search with vector embeddings
- Query: Users ask questions through the chat interface
- Retrieval: System searches for relevant document chunks
- Generation: OpenAI generates responses using retrieved context
- Response: Users receive answers with source citations
- Free Tier: Supports up to 50MB of documents
- Vector Dimensions: 1536 (OpenAI text-embedding-3-small)
- Search Algorithm: HNSW with cosine similarity
- Chat: gpt-4o-mini (configurable)
- Embeddings: text-embedding-3-small
- Temperature: 0.7 for balanced creativity
- CPU: 0.25 cores
- Memory: 0.5 GB
- Scaling: 1-3 replicas based on load
- OpenAI API Key: Ensure valid API key with sufficient credits
- Azure Search: Check service name and admin key
- CORS: Configure allowed origins in backend
- Docker Build: Ensure all dependencies are in requirements.txt
# Enable debug logging
export LOG_LEVEL=DEBUG- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is open source and available under the MIT License.
- β
Azure Resource Group:
ragchat12481-rg - β
Azure AI Search:
ragchat12481-search - β
Azure Storage:
ragchat12481sa - β
Azure Static Web App:
https://zealous-grass-0c5e85103.3.azurestaticapps.net - β
Azure Container Apps Environment:
ragchat12481-cae
- π’ Backend API: Running locally
- π’ Frontend UI: Running locally
- π‘ Container Apps: Ready for deployment
- π‘ CI/CD Pipeline: Configured, ready for first push
- Push code to GitHub repository
- Configure GitHub secrets for deployment
- CI/CD will automatically deploy to Azure
- Test the full production environment
Once deployed, the application will be available at:
- Frontend: https://zealous-grass-0c5e85103.3.azurestaticapps.net
- Backend API: Will be provided after Container Apps deployment# Trigger CI/CD Pipeline