Mental Health Chatbot — RAG over PubMed

The project sits at the intersection of AI, psychology, and neuroscience. The chatbot links neurotransmitters (dopamine, serotonin, GABA, glutamate, norepinephrine, acetylcholine, endorphins) to mood disorders (depression, anxiety, bipolar, schizophrenia, OCD, PTSD), and surfaces how nutrition, exercise, and lifestyle affect well-being. Architecture flowchart LR subgraph DATA["Data Acquisition"] P["PubMed viaNCBI Entrez"] -->|"MeSH queries:6 disorders × 7 NTs"| J["1,500+ abstracts(JSON on disk)"] end subgraph IDX["Indexing"] J --> D["LlamaIndexDocuments"] D -->|"SentenceSplitter512 tok / 50 overlap"| C["Chunks"] C --> E["BioBERTembeddings"] E --> F["FAISSIndexFlatL2"] end subgraph CHAT["Chat Engine"] Q["User question"] --> CE["CondenseQuestionChatEngine"] MB["ChatMemoryBuffer600 tokens"] -.-> CE CE -->|"condensed query"| F F -->|"top-k = 3 chunks"| LLM["Phi-2 Orange Q4_K_Mvia llama.cpp"] LLM --> ANS["Answer"] end subgraph EVAL["Evaluation"] BA["BioASQ-13b100 questions"] --> R["RAGAS+ BertScore"] ANS --> R R --> M["Correctness: 0.60BertScore: 0.67"] end Data acquisition — 1,500+ PubMed abstracts scraped via Biopython Entrez. MeSH queries built from a Cartesian product of 6 disorders (depression, anxiety, bipolar, schizophrenia, OCD, PTSD) × 7 neurotransmitters (dopamine, serotonin, GABA, glutamate, norepinephrine, acetylcholine, endorphins), persisted as JSON. Indexing — BioBERT embeddings (biomedical NLI/STS fine-tune) feeding a FAISS IndexFlatL2 vector store; SentenceSplitter with 512-token chunks and 50-token overlap. Retrieval + generation — LlamaIndex CondenseQuestionChatEngine with a ChatMemoryBuffer for multi-turn follow-ups; local quantized GGUF LLM (Phi-2 Orange Q4_K_M) via llama.cpp. No paid APIs at inference time. Evaluation — RAGAS AnswerCorrectness against the first 100 BioASQ-13b training questions and their cited PMIDs, with the same local Phi-2 model wrapped as the judge. Key design decisions Local quantized model for reproducibility and zero API cost. The small context window directly shaped top-k, chunk size, and memory-buffer choices. BioBERT over generic sentence-transformer — domain match beat model size for jargon-dense PubMed text. FAISS IndexFlatL2 (exact search) at sub-1k vectors removes recall variance as a confound when tuning the rest of the pipeline. BioASQ for evaluation — peer-reviewed biomedical QA benchmark with curated answers, a stronger signal than self-generated ground truth. Results Final evaluation on the BioASQ-13b subset: ...

May 17, 2025