/RAG-FirstAid-Chatbot

This chatbot uses a Retrieval-Augmented Generation (RAG) approach to provide first-aid support for Diabetes, Cardiac, and Renal emergencies.

Primary LanguagePython

๐Ÿค– RAG-Powered First-Aid Chatbot

A smart chatbot that provides short, medically-aware first-aid guidance for emergencies related to:

  • Diabetes
  • Cardiac issues
  • Renal conditions

It uses:

  • ๐Ÿง  Gemini API for condition detection and final answer generation
  • ๐Ÿ“š Local medical knowledge (from a curated Excel file)
  • ๐ŸŒ Live web search using Serper.dev (Google Search API)
  • โœ… Answers limited to โ‰ค 250 words with disclaimers and citations

โš ๏ธ Disclaimer

This chatbot is for educational purposes only and is not a substitute for professional medical advice.


๐Ÿ“ Folder Structure

RAG-FirstAid-Chatbot/
โ”‚
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ chatbot.py                  # Main pipeline
โ”‚   โ”œโ”€โ”€ model.py                    # Checkout the model available through API
โ”‚   โ”œโ”€โ”€ triage.py                   # Gemini: symptom โ†’ condition
โ”‚   โ”œโ”€โ”€ retrieval.py                # Local snippet retriever
โ”‚   โ”œโ”€โ”€ web_search.py               # Serper.dev integration
โ”‚   โ””โ”€โ”€ generator.py                # Gemini: RAG response builder
โ”‚
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ test_bot.py                 # Unit test for pipeline
โ”‚   |โ”€โ”€ test_queries.py             # Evaluates all 10 official test cases
โ”‚   โ””โ”€โ”€ test_queries_response.md    # Response of all 10 official test cases
โ”‚
โ”œโ”€โ”€ Assignment Data Base.xlsx       # Local knowledge base
โ”œโ”€โ”€ requirements.txt                # List of required libraries
โ”œโ”€โ”€ .env                            # API keys
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ architecture.md                 # System flow
โ””โ”€โ”€ performance.md                  # Evaluation results

๐Ÿ› ๏ธ Setup Instructions

git clone <your-repo-link>
cd RAG-FirstAid-Chatbot

python -m venv venv
venv\Scripts\activate           # (use source venv/bin/activate for Linux/Mac)

pip install -r requirements.txt

๐Ÿ” Environment Variables (.env)

Create a .env file and add:

GEMINI_API_KEY=your_google_api_key
SERPER_API_KEY=your_serper_api_key

โ–ถ๏ธ Running the Chatbot

# From project root
python -m src.chatbot

Then modify the query variable inside chatbot.py for different test inputs.


๐Ÿงช Run Tests

# Unit test
set PYTHONPATH=.
pytest tests/

# 10 official test cases
python tests/test_queries.py

๐Ÿง  Design Trade-offs

Area Design Decision Trade-off
Triage Gemini API More accurate than keyword matching, but slower
Knowledge Base Excel file + embeddings (local) Simple setup; no DB required
Retrieval Top-3 local + top-3 web Balances trust (local) + freshness (web)
Answer Gen Gemini RAG prompt with strict template Keeps output short & informative
Testing Manual + Pytest + Query evaluation script No UI, but CLI is simple to demo

โœ… Features Recap

  • โœ… Gemini-powered symptom triage
  • โœ… Combined local and web retrieval
  • โœ… Medically aware answers
  • โœ… Unit tests + test queries
  • โœ… Ready for demo and GitHub push

๐Ÿ’ก Future Improvements

  • Add interactive chat UI (e.g., Streamlit or Gradio)
  • Deploy as web app with REST API
  • Add medical named entity recognition (NER)