zakaria-ch49/Medical-Question-Answering-with-Retrieval-Augmented-Generation_RAG
<div align="center">
π₯ Medical RAG Assistant
AI-Powered Medical Question Answering with Retrieval-Augmented Generation
    
</div>
π What's New
<br/>
An intelligent medical assistant that retrieves real scientific evidence from PubMed and generates structured, evidence-based answers using state-of-the-art LLMs.
β οΈ For educational purposes only β not a substitute for professional medical advice.
</div>
π― Try the Live Demo
<div align="center">

</div>
β¨ Features
π Architecture
User Question (any language)
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββ
β Streamlit Web UI β
β src/streamlit_app.py β
ββββββββββββββββββββ¬βββββββββββββββββββββββββββββ
β
βββββββββββββββΌβββββββββββββββ
β Query Translator β OpenRouter API
β (LLM β MeSH English) β ββββββββββββββββββ
βββββββββββββββ¬βββββββββββββββ
β optimised PubMed query
βββββββββββββββΌβββββββββββββββ
β PubMed Downloader β src/download_pubmed.py
β NCBI E-utilities API β (batch fetch, up to 200 articles)
βββββββββββββββ¬βββββββββββββββ
β title + abstract (preprocessed)
βββββββββββββββΌβββββββββββββββ
β BGE Embedding Engine β src/bio_clinical_embeddings.py
β BAAI/bge-base-en β
β FAISS Vector Index β
βββββββββββββββ¬βββββββββββββββ
β top-k relevant documents (BGE score β€ 0.30)
βββββββββββββββΌβββββββββββββββ
β OpenRouter LLM β src/open_router.py
β Qwen3-235B-A22B-Thinking β (streaming SSE)
βββββββββββββββ¬βββββββββββββββ
β
Structured Medical Answer
(cited, evidence-graded, multilingual)π¬ RAG Pipeline β Step by Step
π Project Structure
medical-rag-assistant/
β
βββ src/
β βββ streamlit_app.py # π₯οΈ Streamlit web interface (main entry point)
β βββ main.py # β¨οΈ CLI interface (interactive terminal mode)
β βββ download_pubmed.py # π₯ PubMed batch downloader + text preprocessor
β βββ bio_clinical_embeddings.py # π§ BGE embeddings + FAISS vector store
β βββ open_router.py # π€ OpenRouter LLM client (streaming + sync)
β
βββ tests/
β βββ conftest.py # Pytest configuration & shared fixtures
β βββ test_download_pubmed.py # Unit tests β PubMed downloader
β βββ test_bio_clinical_embeddings.py # Unit tests β embeddings & search
β βββ test_open_router.py # Unit tests β OpenRouter client
β
βββ data/
β βββ cache/ # πΎ Auto-generated PubMed cache (git-ignored)
β
βββ .github/workflows/ci.yml # β
GitHub Actions CI (pytest on every push)
βββ .env.example # π Environment variable template
βββ Dockerfile # π³ Container image definition
βββ docker-compose.yml # π³ One-command local deployment
βββ Makefile # π οΈ Developer shortcuts (install, run, cleanβ¦)
βββ requirements.txt # π¦ Full Python dependencies
βββ requirements-ci.txt # π¦ Lightweight CI-only dependenciesπ Quick Start
Prerequisites
- Python 3.11+
- An OpenRouter API key β free tier available
1 Β· Clone & configure
git clone https://github.com/zakaria-ch49/Medical-Question-Answering-with-RAG.git
cd Medical-Question-Answering-with-RAG
cp .env.example .env
# Open .env and paste your OPENROUTER_API_KEY2 Β· Install dependencies
pip install -r requirements.txt
# or: make install3 Β· Launch the web UI
streamlit run src/streamlit_app.py
# or: make runOpen http://localhost:8501 in your browser.
4 Β· (Optional) CLI mode
python src/main.py
# or: make cliπ³ Docker Deployment
# Build and start (detached)
docker compose up --build -d
# Follow logs
docker compose logs -f
# Stop
docker compose downThe app is exposed on port 7860 (HuggingFace Spaces compatible).
β Running Tests
pip install -r requirements-ci.txt
pytest tests/ -vThe test suite uses mocks β no internet connection or GPU required.
βοΈ Environment Variables
Create a .env file from the template:
cp .env.example .envπ¦ Tech Stack
LLM β `qwen/qwen3-vl-235b-a22b-thinking` - 235 billion total parameters Β· 22 billion active (Mixture of Experts) - Advanced chain-of-thought reasoning Β· Multilingual Β· Strong medical comprehension
β οΈ Limitations
- π Internet required β PubMed and openFDA articles are fetched live; no offline mode
- π’ Cold start β BGE embedding model loads on first query (~30 s on CPU)
- π Abstracts only β Full-text articles are not retrieved, only titles & abstracts
- π API key required β An OpenRouter key is needed to generate answers
- π₯ Not for clinical use β For educational and research purposes only; always consult a healthcare professional
- π English-biased β PubMed is predominantly in English; non-English queries may return fewer results
πΊοΈ Roadmap
π‘ Contributions welcome! Feel free to open issues or pull requests.
π License
This project is licensed under the MIT License β see the LICENSE file for details.
<div align="center">
Made with β€οΈ by Zakaria CHADADI for medical AI research

</div>
