A specialized clinical AI chatbot application powered by RAG (Retrieval Augmented Generation) technology. This application provides evidence-based medical information to healthcare professionals.
- RAG-Powered Responses: Uses Retrieval Augmented Generation for accurate, context-aware answers
- Clinical Document Processing: Upload and index clinical guidelines, research papers, and medical documents
- Real-time Chat Interface: Professional, responsive chat UI built with Next.js and Material-UI
- Conversation Management: Maintain conversation context across multiple interactions
- Vector Database: Pinecone integration for efficient document retrieval
- Comprehensive Testing: Full test coverage for backend services
- Python 3.10+
- FastAPI: Modern, fast web framework
- LangChain: LLM orchestration and RAG implementation
- Pinecone: Vector database for document embeddings
- OpenAI GPT-4: Large language model for response generation
- PyPDF: PDF document processing
- Next.js 14: React framework with TypeScript
- Material-UI (MUI): Professional UI component library
- Zustand: Lightweight state management
- Axios: HTTP client for API communication
- React Markdown: Markdown rendering for AI responses
- Pinecone: Cloud-based vector database
Clinical-ChatBot/
├── backend/
│ ├── app/
│ │ ├── api/
│ │ │ └── routes/
│ │ │ ├── chat.py # Chat endpoints
│ │ │ ├── documents.py # Document management
│ │ │ └── health.py # Health checks
│ │ ├── models/
│ │ │ └── schemas.py # Pydantic models
│ │ ├── services/
│ │ │ ├── pinecone_service.py # Vector DB operations
│ │ │ ├── document_processor.py # Document processing
│ │ │ └── rag_engine.py # RAG implementation
│ │ ├── config.py # Configuration
│ │ └── main.py # FastAPI app
│ ├── tests/
│ │ ├── test_rag_engine.py
│ │ ├── test_document_processor.py
│ │ └── test_api_chat.py
│ ├── requirements.txt
│ └── .env.example
├── frontend/
│ ├── src/
│ │ ├── components/
│ │ │ ├── ChatContainer.tsx # Main chat UI
│ │ │ ├── ChatMessage.tsx # Message component
│ │ │ ├── ChatInput.tsx # Input component
│ │ │ └── DocumentUpload.tsx # Upload component
│ │ ├── pages/
│ │ │ ├── _app.tsx
│ │ │ ├── _document.tsx
│ │ │ └── index.tsx
│ │ ├── services/
│ │ │ └── api.ts # API client
│ │ ├── store/
│ │ │ └── chatStore.ts # State management
│ │ ├── theme/
│ │ │ └── theme.ts # MUI theme
│ │ └── types/
│ │ └── index.ts # TypeScript types
│ ├── package.json
│ ├── tsconfig.json
│ └── next.config.js
└── README.md
- Python 3.10 or higher
- Node.js 18 or higher
- OpenAI API key
- Pinecone account and API key
-
Navigate to the backend directory:
cd backend -
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Create
.envfile from example:cp .env.example .env
-
Configure environment variables in
.env:OPENAI_API_KEY=your_openai_api_key PINECONE_API_KEY=your_pinecone_api_key PINECONE_ENVIRONMENT=your_pinecone_environment PINECONE_INDEX_NAME=clinical-chatbot SECRET_KEY=your_secret_key
-
Run the backend server:
python -m app.main
The API will be available at
http://localhost:8000
-
Navigate to the frontend directory:
cd frontend -
Install dependencies:
npm install
-
Create
.env.localfile:cp .env.local.example .env.local
-
Configure environment variables in
.env.local:NEXT_PUBLIC_API_URL=http://localhost:8000
-
Run the development server:
npm run dev
The application will be available at
http://localhost:3000
cd backend
pytestRun tests with coverage:
pytest --cov=app --cov-report=htmlcd frontend
npm testOnce the backend is running, visit:
- Swagger UI:
http://localhost:8000/api/docs - ReDoc:
http://localhost:8000/api/redoc
POST /api/chat/message- Send a chat messageGET /api/chat/history/{conversation_id}- Get conversation historyDELETE /api/chat/conversation/{conversation_id}- Clear conversation
POST /api/documents/upload- Upload PDF documentPOST /api/documents/upload-text- Upload text contentGET /api/documents/stats- Get index statistics
GET /api/health- Health checkGET /api/health/ping- Simple connectivity check
- Use the document upload interface in the frontend
- Select a PDF file containing clinical information
- The system will process and index the document
- Documents are chunked and embedded for retrieval
- Type your clinical question in the chat input
- Toggle "Use RAG" to enable/disable document retrieval
- The AI will respond with evidence-based information
- Sources are displayed when RAG is enabled
- Conversations are automatically tracked with unique IDs
- Clear conversations using the trash icon
- Conversation history is maintained for context
Key settings in backend/app/config.py:
CHUNK_SIZE: Size of document chunks (default: 1000)CHUNK_OVERLAP: Overlap between chunks (default: 200)MAX_CONTEXT_LENGTH: Maximum context for RAG (default: 4000)TEMPERATURE: LLM temperature (default: 0.7)
Key settings in frontend/src/theme/theme.ts:
- Theme colors and typography
- Component styling
- Material-UI customization
- Never commit
.envfiles - Use strong secret keys in production
- Implement proper authentication for production deployments
- Validate all user inputs
- Rate limit API endpoints
- Use HTTPS in production
- Set
APP_ENV=productionin.env - Use a production-grade WSGI server (e.g., Gunicorn)
- Set up proper logging
- Configure CORS for your frontend domain
- Build the production bundle:
npm run build
- Start the production server:
npm start
- Or deploy to Vercel, Netlify, etc.
-
Pinecone connection errors
- Verify API key and environment
- Check index name matches configuration
-
OpenAI API errors
- Verify API key is valid
- Check account has sufficient credits
-
Frontend can't connect to backend
- Verify NEXT_PUBLIC_API_URL is correct
- Check CORS settings in backend
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
This project is for educational and research purposes.
This AI assistant provides clinical information for reference only. Always consult qualified healthcare providers for medical decisions. This system is not a substitute for professional medical advice, diagnosis, or treatment.
For issues or questions, please create an issue in the repository.