# 🧬 PharmaSpine AI
**Medical-Grade Intelligence & Clinical Governance Gateway**
---
## 🌟 Product Overview
**PharmaSpine AI** is a next-generation, enterprise-grade Medical Artificial Intelligence platform designed exclusively for the pharmaceutical and healthcare industry. Built on a **Zero-Trust Clinical Governance Architecture**, PharmaSpine AI ensures that every piece of medical information generated is clinically accurate, fully cited, and strictly governed by FDA guidelines.
Whether communicating complex clinical data to healthcare professionals or offering simple, empathetic guidance to patients, PharmaSpine AI bridges the gap between massive medical databases and real-time human interaction with zero compromise on safety.
### 🧩 System Architecture Flow
```mermaid
graph TD
%% Define Styles
classDef user fill:#3b82f6,stroke:#1d4ed8,stroke-width:2px,color:white;
classDef frontend fill:#10b981,stroke:#047857,stroke-width:2px,color:white;
classDef gateway fill:#8b5cf6,stroke:#5b21b6,stroke-width:2px,color:white;
classDef ai fill:#f59e0b,stroke:#b45309,stroke-width:2px,color:white;
classDef db fill:#ef4444,stroke:#b91c1c,stroke-width:2px,color:white;
classDef check fill:#f43f5e,stroke:#be123c,stroke-width:2px,color:white;
%% Nodes
User((User)):::user
UI[React/Vite Frontend]:::frontend
subgraph "🛡️ Governance Gateway (FastAPI)"
Cache[Semantic Cache]:::gateway
Precheck[Intent & Audience Pre-check]:::check
AE[Adverse Event Detection]:::check
SelfRAG[Self-RAG Refinement]:::ai
Orchestrator{Orchestrator}:::gateway
CRAG[CRAG Evaluator - Llama 3 8B / Phi 3.5]:::ai
Synth[Answer Synthesizer - Llama 3.3]:::ai
Postcheck[Output Guardrails & Citations]:::check
end
subgraph "🗄️ Multi-Database Network"
Qdrant[(Qdrant Vector DB
MedCPT)]:::db
Neo4j[(Neo4j Graph DB)]:::db
Postgres[(PostgreSQL
Audit & History)]:::db
end
%% Flow
User -->|Query| UI
UI -->|POST /gateway/answer| Cache
Cache -->|Cache Miss| Precheck
Precheck -->|Allowed| AE
AE --> Orchestrator
Orchestrator -->|Parallel Search| SelfRAG
Orchestrator -->|Hybrid Query| Qdrant
Orchestrator -->|Hybrid Query| Neo4j
Qdrant -->|Vectors & SPLADE| CRAG
Neo4j -->|Graph Relationships| CRAG
CRAG -->|Low Confidence| SelfRAG
CRAG -->|High Confidence| Synth
Synth -->|Draft Answer| Postcheck
Postcheck -->|Final Validation| Postgres
Postgres --> UI
UI --> User
```
---
## 🚀 Core Capabilities
### 1. 🛡️ Zero-Trust Clinical Governance Gateway
At the heart of PharmaSpine AI is the **Governance Gateway**—a rigorous security layer that intercepts, evaluates, and filters all AI traffic.
- **Pharmacovigilance (Adverse Event) Detection:** Instantly flags severe symptoms (e.g., severe rash, breathing difficulty). It runs in an asynchronous parallel thread (ThreadPoolExecutor) to ensure zero latency, and securely triggers an automated SMTP email to safety teams.
- **Strict Off-Label Policy Enforcement:** Automatically blocks AI from recommending dosages or lines of therapy without an official FDA label citation.
- **Output Guardrails:** Prevents toxic, out-of-domain, or dangerous medical advice from ever reaching the end user.
### 2. 🧠 Multi-Engine Hybrid Retrieval Architecture
PharmaSpine AI doesn't rely on a single database; it utilizes a highly optimized **Multi-Database Retrieval Network** to fetch facts with mathematical precision.
- **Qdrant Vector DB (MedCPT):** Uses specialized medical vector embeddings for deep semantic search.
- **SPLADE Lexical Engine:** Captures exact keyword and medical term matches.
- **Neo4j Graph Database:** Maps complex relationships between drugs, diseases, and side effects.
- **Corrective RAG (CRAG):** Employs Self-Reflective loops (using Llama 3 8B via Groq) to double-check and refine answers before generation, strictly configured to prevent hallucinated data combinations.
### 3. 👥 Dynamic Persona Modes (Context-Aware UI)
The system dynamically adapts its intelligence based on the target audience.
- **Healthcare Professional Mode:** Delivers highly technical, clinical, and jargon-rich answers tailored for researchers and HCPs. Chat histories are strictly siloed to professional queries.
- **Patient Mode:** Translates complex medical literature into simple, compassionate language, automatically appending necessary medical disclaimers. Chat histories dynamically update to isolate patient-facing queries.
### 4. ⚡ Ultra-Low Latency & High Performance
- **Groq LPU Acceleration:** Powered by `Llama-3.3-70b-versatile` via Groq Cloud for near-instantaneous primary synthesis.
- **Real-Time Routing:** Evaluates intents and grades retrieval confidence in milliseconds using optimized cloud and local LLMs.
- **Semantic Caching:** Delivers zero-latency responses for frequently asked questions via an in-memory LRU cache.
### 5. 🔍 Transparent Audit & Compliance
- **Database-Backed History:** Every user interaction, retrieval score, and AI decision is permanently logged in an immutable **PostgreSQL** database.
- **Clickable Citations:** Users can inspect the exact Governance JSON Data and raw evidence chunks that the AI used to formulate its answer directly in the UI.
---
## 🏗️ Technical Stack
* **Frontend:** React, Vite, TypeScript (Featuring auto-scrolling, dynamic metadata panels, real-time typing effects, and Role-Based History Filtering).
* **Backend:** FastAPI (Python), PostgreSQL (Alembic Migrations), Uvicorn.
* **AI Models:** Llama-3.3-70b (Synthesis), Llama-3-8B (Cloud Routing/Grading), Phi-3.5 (Local Fallback Routing), MedCPT (Dense Embeddings), SPLADE (Sparse Embeddings).
* **Databases:** Qdrant (Vector), Neo4j (Graph), PostgreSQL (Relational/Audit).
---
## 🎯 Target Use Cases
1. **Medical Affairs Teams:** Instantly querying massive repositories of clinical trial data and FDA labels.
2. **Healthcare Providers (HCPs):** Quick point-of-care reference for drug indications, mechanisms of action, and interactions.
3. **Patient Support Programs:** Providing safe, governed, and easy-to-understand drug information directly to patients without crossing into diagnostic territory.
---
*PharmaSpine AI: Where State-of-the-Art AI meets Uncompromising Medical Integrity.*