How ridabayi/medical-rag-chatbot works
Project Type and Purpose
• This is a full-stack RAG (Retrieval-Augmented Generation) chatbot specialized for medical content.
• It ingests medical PDFs, builds a vector index (FAISS), runs a backend API that queries an LLM, and serves a web UI.
• CI/CD is managed by Jenkins in Docker-in-Docker, with automated container image build, security scan (Trivy), push to AWS ECR, and deployment to AWS App Runner.
File Structure Analysis
• Top-level:
• Dockerfile / Jenkinsfile / custom_jenkins/Dockerfile: container definitions for the app and Jenkins.
• data/: raw PDF source.
• vectorstore/: persisted FAISS index.
• app/: core Python code.
• Within app/:
• application.py: Flask/FastAPI server entry point.
• common/: shared utilities (logging, exception handling).
• components/: ingest (data_loader, pdf_loader), vector build (embeddings, vector_store), retrieval (retriever), LLM integration (llm).
• config/: centralized configuration.
• templates/: HTML UI.
• setup.py & requirements.txt: packaging & dependencies.
README Insights
• Describes local setup, Jenkins CI pipeline, Docker, Trivy, AWS ECR, AWS App Runner.
• Highlights stages: checkout, build, scan, push, deploy.
• References AWS IAM roles and credentials.
Main Components
a. Frontend Web UI
• Browser → index.html served by the backend.
b. Backend API
• Flask/FastAPI application (application.py).
• Endpoints: “/chat” calls retriever & llm components.
c. Data Ingestion & Vector Store
• PDF loader → data_loader → embeddings → FAISS vector_store.
• Persisted on disk (vectorstore/db_faiss).
d. LLM Service
• External OpenAI or other LLM endpoint.
e. CI/CD Pipeline
• GitHub repo → Jenkins (custom_jenkins).
• Stages: Checkout → Docker build → Trivy scan → Push to AWS ECR → Deploy to AWS App Runner.
f. AWS Infrastructure
• ECR: container registry.
• App Runner: container deployment runtime.
• IAM: credentials for Jenkins to push/deploy.
• (Optionally) Secrets Manager for tokens.
Relationships & Data Flow
• Data Flow:
1. Admin drops PDF in data/ → ingestion pipeline populates FAISS.
2. User types query in UI → HTTP request to backend.
3. Backend uses retriever against FAISS → gets context.
4. Context + query sent to LLM → response returned.
5. Response sent back to UI.
• CI/CD Flow:
1. Code push to GitHub triggers Jenkins.
2. Jenkins container builds Docker image.
3. Trivy scans image; on success → tag & push to AWS ECR.
4. Jenkins invokes AWS CLI to update App Runner service.
• User → Browser → Backend.
• Backend → Vector Store & LLM.
• GitHub → Jenkins → ECR → App Runner.
Architectural Patterns & Design Principles
• Modular separation: ingestion, retrieval, LLM, API, UI.
• Single-responsibility components in app/components.
• Configuration centralization in app/config.
• Infrastructure as code via Dockerfiles and Jenkinsfile.
• Immutable container images and automated deployments.
Technologies & Frameworks
• Python (Flask or FastAPI).
• FAISS for vector search.
• OpenAI (or other) LLM API.
• Docker & Docker-in-Docker.
• Jenkins for CI/CD.
• Trivy for security scanning.
• AWS ECR & App Runner for container hosting.
• (Optionally AWS IAM, AWS CLI).
Advanced AWS Deployment Layer
• Jenkins container with AWS credentials deployed on-prem or in Docker.
• AWS App Runner pulling the image and running the service behind a load-balanced endpoint.
• IAM roles & policies linked to Jenkins.