尚未偵測到更新。GitHub 發布版本後會顯示在這裡。
個人 GitHub 帳號下公開儲存庫的擁有者可以登入並驗證所有權,自行管理介紹,無需管理員核准。
登入並產生驗證檔案,在 30 分鐘內將其提交至此儲存庫的預設分支。其他分支或分叉儲存庫中的檔案無效。然後在下方檢查檔案,即可無需管理員核准直接管理專案。請保留檔案以維持管理權限。
如需登入,將前往登入頁面。登入後請回到此處,再次點擊所選的驗證按鈕。
在專案資料夾中執行 /nomorevibe verify,即可驗證所有權並自行管理介紹。
一分鐘完成驗證Evidence-synthesis RAG assistant for TCM practitioners — hybrid vector + knowledge graph retrieval over 17 classical texts, with query classification, self-critique verification, and blind A/B arena evaluation.
翻譯準備中
取自儲存庫 README
正在載入完整 README。
檢視完整 README ↗The public site is tcm-sage-sandy.vercel.app. It starts with six clearly labelled prerecorded examples, original excerpts and saved SymMap relationships. These examples work without a model or backend request. English is the default; Chinese is available.
Optional live research requires a project access code. It uses the full12,204-chunk BGE-M3 index, SiliconFlow's fixed free BGE embedding/reranking models and OpenRouter's fixed free Nemotron model. Provider availability is not guaranteed. Historical prescriptions and graph labels are research material, not medical advice or evidence of clinical benefit. Public Arena submissions and raw statistics are disabled; the original presentation entrypoint remains available locally.
Vercel Hobby serves web/; Render Free serves src/release_api.py at tcm-sage-api.onrender.com. Provider keys belong only in the backend environment. Render may sleep; its SQLite quota ledger can reset on replacement instances. Initial live access is code-restricted and fixed-free, with no paid fallback. See release verification and limitations and release operations. The historical architecture/setup below describes the original presentation stack.
TCM-Sage is an evidence-synthesis tool for Traditional Chinese Medicine (TCM) practitioners. This project aims to empower practitioners by providing explainable, evidence-backed insights from the vast corpus of classical TCM literature using a Retrieval-Augmented Generation (RAG) architecture.
The vast body of TCM knowledge, spanning thousands of years of literature, represents both a profound asset and a significant operational challenge. Manually searching for analogous historical cases or cross-referencing symptoms during a patient consultation is impractical. This project leverages a Large Language Model (LLM) not as a decision-maker, but as an intelligent clinical reference assistant. By creating an explainable, evidence-backed tool, TCM-Sage empowers practitioners to query the entire corpus of TCM literature in seconds, helping them validate hypotheses and deliver informed, evidence-based care.
The system is built on a Modular RAG paradigm to handle the complexities of classical Chinese texts.
Knowledge Base: 17 classical TCM texts (3.72M characters) including the four canonical works (《黄帝内经》《伤寒论》《金匮要略》《神农本草经》), 本草纲目, 备急千金要方, 金元四大家著作, and 温病学 texts. Texts are chunked with sentence-aware splitting and embedded into a persistent ChromaDB vector store using DashScope text-embedding-v4 (1024 dimensions).
Hybrid Retriever: The retriever combines semantic vector search with the SymMap 2.0 Knowledge Graph (18,450 entities, 21,476 relationships) built with NetworkX and connected via a crosswalk bridge for entity resolution.
Reflective Generator: A two-layer "glass-box" generator inspired by Self-RAG ensures trustworthy answers:
Query Routing: A small, fast LLM pre-classifies query severity to apply either a creative (higher temperature) or strict (zero temperature) generation setting based on clinical severity.
Self-Critique: The main LLM generates an answer and then validates it against the retrieved source text, providing a direct citation to the source chapter.
The project is in active development approaching FYP presentation:
/kg/[entityId]) with interactive graph visualization.Clone the repository:
git clone https://github.com/AndyZHENG0715/TCM-Sage.git
cd TCM-Sage
Create a Python virtual environment (required):
python -m venv venv
Install backend dependencies using the project venv:
# Windows
venv\Scripts\python.exe -m pip install -r requirements.txt
# macOS / Linux
venv/bin/python -m pip install -r requirements.txt
Install frontend dependencies:
cd web
npm install
cd ..
Set up environment variables:
.env.example to .env.LLM_PROVIDER=alibaba
DASHSCOPE_API_KEY="your-api-key-here"
Build or refresh the vector knowledge base (run once after source updates):
# Windows
venv\Scripts\python.exe src/ingest.py
# macOS / Linux
venv/bin/python src/ingest.py
Start the backend API (http://127.0.0.1:8000):
# Windows
venv\Scripts\python.exe src/api.py
# macOS / Linux
venv/bin/python src/api.py
Start the frontend dev server (http://localhost:3000):
cd web
npm run dev
Run the CLI application (optional):
# Windows
venv\Scripts\python.exe src/main.py
# macOS / Linux
venv/bin/python src/main.py
Run lightweight verification scripts (optional):
# Citation formatting / reconstruction checks
venv\Scripts\python.exe src/test_citations.py
# SymMap KG retrieval sanity checks
venv\Scripts\python.exe scripts/verify_symmap_retrieval.py
TCM-Sage analyzes each query to determine clinical severity, routing it to optimized LLM instances with tailored temperature settings.
A modern, interactive graph viewer powered by @xyflow/react renders subgraph neighborhoods around cited entities with dagre layout, allowing practitioners to explore relationships between symptoms, herbs, formulas, and related entities from the SymMap 2.0 knowledge graph.
All responses are backed by direct, verifiable citations from the 17-text classical corpus. The system quotes original text verbatim before explaining, and presents citations in a dedicated panel with full paragraph viewing and source reconstruction.
A blind A/B comparison system where TCM practitioners evaluate RAG-enhanced responses against plain LLM responses without knowing which is which. Includes a statistics page (/arena/stats) with paired T-Test analysis, win rate charts (downloadable as PNG), and per-query results table.
Live statistical analysis of arena votes with downloadable bar charts and pie charts. Computes t-statistic, p-value, Cohen's d effect size, and significance interpretation for FYP presentation.
Seamlessly switch between Alibaba Cloud, Google, OpenAI, and Anthropic for maximum flexibility and availability.
See docs/CONFIGURATION.md for detailed configuration options including provider setup, retrieval parameters, model selection, and graph depth settings.
TCM-Sage/
├── src/ # Python RAG core (FastAPI, LangChain, retriever, arena)
│ ├── api.py # Thin FastAPI route layer (SSE, CORS, health)
│ ├── source_context.py # Citation source context and raw book lookup
│ ├── arena_stream.py # Arena dual-panel SSE scheduler
│ ├── arena_stats.py # Arena vote statistics and t-test analysis
│ ├── main.py # CLI entry point + LLM factory, prompts, classification
│ ├── retriever.py # HybridRetriever — vector + graph ensemble
│ ├── graph_builder.py # TCMKnowledgeGraph — NetworkX loader, traversal
│ ├── ingest.py # Build vector index + chunks.json
│ ├── arena.py # Arena blind A/B evaluation + vote storage
│ ├── embeddings.py # DashScope text-embedding-v4 + qwen3-rerank
│ └── config.py # Central paths and defaults
├── web/ # Next.js 16 frontend
│ ├── app/ # Routes: chat, arena/, arena/stats, kg/, source/
│ ├── components/ # UI components (CitationPanel, KGViewer, etc.)
│ ├── hooks/ # React hooks (useChat, useArena, useSettings)
│ ├── i18n/ # Chinese/English UI translations
│ └── lib/ # API client, markdown renderer, shared types
├── data/
│ ├── source/ # 17 classical TCM .txt corpus (UTF-8)
│ ├── processed/ # chunks.json + ingest_checkpoint.json
│ ├── graph/symmap/ # SymMap v2.0 KG JSON + raw xlsx
│ ├── graph/crosswalk/ # RAG↔SymMap entity bridge (approved/pending CSV)
│ └── feedback/ # Arena votes (arena_votes.jsonl)
├── scripts/ # Utility and test scripts
├── vectorstore/ # ChromaDB persistence (generated)
├── presentation/ # Slidev FYP presentation
├── docs/ # Project documentation
│ ├── ARCHITECTURE.md # System architecture
│ ├── CONFIGURATION.md # Configuration reference
│ ├── GETTING-STARTED.md # First-time setup guide
│ ├── DEVELOPMENT.md # Developer guide
│ ├── TESTING.md # Testing guide
│ ├── API.md # API reference
│ └── report/ # FYP Final Report (LaTeX + PDF)
└── requirements.txt # Python dependencies
This project is licensed under the MIT License. See the LICENSE file for details.