ZhiFangDanTai: Fine-tuning Graph-based Retrieval-Augmented Generation Model for Traditional Chinese Medicine Formula

ZiXuan Zhang, Bowen Hao, Yingjie Li, Hongzhi Yin

Abstract

Traditional Chinese Medicine (TCM) formula generation requires a deep understanding of complex herb interactions and clinical reasoning. We present ZhiFangDanTai, a framework integrating Graph-based Retrieval-Augmented Generation (GraphRAG) with fine-tuned Large Language Models (LLMs). By leveraging structured knowledge graphs and Direct Preference Optimization (DPO), the model achieves high medical accuracy and explainability, significantly reducing hallucinations compared to standard RAG approaches.

Introduction

Traditional Chinese Medicine (TCM) is a holistic medical system where formulas are meticulously balanced based on specific herb roles—sovereign, minister, assistant, and courier—and nuanced patient indicators like tongue and pulse diagnosis. Existing AI approaches for TCM formula generation often fall into two traps: traditional deep learning models act as "black boxes" focusing only on herb associations, while standard LLMs and Retrieval-Augmented Generation (RAG) systems frequently "hallucinate" incorrect medical advice due to a lack of deep domain knowledge and an inability to synthesize global context from unstructured text.

Methodology

The ZhiFangDanTai framework bridges the gap between structured medical knowledge and generative flexibility through a multi-stage pipeline.

The ZhiFangDanTai workflow integrates GraphRAG with SFT and DPO fine-tuning.

GraphRAG Module

Instead of simple text retrieval, the system constructs a Knowledge Graph (KG) from TCM documents. It utilizes the Leiden community detection algorithm to group related entities into "communities" (e.g., specific diseases or herb categories). The model generates summaries for these communities, allowing it to retrieve both local details and global context during the query process.

Knowledge Graph Construction

The KG maps complex relationships between diseases, symptoms, and ingredients. This structured approach allows the model to move beyond simple herb lists by defining a seven-category taxonomy for TCM information, including contraindications and preparation methods.

A partial view of the constructed TCM knowledge graph showing relationships between formulas and herbs.

Fine-tuning (SFT + DPO)

The model undergoes Supervised Fine-tuning (SFT) on an enhanced instruction dataset. Crucially, it also employs Direct Preference Optimization (DPO) to align outputs with expert-level reasoning. This process effectively "teaches" the model to prefer medically sound formulas over plausible-sounding but incorrect hallucinations.

Datasets and Evaluation

The study utilized approximately 80,000 TCM formulas from the Chinese Formula Database and ancient catalogues, alongside a clinical dataset of 30,400 real-world patient records from Haodf.com.

ZhiFangDanTai significantly outperformed state-of-the-art baselines, including vanilla LLaMA and standard RAG, across both machine translation metrics and TCM-specific indicators. It achieved an average score of 0.8373 across all metrics, compared to 0.6959 for standard RAG. Notably, the model scored high on the Compatibility Compliance Rate (CCR) and Correct Sovereign-minister-assistant-messenger Compatibility Rate (CSCR), indicating strict adherence to traditional medical rules.

Key Insights

  • Community Summarization: By summarizing entire "communities" of knowledge rather than just retrieving text snippets, the model gains a global understanding of disease patterns essential for TCM.
  • DPO as a Guardrail: DPO proved highly effective at suppressing "hallucinated" herbs that might appear plausible to a general LLM but violate TCM principles.
  • Synergy of Retrieval and Tuning: Retrieval provides "open-book" facts, while fine-tuning provides the "internalized" ability to synthesize those facts correctly.

Conclusion and Future Work

ZhiFangDanTai demonstrates that combining GraphRAG with advanced alignment techniques can produce a robust decision-support tool for TCM. While the GraphRAG process adds slight computational latency, the gains in accuracy and explainability are substantial. Future work will explore more complex graph structures and expand the dataset to include diverse regional TCM practices. The authors emphasize that this model is intended for decision support and should not replace professional medical judgment.

Summary updated

Abstract

Traditional Chinese Medicine (TCM) formulas play a significant role in treating epidemics and complex diseases. Existing models for TCM utilize traditional algorithms or deep learning techniques to analyze formula relationships, yet lack comprehensive results, such as complete formula compositions and detailed explanations. Although recent efforts have used TCM instruction datasets to fine-tune Large Language Models (LLMs) for explainable formula generation, existing datasets lack sufficient details, such as the roles of the formula's sovereign, minister, assistant, courier; efficacy; contraindications; tongue and pulse diagnosis-limiting the depth of model outputs. To address these challenges, we propose ZhiFangDanTai, a framework combining Graph-based Retrieval-Augmented Generation (GraphRAG) with LLM fine-tuning. ZhiFangDanTai uses GraphRAG to retrieve and synthesize structured TCM knowledge into concise summaries, while also constructing an enhanced instruction dataset to improve LLMs' ability to integrate retrieved information. Furthermore, we provide novel theoretical proofs demonstrating that integrating GraphRAG with fine-tuning techniques can reduce generalization error and hallucination rates in the TCM formula task. Experimental results on both collected and clinical datasets demonstrate that ZhiFangDanTai achieves significant improvements over state-of-the-art models. Our model is open-sourced at https://huggingface.co/tczzx6/ZhiFangDanTai1.0.
BibTeX
@article{zhang2025zhifangdantai,
  author = {ZiXuan Zhang and Bowen Hao and Yingjie Li and Hongzhi Yin},
  title = {{ZhiFangDanTai: Fine-tuning Graph-based Retrieval-Augmented Generation Model for Traditional Chinese Medicine Formula}},
  journal = {IEEE Journal of Biomedical and Health Informatics},
  year = {2025},
  doi = {10.1109/jbhi.2025.3607819},
}
Figure