CoolFace
Apppublic

dmcartor/nutrition-disorder-RAG-bot

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
App README

Nutrition Disorder RAG Bot

A conversational agent built with Streamlit that answers user questions about nutrition disorders using a Retrieval-Augmented Generation (RAG) workflow. It integrates an LLM (GPT-4o-mini) with a vector database to provide accurate, evidence-based responses grounded in domain-specific documents.


Table of Contents

  1. 1.What the App Does
  2. 2.Tech Stack & Tools
  3. 3.Key Skills Demonstrated
  4. 4.Installation & Setup
  5. 5.Usage
  6. 6.Issues Encountered & Lessons Learned
  7. 7.License

What the App Does

  • —Provides a chat-based interface for users to ask questions about nutrition disorders (symptoms, causes, treatments, etc.).
  • —Uses a RAG pipeline to:
  1. 1.Expand the user query with domain terminology.
  2. 2.Retrieve relevant snippets from a Chroma vector store.
  3. 3.Generate an initial answer via GPT-4o-mini.
  4. 4.Score groundedness and precision of the response.
  5. 5.Refine the response or query in iterative loops until a quality threshold is met.
  6. 6.Maintains conversational memory with Mem0, allowing context continuity and personalized follow-up.
  7. 7.Enforces input safety via Llama Guard (Groq) before processing any user message.

Tech Stack & Tools

  • —Python 3.10+: Core language for the application.
  • —Streamlit: Front-end UI framework for rapid app deployment.
  • —LangChain & langchain-openai: Workflow orchestration and LLM integration.
  • —ChromaDB: High-performance vector store for embedding-based retrieval.
  • —OpenAI API (GPT-4o-mini): Underlying model for query expansion, generation, and evaluation.
  • —Groq Guard: Safety filter for user inputs.
  • —Mem0: Session-based memory storage for conversational history.
  • —dotenv: Secure management of environment variables (API keys, endpoints).
  • —Docker (optional): Containerization (used during testing on Hugging Face Spaces).

Key Skills Demonstrated

  1. 1.Retrieval-Augmented Generation (RAG)
  • —Designing and orchestrating multi-step query, retrieval, generation, and iterative refinement loops.
  • —Vector Database Management
  • —Ingesting domain-specific documents, creating embeddings, and configuring a Chroma vector store.
  • —LLM Integration & Prompt Engineering
  • —Crafting system and user prompts for query expansion, groundedness scoring, precision checking, and response refinement.
  • —API & Environment Configuration
  • —Handling custom API endpoints and keys securely via .env; diagnosing 401 errors and endpoint mismatches.
  • —Dependency & Version Control
  • —Aligning local Python packages with a Colab environment (pip freeze, venv) to resolve compatibility issues.
  • —Streamlit App Development
  • —Building conversational UI components, session state management, and error trace display.
  • —Debugging & Deployment
  • —Troubleshooting in Colab, Docker, Hugging Face Spaces, and local environments; interpreting stack traces.

Installation & Setup

  1. 1.Clone the repository
bash
   git clone <repo-url>
   cd Nutrition_Disorder_RAG_Bot
  1. 1.Create a virtual environment
bash
   python3 -m venv venv
   source venv/bin/activate  # macOS/Linux
   venv\\Scripts\\activate   # Windows PowerShell
  1. 1.Install dependencies
bash
   pip install -r requirements.txt
  1. 1.Configure environment variables
  • —Copy .env.example to .env and fill in:
dotenv
     API_KEY="<>"                # OpenAI key 
     OPENAI_API_BASE="<>"        # If relevant
     GROQ_KEY="gsk-..."
     MEM0="m0-..."
  1. 1.Prepare the Chroma vector store
  • —Ensure your research_db/ directory is populated with embeddings (see ingestion script).

Usage

bash
streamlit run app.py
  1. 1.Enter your name to start a session.
  2. 2.Ask any nutrition disorder question.
  3. 3.View real-time safety filtering, tracebacks, and iterative RAG logs.
  4. 4.Type exit to end the conversation.

Issues Encountered & Lessons Learned

  • —Dependency Drift: Colab’s environment tolerated mismatched LangChain variants. Local install required pinning exact versions and aligning imports (langchain-openai vs langchain-community).
  • —Endpoint Wiring: Some client wrappers didn’t respect openai_api_base. Solution: explicitly set openai.api_base and openai.api_key at runtime.
  • —Complex Workflow Debugging: Iterative scoring and refinement loops needed careful logging (print, Streamlit’s st.code(traceback)) to trace state and diagnose broken transitions.
  • —Docker & HF Spaces: Containerizing Streamlit and matching requirements.txt libraries was crucial to reproduce local success remotely.