Skip to content

BlendIntel Core is a full-stack TypeScript project for nutrition chat. It uses Pinecone and OpenAI to answer detailed questions about smoothies, bowls, and ingredients. All responses are grounded in validated nutrition data, with a chatbox frontend for interactive, structured, and human-readable results.

Notifications You must be signed in to change notification settings

Rhardin378/BlendIntel-Core

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

37 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

BlendIntel Core

An intelligent nutrition search and recommendation system for Smoothie King menu items, powered by advanced RAG (Retrieval-Augmented Generation) architecture with FDA-compliant nutrition visualization.

๐ŸŽฏ Overview

BlendIntel Core transforms natural language nutrition queries into personalized smoothie recommendations by combining vector search, semantic reranking, and conversational AI. Users can type questions like "What's a high-protein smoothie with strawberries?" and receive accurate, context-aware suggestions with complete nutritional information displayed in familiar FDA nutrition label format.

โœจ Key Features

๐Ÿท๏ธ Nutrition Labels

  • Pixel-Perfect Rendering: Professionally formatted nutrition facts display
  • Size-Aware Display: Shows nutrition for selected serving size (20oz, 32oz, 44oz)
  • Visual Impact: Instantly recognizable format builds user trust

๐Ÿ” Semantic Search with RAG

  • Vector Embeddings: OpenAI's text-embedding-3-small (512 dimensions) converts menu items into semantic representations
  • Pinecone Vector Database: Stores and queries 300+ smoothie embeddings for lightning-fast similarity search
  • Rich Metadata: Each vector includes nutrition facts, allergens, ingredients, and available sizes

๐ŸŽฏ Intelligent Reranking

  • Two-Stage Retrieval: Initial vector search retrieves 30 candidates, then BGE-Reranker-v2-m3 reranks for precision
  • Cross-Encoder Model: Deeply analyzes query-document pairs for superior relevance vs. pure vector similarity
  • Context-Aware: Understands multi-constraint queries ("45g protein AND strawberries AND under 400 calories")

๐Ÿ’ฌ Conversational AI Response

  • GPT-3.5 Turbo: Generates natural language explanations for recommendations
  • Nutrition-Focused: Highlights protein content, macros, allergens, and portion sizes
  • Top 5 Alternatives: Provides options for dietary restrictions and preferences

๐Ÿ”— Share & Discover

  • URL State Persistence: Share search results via unique URLs
  • Auto-Search from URLs: Recipients see results instantly
  • Category Filtering: Browse by smoothies, bowls, or power eats

๐Ÿ—๏ธ Architecture

User Input (Text)
    โ†“
[OpenAI Embeddings] โ†’ Query Vector (512d)
    โ†“
[Pinecone Search] โ†’ Top 30 Candidates (vector similarity)
    โ†“
[BGE Reranker] โ†’ Top 10 Results (relevance scoring)
    โ†“
[GPT-3.5 Turbo] โ†’ Natural Language Response
    โ†“
Frontend Display:
  - AI Conversational Response
  - Top Recommendation Card
  - Expandable Alternatives
  - Collapsible Ingredients
  - Share Functionality

๐ŸŽจ User Experience Flow

Search Flow

1. User types โ†’ "High protein smoothie with strawberries"
2. Category filter (optional) โ†’ Smoothies
3. RAG pipeline processes โ†’ Gladiatorยฎ Strawberry found
4. Display results:
   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
   โ”‚ AI: "Perfect choice! The        โ”‚
   โ”‚ Gladiatorยฎ Strawberry has       โ”‚
   โ”‚ exactly 45g of protein..."      โ”‚
   โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
   โ”‚ ๐Ÿ† Top Recommendation           โ”‚
   โ”‚                                 โ”‚
   โ”‚ Gladiatorยฎ Strawberry           โ”‚
   โ”‚ Calories: 220 | Protein: 45g    โ”‚
   โ”‚ Carbs: 3g | Fat: 3g             โ”‚
   โ”‚                                 โ”‚
   โ”‚ ๐Ÿฅฃ Ingredients (12)              โ”‚
   โ”‚ [Expand to view]                โ”‚
   โ”‚                                 โ”‚
   โ”‚ ๐Ÿ”— Share results                โ”‚
   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
5. User clicks share โ†’ URL copied to clipboard
6. Share with friend โ†’ Auto-loads same results

๐Ÿ“Š Data Pipeline

1. Web Scraping

  • Scraped 100+ Smoothie King menu items with complete nutrition profiles
  • Extracted size variations, ingredients, allergens, and macros

2. Vector Generation

node scripts/embed.js
# โ†’ Generates embeddings for all smoothies
# โ†’ Output: smoothies_vectors.json, ingredients_vectors.json, etc.

3. Pinecone Upload

node scripts/upload-to-pinecone.js
# โ†’ Sanitizes metadata (flattens nested objects)
# โ†’ Chunks uploads (100 vectors/batch)
# โ†’ Creates index if needed

๐Ÿš€ API Endpoints

POST /api/nutritionSearchRerank

Request:

{
  "query": "What is a Smoothie with 45 protein and strawberries",
  "topK": 10,
  "category": "smoothies"
}

Response:

{
  "query": "...",
  "category": "smoothies",
  "topRecommendation": {
    "id": "smoothies_27",
    "name": "Gladiatorยฎ Strawberry",
    "nutrition_protein": 45,
    "nutrition_calories": 220,
    "nutrition_carbs": 3,
    "nutrition_fat": 3,
    "nutrition_sugar": 1,
    "nutrition_fiber": 1,
    "allergens": ["Egg", "Milk"],
    "ingredients": ["Strawberries", "Protein Blend", ...],
    "availableSizes": ["small(20 oz)", "medium(32 oz)", "large(44 oz)"],
    "nutritionSize": "medium(32 oz)"
  },
  "topFive": [ ... ],
  "allResults": [ ... ],
  "aiResponse": "Great choice! The Gladiatorยฎ Strawberry is perfect for your request with exactly 45g of protein...",
  "total": 10,
  "reranked": true
}

๐Ÿ› ๏ธ Tech Stack

Component Technology Purpose
Framework Next.js 15 (App Router) Full-stack React framework
Frontend React + TypeScript Type-safe UI components
Styling Tailwind CSS Responsive, utility-first styling
Vector DB Pinecone (Serverless) Semantic search at scale
Embeddings OpenAI text-embedding-3-small 512d vectors, $0.00002/1K tokens
Reranker Pinecone Inference (bge-reranker-v2-m3) Precision relevance scoring
LLM OpenAI GPT-3.5 Turbo Natural language responses
Analytics Vercel Analytics Search tracking & insights
Language TypeScript/JavaScript Type-safe development

๐Ÿงช Example Queries

Query Category Top Result Why It Works
"45g protein with strawberries" All Gladiatorยฎ Strawberry (45g) Exact protein match + ingredient
"Low calorie high protein" Smoothies Original High Protein Banana (330 cal, 27g) Optimizes both constraints
"Something for after the gym" All The Activatorยฎ Recovery Context-aware (post-workout)
"Nut-free option under 300 calories" Power Eats Power Punch Plusยฎ (280 cal) Allergen exclusion + calorie filter

๐ŸŽจ Frontend Components

Search Interface Features

  • โœ… Chat-style conversational UI
  • โœ… Category filtering (all, smoothies, bowls, power-eats)
  • โœ… URL state persistence for sharing
  • โœ… Auto-search from shared URLs
  • โœ… Loading states with animations
  • โœ… Empty state with category suggestions
  • โœ… Error handling with friendly messages

Result Card Features

  • โœ… AI-generated explanation with bold markdown support
  • โœ… Top recommendation with nutrition grid
  • โœ… Category badges with color coding
  • โœ… Allergen warnings
  • โœ… Collapsible ingredients section
  • โœ… Share button (Web Share API + clipboard)
  • โœ… Expandable alternatives (show top 5)
  • โœ… Responsive design (mobile-first)

๐Ÿ” Environment Variables

# OpenAI API
OPENAI_API_KEY=your_openai_key_here

# Pinecone Vector Database
PINECONE_API_KEY=your_pinecone_key_here
PINECONE_INDEX_NAME=nutrition-information

Getting API Keys

  1. OpenAI: platform.openai.com
  2. Pinecone: app.pinecone.io

๐Ÿ“ Local Development

# Install dependencies
npm install

# Set up environment variables
cp .env.example .env
# Add your API keys to .env

# Generate embeddings (one-time setup)
node scripts/embed.js

# Upload to Pinecone (one-time setup)
node scripts/upload-to-pinecone.js

# Start development server
npm run dev

# Open http://localhost:3000/search

Testing the API

Text Search:

curl -X POST http://localhost:3000/api/nutritionSearchRerank \
  -H "Content-Type: application/json" \
  -d '{"query":"high protein smoothie","topK":10,"category":"smoothies"}'

๐Ÿš€ Deployment

Vercel Deployment (Recommended)

# Install Vercel CLI
npm i -g vercel

# Deploy
vercel --prod

# Set environment variables in Vercel dashboard

Environment Setup

  1. Add all API keys to Vercel project settings
  2. Ensure Pinecone index is created and populated
  3. Verify rate limiting is working (10 requests/hour per IP)

๐Ÿ›ก๏ธ Rate Limiting

  • Limit: 10 searches per hour per IP address
  • Purpose: Protect OpenAI API costs during demo
  • Implementation: In-memory rate limiter with automatic cleanup
  • User Experience: Friendly error message with retry time

๐ŸŽ“ Learning Outcomes

This project demonstrates:

Backend/AI Engineering

  • โœ… Production RAG architecture (retrieve โ†’ rerank โ†’ generate)
  • โœ… Vector database optimization (metadata sanitization, chunking)
  • โœ… Multi-model orchestration (embeddings + reranker + LLM)
  • โœ… Cost-effective AI (strategic model selection)
  • โœ… Real-world data pipeline (scraping โ†’ embedding โ†’ indexing)
  • โœ… Rate limiting & cost protection

Frontend/UX Engineering

  • โœ… Chat-style conversational interface
  • โœ… Responsive, mobile-first design
  • โœ… Real-time user feedback (loading states, animations)
  • โœ… URL state management for sharing
  • โœ… Progressive disclosure (collapsible sections)
  • โœ… Markdown parsing for rich text formatting

Full-Stack Integration

  • โœ… Next.js 15 App Router patterns
  • โœ… TypeScript type safety across stack
  • โœ… API route design for AI services
  • โœ… Server-side rate limiting
  • โœ… Analytics integration
  • โœ… Error handling & user feedback

๐Ÿ”ฎ Future Enhancements

Planned Features

  • Spanish Language Support: Bilingual UI and query translation for Hispanic customers
  • Nutrition-Based Filtering: Client-side filters for calories, protein, carbs, allergens
  • User Preferences: Save favorite searches and dietary restrictions
  • Comparison Mode: Side-by-side nutrition comparison of multiple items
  • Enhanced Analytics: Track popular queries, category preferences, conversion metrics
  • Caching Layer: Redis for frequently searched queries
  • Component Refactoring: Break down large components for better maintainability

Technical Improvements

  • Spanish embeddings index for better multilingual search
  • Advanced reranking with nutrition-aware scoring
  • Progressive Web App (PWA) capabilities
  • Offline mode with cached results
  • A/B testing framework for search quality
  • Comprehensive unit and integration tests

๐Ÿ“Š Project Stats

  • Lines of Code: 6,353 (smoothies.json)
  • Menu Items: 300+
  • Categories: 3 (Smoothies, Bowls, Power Eats)
  • Nutrition Fields: 6 per item (calories, protein, carbs, fat, sugar, fiber)
  • Vector Dimensions: 512
  • Average Search Latency: ~2-3 seconds (embedding + vector search + rerank + GPT)

๐Ÿ“„ License

MIT


๐Ÿ—๏ธ Component Architecture

BlendIntel uses a modular component architecture with centralized state management for maintainability and scalability.

๐Ÿ“ Component Structure

src/app/search/components/
โ”œโ”€โ”€ layout/          # Page structure (header, filter, input)
โ”œโ”€โ”€ states/          # Loading, error, empty states
โ”œโ”€โ”€ messages/        # Chat interface components
โ”œโ”€โ”€ results/         # Search result display
โ””โ”€โ”€ shared/          # Reusable UI components

๐Ÿง  State Management Strategy

Context API (SearchContext) manages:

  • Search query and results
  • Loading/error states
  • Category selection
  • UI state (expanded items, show all results)

Props for pure display components:

  • NutritionGrid, AllergenBadges, CategoryBadge
  • Better testability and reusability

๐ŸŽฏ Adding New Components

  1. Determine if state comes from Context or Props
  2. Create component in appropriate directory
  3. Add to barrel export (index.ts)
  4. Import and use in parent component

Built with โค๏ธ for nutrition-conscious smoothie lovers

Combining the power of RAG, semantic search, and thoughtful UX design to make healthy choices effortless.

About

BlendIntel Core is a full-stack TypeScript project for nutrition chat. It uses Pinecone and OpenAI to answer detailed questions about smoothies, bowls, and ingredients. All responses are grounded in validated nutrition data, with a chatbox frontend for interactive, structured, and human-readable results.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •