--- title: RAG for Vrikshayurveda emoji: 🌿 colorFrom: green colorTo: green sdk: gradio sdk_version: "4.44.1" app_file: app.py pinned: false license: mit --- # 🌿 RAG for Vrikshayurveda **Retrieval-Augmented Generation for Surapala's Science of Plant Life (ΰ€΅ΰ₯ƒΰ€•ΰ₯ΰ€·ΰ€Ύΰ€―ΰ₯ΰ€°ΰ₯ΰ€΅ΰ₯‡ΰ€¦)** A full-stack AI system that diagnoses plant disorders and recommends traditional Ayurvedic treatments based on the ancient Vrikshayurveda text by Surapala. Combines modern RAG architecture with a classical forward + backward chaining inference engine. ![Python](https://img.shields.io/badge/Python-3.10+-blue?logo=python&logoColor=white) ![Gradio](https://img.shields.io/badge/Gradio-4.x-orange?logo=gradio&logoColor=white) ![License](https://img.shields.io/badge/License-MIT-green) --- ## πŸ—οΈ Architecture ``` User Query β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Query Expansion β”‚ ← Groq (Llama 3.3 70B) generates 3 rephrasings β”‚ (4 variants) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ BGE-large-en β”‚ ← BAAI/bge-large-en-v1.5 (1024-dim embeddings) β”‚ Encoding β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Pinecone Vector β”‚ ← Top-K retrieval + deduplication by parent ID β”‚ Search β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β” β–Ό β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Contextβ”‚ β”‚ Inference Engine β”‚ β”‚ Build β”‚ β”‚ β€’ Symptom Extractor β”‚ β”‚ β”‚ β”‚ β€’ Forward Chaining β”‚ β”‚ β”‚ β”‚ β€’ Backward Chaining β”‚ β”‚ β”‚ β”‚ β€’ 42 Ayurvedic Rulesβ”‚ β””β”€β”€β”€β”¬β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Groq LLM β”‚ ← Llama 3.3 70B generates final response β”‚ (RAG + Inference β”‚ β”‚ grounded) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` --- ## ✨ Features ### 🩺 Diagnose Tab - Describe plant symptoms in natural language - Get Ayurvedic diagnosis with dosha classification (Vata/Pitta/Kapha) - View the full reasoning chain from the inference engine - Receive traditional treatment recommendations from Vrikshayurveda - See retrieved source passages with relevance scores ### πŸ”— Symptom Chain Explorer - Interactive visual inference engine - Select symptoms from 27 observable indicators - Watch forward chaining fire rules in real-time on a canvas - Step through rules one at a time or auto-run the full chain - See proof trace with colored condition/conclusion pills - Stats bar showing fact count, rules fired, and diagnosed disorders --- ## 🧠 Inference Engine The inference engine implements **42 Ayurvedic diagnostic rules** from the Vrikshayurveda text: | Component | Description | |-----------|-------------| | **Symptom Extractor** | NLP-based extraction of atomic facts from natural language | | **Forward Chaining** | Priority-sorted rule firing to derive disorders and remedies | | **Backward Chaining** | Differential diagnosis across 10 disorder categories | | **Rule Base** | 42 YAML-defined rules covering 3 doshas, 10 disorders, 8 causes | ### Disorder Categories - **Internal**: Vata, Pitta, Kapha disorders - **External**: Heat/Frost, Stormy Wind, Fire/Lightning/Drought - **Other**: Mechanical Wound, Faulty Seed, Insect Infestation, Excessive Watering --- ## πŸš€ Setup ### Prerequisites - Python 3.10+ - API keys for Pinecone, Groq ### Installation ```bash git clone https://github.com/Viraj-77/RAG4Vrikshayurveda.git cd RAG4Vrikshayurveda pip install -r requirements.txt ``` ### Environment Variables Create a `.env` file: ```env GROQ_API_KEY=your_groq_api_key PINECONE_API_KEY=your_pinecone_api_key PINECONE_INDEX_NAME=jaim3 ``` ### Run ```bash python app.py ``` The app launches at `http://127.0.0.1:7860` --- ## πŸ“ Project Structure ``` RAG4Vrikshayurveda/ β”œβ”€β”€ app.py # Gradio web interface + Symptom Chain Explorer β”œβ”€β”€ rag_pipeline.py # Core RAG pipeline (embed β†’ retrieve β†’ generate) β”œβ”€β”€ inference/ β”‚ β”œβ”€β”€ engine.py # Unified inference entry point β”‚ β”œβ”€β”€ forward_chain.py # Forward chaining engine β”‚ β”œβ”€β”€ backward_chain.py # Backward chaining + differential diagnosis β”‚ └── symptom_extractor.py # NLP fact extraction from text β”œβ”€β”€ vrikshayurveda_rules.yaml # 42 Ayurvedic diagnostic rules β”œβ”€β”€ db.pdf # Vrikshayurveda source text β”œβ”€β”€ embed_pdf.py # PDF β†’ Pinecone indexing script β”œβ”€β”€ augment_and_reindex.py # Data augmentation + reindexing β”œβ”€β”€ requirements.txt └── .env # API keys (not committed) ``` --- ## πŸ”§ Tech Stack | Component | Technology | |-----------|-----------| | **Embeddings** | BAAI/bge-large-en-v1.5 (1024 dimensions) | | **Vector DB** | Pinecone | | **LLM** | Llama 3.3 70B via Groq | | **Inference** | Custom forward + backward chaining engine | | **Frontend** | Gradio 4.x | | **Knowledge Base** | Vrikshayurveda by Surapala | --- ## πŸ“š References - **Vrikshayurveda** β€” *The Science of Plant Life* by Surapala (ancient Indian botanical text) - Surapala's Vrikshayurveda covers plant diseases, their causes (doshas), and Ayurvedic treatments using natural materials --- ## πŸ“„ License This project is licensed under the MIT License.