Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cover Image

🩺 Medical Assistant Chatbot

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.

Overview

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

Project Stack

Core Technologies

  • 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

Data Ingestion & Processing

  • PDFPlumber: PDF text extraction and processing
  • NumPy: Numerical computing and array operations
  • PyYAML: YAML configuration file parsing

Vector Operations & Search

  • FAISS-CPU: CPU-optimized vector indexing and similarity search
  • OpenAI Embeddings: Text embedding generation for semantic search (text-embedding-3-small)

Architecture

  • 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

Project Structure

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

Features

  • 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

Setup Instructions

Prerequisites

  • Python 3.8 or higher
  • OpenAI API key
  • Git (for cloning the repository)

Installation

  1. Clone the repository

    git clone <repository-url>
    cd medical_chatbot
  2. Create a virtual environment

    python -m venv venv
    
    # On Windows
    venv\Scripts\activate
    
    # On macOS/Linux
    source venv/bin/activate
  3. Install dependencies

    pip install -r requirements.txt
  4. Configure API keys

    Create or update secrets.ini:

    [API KEYS]
    OPENAI_API_KEY = your_openai_api_key_here
  5. Verify configuration

    Ensure config.ini points 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

🏃‍♂️ How to Run

Starting the Application

  1. Activate your virtual environment (if not already active)

    # On Windows
    venv\Scripts\activate
    
    # On macOS/Linux
    source venv/bin/activate
  2. Run the Streamlit application

    streamlit run app.py
  3. Access the application

    Open your web browser and navigate to the URL displayed in the terminal (typically http://localhost:8501)

Using the Chatbot

  1. Select a Patient: Use the sidebar to choose a patient from the dropdown menu
  2. Ask Questions: Type your medical questions in the chat input
  3. Get Responses: The chatbot will provide context-aware responses using patient data and medical knowledge

Configuration

Configuration Files

  • config.ini: Paths to data files and system prompts
  • secrets.ini: API keys and sensitive configuration
  • system_prompts/: YAML files containing LLM system prompts

Customization

  • Add New Patients: Update data/patients.jsonl with new patient data
  • Change Medical Knowledge: Replace data/ehab368.pdf with your medical documents
  • Modify Prompts: Edit YAML files in system_prompts/ to customize LLM behavior
  • Adjust Search Parameters: Modify top_k and other parameters in lib/chatbot.py

About

RAG-based Medical Assistant Chatbot using FAISS, deployed using Streamlit.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages