An AI-powered medical research assistant that lets you upload PDF papers and ask questions about them using Retrieval-Augmented Generation (RAG). Built with Next.js, FastAPI, ChromaDB, and Google Gemini.
- PDF Upload & Indexing — drag-and-drop PDFs and index them into a vector database in seconds
- RAG-powered Q&A — ask natural language questions and get answers grounded in the uploaded papers
- Source Attribution — every answer shows exactly which passages it drew from
- Confidence Scoring — guardrail system rates how well each answer is supported by the sources
- Google OAuth — secure sign-in via Google, powered by NextAuth.js (free, no billing required)
- Markdown Rendering — AI answers render with bold, lists, and headers for readability
- Dark Sidebar Layout — modern indigo/slate UI with navigation, user avatar, and sign-out
| Tech | Purpose |
|---|---|
| Next.js 16 (App Router) | React framework |
| TypeScript | Type safety |
| Tailwind CSS v4 | Styling |
| NextAuth.js (Auth.js v5) | Google OAuth |
| Axios | API calls |
| Lucide React | Icons |
| Tech | Purpose |
|---|---|
| FastAPI | REST API |
| ChromaDB | Vector store |
| Google Gemini AI | LLM + embeddings |
| LangChain | PDF chunking & RAG pipeline |
| Python-dotenv | Environment config |
ClinicaQuery-AI/
├── backend/
│ ├── core/
│ │ ├── ingestion.py # PDF chunking + embedding
│ │ ├── generator.py # Gemini answer generation
│ │ └── guardrails.py # Confidence scoring
│ ├── routes/
│ │ ├── upload.py # POST /api/upload
│ │ └── query.py # POST /api/query
│ ├── vectorstore/
│ │ └── chroma_store.py # ChromaDB wrapper
│ └── main.py # FastAPI app entry point
│
└── frontend/
├── app/
│ ├── api/auth/[...nextauth]/
│ │ └── route.ts # NextAuth handler
│ ├── components/
│ │ ├── AppShell.tsx # Auth guard + sidebar layout
│ │ ├── Sidebar.tsx # Dark navigation sidebar
│ │ ├── ChatWindow.tsx# Main chat interface
│ │ ├── SourceCard.tsx# Collapsible source snippets
│ │ └── ConfidenceBadge.tsx
│ ├── login/
│ │ └── page.tsx # Google sign-in page
│ ├── upload/
│ │ └── page.tsx # Drag-and-drop PDF upload
│ └── layout.tsx
├── auth.ts # NextAuth config
└── proxy.ts # Route protection
- Node.js 18+
- Python 3.10+
- A Google Cloud project (free tier) — for OAuth
- A Google Gemini API key — get one free
git clone https://github.com/Sowaiba-01/ClinicaQuery-AI.git
cd ClinicaQuery-AIcd backend
python -m venv .venv
.venv\Scripts\activate # Windows
# source .venv/bin/activate # macOS/Linux
pip install -r requirements.txtCreate backend/.env:
GEMINI_API_KEY=your-gemini-api-key-hereStart the backend:
uvicorn main:app --reload --port 8000Backend runs at http://localhost:8000
cd frontend
npm installCreate frontend/.env.local (copy from .env.local.example):
AUTH_SECRET=your-random-secret # openssl rand -base64 32
AUTH_GOOGLE_ID=your-client-id.apps.googleusercontent.com
AUTH_GOOGLE_SECRET=your-client-secret
AUTH_URL=http://localhost:3000- Go to console.cloud.google.com and create a project
- APIs & Services → OAuth consent screen → External → fill in app name & email → Save
- APIs & Services → Credentials → Create Credentials → OAuth 2.0 Client ID
- Application type: Web application
- Authorised redirect URI:
http://localhost:3000/api/auth/callback/google
- Copy the Client ID and Client Secret into
.env.local - OAuth consent screen → Test users → Add users → add your Gmail
Start the frontend:
npm run devFrontend runs at http://localhost:3000
Navigate to http://localhost:3000 you'll be redirected to the Google sign-in page. After signing in you'll see the full app with the sidebar.
- Sign in with Google
- Click Upload PDF in the sidebar
- Drag and drop a medical paper (PDF, max 50 MB)
- Wait for indexing to complete (progress bar shows status)
- Go to Chat and ask questions about the paper
- Each answer shows:
- The response with markdown formatting
- A confidence score (high / medium / low)
- Collapsible source snippets with relevance scores
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/upload |
Upload and index a PDF |
POST |
/api/query |
Ask a question about indexed papers |
GET |
/ |
Health check |
curl -X POST http://localhost:8000/api/query \
-H "Content-Type: application/json" \
-d '{"question": "What are the side effects of metformin?"}'{
"answer": "According to the uploaded paper, metformin commonly causes...",
"sources": [
{
"text_snippet": "Gastrointestinal side effects including nausea...",
"source_file": "clinical_trial_2024.pdf",
"relevance_score": 0.91
}
],
"guardrails": {
"confidence_score": 87,
"is_supported": true,
"warning": null
}
}| Variable | Description |
|---|---|
GEMINI_API_KEY |
Google Gemini API key |
| Variable | Description |
|---|---|
AUTH_SECRET |
Random secret for NextAuth session encryption |
AUTH_GOOGLE_ID |
Google OAuth Client ID |
AUTH_GOOGLE_SECRET |
Google OAuth Client Secret |
AUTH_URL |
App URL (http://localhost:3000 for dev) |
This tool is intended for research purposes only. It is not a substitute for professional medical advice, diagnosis, or treatment. Always consult a licensed physician.
License: MIT