dmcartor/nutrition-disorder-RAG-bot
0
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
- What the App Does
- Tech Stack & Tools
- Key Skills Demonstrated
- Installation & Setup
- Usage
- Issues Encountered & Lessons Learned
- 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:
- Expand the user query with domain terminology.
- Retrieve relevant snippets from a Chroma vector store.
- Generate an initial answer via GPT-4o-mini.
- Score groundedness and precision of the response.
- Refine the response or query in iterative loops until a quality threshold is met.
- Maintains conversational memory with Mem0, allowing context continuity and personalized follow-up.
- 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
- 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
- Clone the repository
git clone <repo-url>
cd Nutrition_Disorder_RAG_Bot- Create a virtual environment
python3 -m venv venv
source venv/bin/activate # macOS/Linux
venv\\Scripts\\activate # Windows PowerShell- Install dependencies
pip install -r requirements.txt- Configure environment variables
- Copy
.env.exampleto.envand fill in:
API_KEY="<>" # OpenAI key
OPENAI_API_BASE="<>" # If relevant
GROQ_KEY="gsk-..."
MEM0="m0-..."- Prepare the Chroma vector store
- Ensure your
research_db/directory is populated with embeddings (see ingestion script).
Usage
streamlit run app.py- Enter your name to start a session.
- Ask any nutrition disorder question.
- View real-time safety filtering, tracebacks, and iterative RAG logs.
- Type
exitto 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-openaivslangchain-community). - Endpoint Wiring: Some client wrappers didn’t respect
openai_api_base. Solution: explicitly setopenai.api_baseandopenai.api_keyat runtime. - Complex Workflow Debugging: Iterative scoring and refinement loops needed careful logging (
print, Streamlit’sst.code(traceback)) to trace state and diagnose broken transitions. - Docker & HF Spaces: Containerizing Streamlit and matching
requirements.txtlibraries was crucial to reproduce local success remotely.
