A lightweight hybrid AI framework for modeling, testing, and evaluating medical diagnostic logic.
This project implements a Simple Medical Diagnosis Expert System using three complementary approaches:
-
Rule-Based (If–Else) Reasoning Deterministic logic using a predefined knowledge base.
-
Retrieval-Augmented Generation (RAG) Enhances reasoning by retrieving contextual medical knowledge to reduce hallucination and improve accuracy.
-
LLM-Based (API) Inference Uses large-language-model reasoning to deliver adaptive, context-aware medical insights.
Combined, these layers form a hybrid expert system that demonstrates how classical AI and modern generative AI can work together for clinical triage-style decision support.
An expert system uses:
- Knowledge Base: Medical rules and symptom–disease mapping
- Inference Engine: Matches user-reported symptoms with predefined rules
- User Interface: A simple Streamlit UI for interaction
The system provides probable diagnoses such as Flu, Common Cold, Malaria, Typhoid, etc., based on symptom combinations.
Users enter symptoms (e.g., fever, cough, sore throat).
Symptoms are stored as facts in memory.
The engine compares facts with the rule base.
Matching rules trigger one or more possible medical conditions.
| Layer | Role | Handles |
|---|---|---|
| If–Else Rules (Python If-Else or Prolog) | Explicit logic | Known symptom patterns, emergencies |
| RAG Retrieval | Semantic matching | Variants of symptoms, contextual knowledge |
| LLM API | Adaptive reasoning | Combining logic + retrieved data |
| Symptom | Possible Diseases | Severity | Recommended Tests | Advice | Emergency |
|---|---|---|---|---|---|
| Fever | Viral Infection, Malaria, Typhoid | Moderate | CBC, Malaria Test | Hydration, paracetamol, rest | No |
| Chest Pain | Heart Attack, Acid Reflux, Anxiety | Severe | ECG, Troponin | Seek emergency care if persistent | Yes |
| Cough | Cold, Bronchitis, COVID-19 | Mild | CXR, COVID test | Steam inhalation, syrup | No |
| Shortness of Breath | Asthma, Pneumonia, Heart Failure | Severe | X-Ray, Oxygen saturation | Immediate medical care | Yes |
| … | … | … | … | … | … |
- Rule Base: Hard-coded medical rules
- Inference Engine: Pattern matching based on symptoms
- RAG Pipeline: Fetches semantically relevant medical context
- LLM API: Generates summarized reasoning
- UI: Streamlit-based interactive interface
if fever and cough and sore_throat:
diagnosis = "Flu"
elif fever and chills and sweating:
diagnosis = "Malaria"
else:
diagnosis = "No rule-based match found"- ✔ Rule-based medical diagnosis
- ✔ RAG-enhanced symptom interpretation
- ✔ LLM-driven clinical reasoning
- ✔ Emergency detection flags
- ✔ Recommended tests + treatment guidance
- ✔ Modular design for integration with telemedicine tools
- ✔ Easy to extend / plug in new medical rules
- Educational tools for learning AI reasoning
- Basic medical triage systems
- Hybrid medical-AI prototypes
- Telemedicine support platforms
- Context-aware symptom analysis with live API access
The system provides:
- Possible diseases
- Severity level
- Recommended tests
- Treatment suggestions
- Emergency status
- RAG-supported context
- LLM summary reasoning
- Python
- Streamlit (Frontend)
- FAISS / Chroma (Optional RAG Vector Store)
- Transformers / Embeddings
- LLM API (OpenAI / Gemini / Local LLM)
# Clone the repo
git clone https://github.com/saad2134/expert-system-medical-diagnosis
# Navigate to project
cd expert-system-medical-diagnosis
# Install dependencies
pip install -r requirements.txt
# Run the Streamlit app
streamlit run src/streamlit_app.py⭐ Star this repo if you found it helpful! Thanks for reading.
#ExpertSystem #MedicalDiagnosis #RuleBasedAI #RAG #RetrievalAugmentedGeneration #HybridAI #LLMInference #AIinHealthcare #HealthTech #DiagnosticAI #MedicalTriage #InferenceEngine #KnowledgeBase #StreamlitApp #AIDecisionSupport #SymptomChecker #ClinicalDecisionSupport #AIHealthcareTools #MachineReasoning #expert-system-medical-diagnosis NeuralTech