Skip to content

Self-Compassion AIβ„’ for Neurodiverse Brains 🧠 is an LLM RAG platform that delivers personalized guidance and support for self-compassion based on high-quality empirical research and science.

License

Notifications You must be signed in to change notification settings

wangjenn/selfcompassion-llm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

88 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Self-Compassion AIβ„’ LLM for Neurodiverse Brains β₯ 🧠

labubu-selfcompassion

✨ Introduction

  • Research shows that individuals with neurodiverse conditions (e.g., ADHD, autism) often struggle with self-compassion (Beaton et al., 2002). Everyday reminders to be kind to oneself can be cognitively demanding and difficult to sustain, especially during stressful situations or when executive function is taxed. This project addresses that gap by offering a lightweight and accessible tool to make self-compassion easier and less effortful. Drawing from leading evidence-based research, this app provides a structured and easy way to practice kindness toward oneself β₯.


πŸ’• Live Demo

  • Try out the deployed app (no setup required!) πŸ‘‰πŸ» Live Demo
videowalkthrough.webm

πŸ’‘ Features

  • Science-based: built using leading empirical research and science on neurodiversity and self-compassion.

  • Interactive Web Interface: easy-to-use Streamlit app with fast, instant responses (press 'Enter' or click 'Answer').

    ScreenFloat Shot of Google Chrome on 2025-08-21 at 14-32-31

  • Smart Search Options: choose between hybrid, BM25, or vector retrieval to find the most relevant guidance.

    ScreenFloat Shot of Streamlit on 2025-08-21 at 14-47-55

  • Personalized Experience (LLM Evaluation): select from 3 prompt styles based on your moods and needs-- πŸ’• Supportive, πŸ“š Direct, or πŸ’ͺ🏻 Action-Oriented!

    ScreenFloat Shot of Streamlit on 2025-08-21 at 14-47-04

Prompt Style Purpose Example Response Tone
πŸ’• Supportive Compassionate, reflective guidance "It's completely understandable that you're feeling this way..."
πŸ“š Direct Concise, factual information "Here are three evidence-based strategies for..."
πŸ’ͺ🏻 Action-Oriented Practical steps and exercises "Try this 5-minute exercise: First, notice..."


  • Advanced Customization: adjust search depth (top-k results), LLM creativity (temperature), and choose between GPT models (gpt-4o-mini or gpt-3.5-turbo).

ScreenFloat Shot of Streamlit on 2025-08-21 at 14-55-10


  • Enhanced Retrieval: optional query expansion and document re-ranking for better, more relevant results.

ScreenFloat Shot of Streamlit on 2025-08-21 at 14-57-17


  • Built-in Analytics: Real-time feedback collection and monitoring dashboards to track usage and effectiveness.

ScreenFloat Shot of Streamlit on 2025-08-21 at 15-00-21




πŸ› οΈ Environment & Configuration

  • Python version: Python 3.11+ recommended
  • Environment variables:
    • OPENAI_API_KEY (required for LLM features; set in a .env file or your environment).


πŸš€ Quickstart (clone and run locally)

  • Clone the repo and install dependencies:

    git clone https://github.com/<your-username>/selfcompassion-llm.git
    cd selfcompassion-llm
    pip install -r requirements.txt
  • Run ingestion to build the index:

    python ingestion.py
  • Launch the Streamlit app:

    streamlit run streamlit_app.py

πŸ›₯ Alternative: Docker Setup

  • Set up API key. Create a .env file in project root:
    OPENAI_API_KEY=your_actual_api_key_here
  • Run docker:
    docker-compose up -- build
  • Access at http://localhost:8503


πŸ“‚ Project Structure

selfcompassion-llm/
β”œβ”€β”€ streamlit_app.py        # main Streamlit app
β”œβ”€β”€ ingestion.py            # build FAISS/embedding index
β”œβ”€β”€ monitor.py              # simple monitoring dashboard
β”œβ”€β”€ docker-compose.yml      # docker setup
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ Makefile                # developer shortcuts 
β”œβ”€β”€ processed_documents_clean.json  # demo dataset
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ images                  # images folder
└── notebooks/              # exploration notebook with example code

🏠 System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        USER INTERFACE                               β”‚
β”‚                     Streamlit Web App                               β”‚
β”‚                                                                     β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                  β”‚
β”‚  β”‚   Query     β”‚  β”‚   Settings  β”‚  β”‚  Feedback   β”‚                  β”‚
β”‚  β”‚   Input     β”‚  β”‚   Panel     β”‚  β”‚   Radio     β”‚                  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                                β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      QUERY PROCESSING                               β”‚
β”‚                                                                     β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                            β”‚
β”‚  β”‚   Query     │────────▢│  Original   β”‚                            β”‚
β”‚  β”‚ Rewriting   β”‚         β”‚   Query     β”‚                            β”‚ 
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                                β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    RETRIEVAL LAYER                                  β”‚
β”‚                                                                     β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                  β”‚
β”‚  β”‚    BM25     β”‚  β”‚   Vector    β”‚  β”‚   Hybrid    β”‚                  β”‚
β”‚  β”‚   Search    β”‚  β”‚   Search    β”‚  β”‚   Search    β”‚                  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                  β”‚
β”‚                               β”‚                                     β”‚
β”‚                               β–Ό                                     β”‚
β”‚                   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                               β”‚
β”‚                   β”‚   Document      β”‚                               β”‚
β”‚                   β”‚  Re-ranking     β”‚                               β”‚
β”‚                   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                                β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   KNOWLEDGE BASE                                    β”‚
β”‚                                                                     β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                  β”‚
β”‚  β”‚ Documents   β”‚  β”‚ Embeddings  β”‚  β”‚ BM25 Index  β”‚                  β”‚
β”‚  β”‚    JSON     β”‚  β”‚    .npy     β”‚  β”‚   Memory    β”‚                  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                                β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    LLM GENERATION                                   β”‚
β”‚                                                                     β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                            β”‚
β”‚  β”‚   OpenAI    │◀────────│   Prompt    β”‚                            β”‚
β”‚  β”‚  gpt-4o-miniβ”‚         β”‚ Engineering β”‚                            β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                            β”‚
β”‚                               β”‚                                     β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”              β”‚                                     β”‚
β”‚  β”‚   3 Prompt  β”‚β—€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                     β”‚
β”‚  β”‚   Styles    β”‚                                                    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                                    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                                β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   MONITORING & LOGGING                              β”‚
β”‚                                                                     β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                  β”‚
β”‚  β”‚  Event Log  β”‚  β”‚ Feedback    β”‚  β”‚ Dashboard   β”‚                  β”‚
β”‚  β”‚   JSONL     β”‚  β”‚ Collection  β”‚  β”‚  Charts     β”‚                  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”„ Data Flow

  1. User Input β†’ Query entered in Streamlit interface
  2. Query Processing β†’ Optional rewriting with domain terms
  3. Retrieval β†’ Multiple search methods (BM25/Vector/Hybrid)
  4. Re-ranking β†’ Document relevance scoring
  5. Context Building β†’ Top documents formatted for LLM
  6. Generation β†’ OpenAI API with custom prompts
  7. Response β†’ Answer + sources displayed to user
  8. Monitoring β†’ Events logged for analytics


πŸ“Š Monitoring

  • Run it with:
    streamlit run monitor.py
  • A separate monitoring page (monitor.py) tracks:
    • Sources per answer
    • Feedback breakdown
    • Query rewriting usage

ScreenFloat Shot of Streamlit on 2025-08-21 at 15-05-29



βœ… Evaluation Results

🚘 Running Evaluation

python evaluation.py
  • App is deployed and running here.
  • The Self-Compassion RAG system was evaluated on a golden dataset of 20 queries with labeled relevant documents. It tests the RAG system against the golden dataset.

πŸ’ͺ🏻 Performance Metrics

Retrieval Method Hit Rate MRR Precision@10 Recall@10
BM25 1.000 0.598 0.100 1.000
Vector 0.900 0.410 0.090 0.900
TF-IDF 0.900 0.410 0.090 0.900
Hybrid 0.950 0.520 0.095 0.950

🎯 LLM Evaluation Summary

Multiple prompt styles tested and compared:

  • πŸ’• Supportive, πŸ“š Direct, πŸ’ͺ🏻 Action-Oriented prompts
  • Each optimized for different query types
  • User feedback collected to assess effectiveness

Multiple models evaluated:

  • gpt-4o-mini (primary) vs gpt-3.5-turbo
  • Performance tested across all retrieval methods

πŸ’‘ Key Findings

  • BM25 consistently achieves perfect hit rate and recall in this dataset, with the best MRR (0.598), ranking relevant documents higher.
  • Hybrid slightly improves over pure TF-IDF and Vector, balancing precision and recall.
  • Vector and TF-IDF show similar performance, with lower MRR than BM25 but decent recall.
  • BM25 emerges as the most reliable retriever under current conditions, though Hybrid provides a good balance.

⚑ Data & Reproducibility

  • Deterministic ingestion pipeline (ingestion.py)

  • requirements.txt provided for environment setup

  • Docker + docker-compose included for containerized runs

  • Repo includes a small demo dataset (processed_documents_clean.json) to immediately run the app and test its functionality.

  • To rebuild the larger embedding index files locally, run:

    make ingest

    or

    python ingestion.py

πŸ“˜ Development Notes

  • Exploration notebooks are under /notebooks/.
  • Embeddings (embeddings.npy, id_index.json) are ignored from git.
  • Feedback data is stored locally (not shared).

πŸ“„ Data Sources

  • All data sources are carefully curated from peer-reviewed research, legally purchased books (excerpts only, fair use), and publicly available expert materials (e.g., podcast transcripts).
  • Full PDF sources are maintained in a separate private repository for copyright compliance.

πŸ“ Disclaimer

  • All responses are anonymous β€” nothing is saved, logged, or tracked by the app.
  • This app does not store, share, or distribute full PDFs or copyrighted materials. All content is based on short excerpts, summaries, or personal notes, either from books I’ve legally purchased or from publily available sources (e.g., peer-reviewed articles, podcast transcripts).
  • This app is intended for educational and personal use only. It is not intended to diagnose, treat, cure, or prevent any mental health condition. If you are in emotional distress or experiencing a crisis, please contact a licensed mental health professional.

β₯ Thank you so much for using the app-- I hope you find it useful! May we all be kind to ourselves! πŸ’•πŸ™πŸ»

selfcompassion

About

Self-Compassion AIβ„’ for Neurodiverse Brains 🧠 is an LLM RAG platform that delivers personalized guidance and support for self-compassion based on high-quality empirical research and science.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published