NutriGen is a Retrieval-Augmented Generation (RAG) system designed to intelligently answer questions about nutrition and dietary science using contextual retrieval, embeddings, and LLM-based augmentation.
It combines Jupyter-based data preparation, Supabase vector search, and a Next.js + OpenAI frontend for real-time conversational responses.
NutriGen leverages the power of:
- LLM embeddings & retrieval for understanding nutrition documents
- Supabase pgvector for fast similarity search
- OpenAI GPT models (and optionally Gemma 7B locally) for natural language responses
- Next.js frontend for an elegant chat-based user interface
The system reads and embeds research documents, stores them as vectors in Supabase, and then uses OpenAI to generate context-aware responses.
π NutriGen/ βββ π main_notebook.ipynb β Jupyter notebook for manual chunking & embedding β ββ Handles 5 chunking strategies β ββ Embedding via all-mpnet-base-v2 and local Gemma 7B β ββ Performs RAG pipeline testing locally β βββ π Backend API/ β βββ ingest.py β Automated ingestion + embedding pipeline β β ββ Uses OpenAI text-embedding-3-small β β ββ Stores embeddings in Supabase (pgvector) β β ββ Connects PostgreSQL for vector queries β βββ ... other scripts β βββ π app/ β βββ api/chat/route.ts β Next.js API route for RAG query + OpenAI augmentation β βββ page.tsx β Frontend chat interface β βββ π .env β Environment variables (OpenAI & Supabase keys) βββ π package.json βββ π README.md βββ π public/ βββ (images for visualization)
yaml Copy code
- Manually chunked 5 types of text splitting for different structural analysis.
- Used Sentence Transformers (
all-MiniLM-L6-v2,all-mpnet-base-v2) to embed text. - Tested Gemma 7B locally for comparison in generation quality.
- Stored embeddings temporarily for inspection and visualization.
ingest.pyautomates embedding creation and uploading.- Uses OpenAIβs
text-embedding-3-smallmodel. - Embeddings are stored in Supabase (PostgreSQL + pgvector).
- A RPC function
match_documentsin Supabase retrieves top-k matches by cosine similarity.
route.tsreceives a query β embeds it β retrieves relevant chunks via Supabase RPC.- If results found: constructs a contextual prompt and sends to OpenAI Chat Completion API.
- If not: returns a helpful fallback response.
- Built in
/app/page.tsx - Features a minimal sleek chat interface inspired by OpenAI Chat UI.
- Displays:
- User + Assistant messages
- Animated typing indicator (three dots while generating)
- Clickable citations showing contextual snippets from source pages
- Dynamic sources section with similarity scores
- Styled in the theme of arcprize.org for a refined scientific aesthetic.
| Layer | Tools / Frameworks |
|---|---|
| Frontend | Next.js 15, React, Tailwind CSS, Framer Motion |
| Backend API | Node.js, OpenAI API |
| Database / Vector Store | Supabase (PostgreSQL + pgvector) |
| Embedding Models | OpenAI text-embedding-3-small, Sentence Transformers |
| Generation Models | OpenAI GPT-4o / GPT-3.5, Gemma 7B (local) |
| Data Prep Notebook | Python, torch, sentence-transformers, numpy, pandas |
Create a .env file in the root:
OPENAI_API_KEY=your_openai_key
SUPABASE_URL=your_supabase_project_url
SUPABASE_SERVICE_ROLE_KEY=your_supabase_service_role_key