A medical assistant chatbot that helps answer medical questions by finding relevant information from patient records and medical documents. The system looks up patient data and searches through PDF files to provide helpful, accurate medical guidance.
This medical chatbot, named Kylle, is designed to assist healthcare professionals by:
- Patient Data Integration: Loads and summarizes patient information from structured data
- Medical Knowledge Retrieval: Uses semantic search to find relevant information from medical documents
- Intelligent Responses: Combines patient context with medical knowledge to provide accurate answers
- Interactive Interface: Web-based chat interface built with Streamlit for easy interaction
- Python 3.13+: Primary programming language
- Streamlit: Web application framework for the chat interface
- OpenAI gpt-4o-mini: Large language model for natural language processing
- FAISS: Vector similarity search for document retrieval
- PDFPlumber: PDF text extraction and processing
- NumPy: Numerical computing and array operations
- PyYAML: YAML configuration file parsing
- FAISS-CPU: CPU-optimized vector indexing and similarity search
- OpenAI Embeddings: Text embedding generation for semantic search (text-embedding-3-small)
- RAG (Retrieval-Augmented Generation): Core AI architecture combining retrieval and generation
- Modular Design: Clean separation of concerns with dedicated modules, production-ready code
- Caching System: Streamlit caching for simple performance optimization
medical_chatbot/
├── app.py # Main Streamlit application
├── config.ini # Configuration file for paths and settings
├── secrets.ini # API keys and sensitive configuration
├── requirements.txt # Python dependencies
├── README.md # This file
├── lib/ # Core library modules
│ ├── chatbot.py # RAG chat session implementation
│ ├── chunking.py # PDF text chunking utilities
│ ├── embedding.py # Embedding generation pipeline
│ ├── retrieval.py # Semantic search functionality
│ ├── data_loader.py # Patient data loading and summarization
│ ├── orchestrator.py # Chat orchestration logic
│ ├── utils.py # Utility functions
│ └── connector.py # LLM connection utilities
├── system_prompts/ # LLM system prompts
│ ├── orchestrator.yaml # Main chat orchestrator prompt
│ └── patient_data_summarizer.yaml # Patient data summarization prompt
├── data/ # Data files
│ ├── patients.jsonl # (PROVIDED) Patient data in JSONL format
│ ├── ehab368.pdf # Medical knowledge base PDF
│ └── synthetic_patient_data.ipynb # (PROVIDED) Patient data notebook
├── db/ # Database and index files
│ ├── ehab368_chunks.jsonl # Chunked PDF content
│ ├── ehab368_faiss.index # FAISS vector index
│ └── ehab368_faiss_metadata.json # Index metadata
└── eda/ # Exploratory data analysis
├── config.ini # EDA configuration
├── patient_data_eda.ipynb # Patient data analysis
├── rag_pipeline.ipynb # RAG pipeline testing
└── rag.ipynb # RAG experimentation
- Smart AI Responses: Uses patient info and medical knowledge together
- Patient Memory: Remembers patient details and keeps track of their info (turned off by default for improved latency)
- Easy Web Chat: Simple chat interface you can use in your browser
- Fast Performance: Works quickly with the help of simple caching
- Clean Code: Well-organized code that's easy to understand and change
- Python 3.8 or higher
- OpenAI API key
- Git (for cloning the repository)
-
Clone the repository
git clone <repository-url> cd medical_chatbot
-
Create a virtual environment
python -m venv venv # On Windows venv\Scripts\activate # On macOS/Linux source venv/bin/activate
-
Install dependencies
pip install -r requirements.txt
-
Configure API keys
Create or update
secrets.ini:[API KEYS] OPENAI_API_KEY = your_openai_api_key_here
-
Verify configuration
Ensure
config.inipoints to the correct file paths:[PATHS] PDF_PATH = data/ehab368.pdf CHUNKS_PATH = db/ehab368_chunks.jsonl INDEX_PATH = db/ehab368_faiss.index METADATA_PATH = db/ehab368_faiss_metadata.json SUMMARIZER_SYS_PROMPT_PATH = system_prompts/patient_data_summarizer.yaml source_name = ehab368.pdf
-
Activate your virtual environment (if not already active)
# On Windows venv\Scripts\activate # On macOS/Linux source venv/bin/activate
-
Run the Streamlit application
streamlit run app.py
-
Access the application
Open your web browser and navigate to the URL displayed in the terminal (typically
http://localhost:8501)
- Select a Patient: Use the sidebar to choose a patient from the dropdown menu
- Ask Questions: Type your medical questions in the chat input
- Get Responses: The chatbot will provide context-aware responses using patient data and medical knowledge
config.ini: Paths to data files and system promptssecrets.ini: API keys and sensitive configurationsystem_prompts/: YAML files containing LLM system prompts
- Add New Patients: Update
data/patients.jsonlwith new patient data - Change Medical Knowledge: Replace
data/ehab368.pdfwith your medical documents - Modify Prompts: Edit YAML files in
system_prompts/to customize LLM behavior - Adjust Search Parameters: Modify
top_kand other parameters inlib/chatbot.py
