Skip to content

mandy8055/smart-filters-poc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” Smart Product Filter POC

AI-powered natural language product filtering for e-commerce washers.

Next.js TypeScript License: MIT


Overview

Transform natural language queries into precise product filters. Type "small family under $800" and get instant, accurate results.

Status: βœ… Proof of Concept (POC) - Production Ready
Purpose: Validate AI-powered filtering before full production deployment


✨ Recent Updates (2025-10-19)

πŸŽ‰ Major bug fixes and optimizations!

  • βœ… Fixed "small family" query (was returning 0 results)
  • βœ… Added pre-validation (rejects gibberish instantly)
  • βœ… Updated to non-deprecated HuggingFace API
  • βœ… Cleaned up logging (90% less noise)
  • βœ… Improved prompt engineering (no more hallucinations)

See CHANGELOG.md for details.


Quick Start

Prerequisites

  • Node.js 18+ or 20+
  • pnpm (recommended) or npm
  • HuggingFace API key (free tier available)

Installation

# Clone repository
git clone <your-repo-url>
cd smart-filters-poc

# Install dependencies
pnpm install

# Setup environment
cp .env.example .env.local
# Edit .env.local and add your HUGGINGFACE_API_KEY

Get HuggingFace API Key

  1. Go to HuggingFace Settings
  2. Create new token with "Read" access
  3. Copy token to .env.local:
    HUGGINGFACE_API_KEY=hf_your_token_here
    

Run Development Server

pnpm dev

Open http://localhost:3000


Key Features

  • πŸ€– AI-Powered - Natural language understanding with 85%+ accuracy
  • ⚑ Pre-Validation - Instant rejection of invalid queries (saves costs)
  • 🎨 Modern UI - Responsive Bosch-inspired design
  • πŸ›‘οΈ Triple Fallback - Pre-validation β†’ AI (3 retries) β†’ Rule-based
  • πŸ“Š Realistic Data - 50 products with exact distribution (30% budget, 40% mid-range, 24% premium, 6% luxury)
  • πŸ”§ Smart Corrections - Auto-fixes common AI mistakes
  • πŸ’¬ Helpful Errors - Suggestions when queries fail

Try It Out

Example Queries

Basic:

  • "small family" β†’ Shows compact washers (4.0-4.5 cu ft capacity)
  • "big family" β†’ Shows large washers (5.0+ cu ft capacity)
  • "energy efficient" β†’ Shows A++ and A+++ rated washers
  • "WiFi enabled" β†’ Shows smart washers with WiFi

Combined:

  • "small family under $800" β†’ Budget compact washers
  • "energy efficient with WiFi" β†’ Smart eco-friendly washers
  • "quiet premium washer" β†’ Low-noise premium washers
  • "budget friendly big family" β†’ Affordable large capacity

Will Be Rejected:

  • "akndkand random text" β†’ Instant error (no AI call)
  • "pizza delivery" β†’ Instant error (unrelated topic)

See docs/TESTING.md for comprehensive test scenarios.


Tech Stack

Frontend:

  • Next.js 15 (App Router)
  • React 19
  • TypeScript 5
  • Tailwind CSS 4

AI:

  • HuggingFace Inference API
  • Mistral-7B-Instruct-v0.3
  • InferenceClient (latest SDK)

Deployment:

  • Vercel
  • Environment variables via Vercel dashboard

Architecture Highlights

Three-Tier Validation System

1. Pre-Validation (Code) ⚑
   β”œβ”€ Checks for valid keywords
   β”œβ”€ Instant rejection (~1ms)
   └─ No AI call = Cost savings

2. AI Processing (HuggingFace) πŸ€–
   β”œβ”€ 3 retry attempts
   β”œβ”€ Smart prompt engineering
   └─ Response normalization

3. Rule-Based Fallback (Regex) πŸ”§
   β”œβ”€ Activates if AI fails
   └─ Always returns something

Smart Features

  • Auto-correction - Fixes attribute paths (e.g., energyRating β†’ specifications.energyRating)
  • Confidence tracking - Monitors AI certainty (0.0-1.0 scale)
  • Minimal logging - Only critical events logged
  • Cost optimization - Pre-validation prevents unnecessary AI calls

Project Structure

smart-filters-poc/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”‚   └── smart-filter/
β”‚   β”‚   β”‚       └── route.ts          # API endpoint with pre-validation
β”‚   β”‚   β”œβ”€β”€ page.tsx                  # Main page
β”‚   β”‚   └── globals.css
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”œβ”€β”€ SmartFilterInput.tsx      # Natural language input
β”‚   β”‚   β”œβ”€β”€ FilterPanel.tsx           # Traditional filters
β”‚   β”‚   β”œβ”€β”€ ProductGrid.tsx           # Product display
β”‚   β”‚   └── ProductCard.tsx
β”‚   └── lib/
β”‚       β”œβ”€β”€ services/
β”‚       β”‚   └── huggingface.ts        # AI service (InferenceClient)
β”‚       β”œβ”€β”€ mocks/
β”‚       β”‚   └── products.json         # 50 mock products
β”‚       β”œβ”€β”€ utils/
β”‚       β”‚   └── mock-data-generator.ts
β”‚       β”œβ”€β”€ available-filters.ts      # Filter configuration
β”‚       └── types.ts                  # TypeScript types
β”œβ”€β”€ docs/
β”‚   β”œβ”€β”€ API.md                        # API documentation
β”‚   β”œβ”€β”€ ARCHITECTURE.md               # Technical details
β”‚   β”œβ”€β”€ DEPLOYMENT.md                 # Deploy guide
β”‚   └── TESTING.md                    # Test scenarios
β”œβ”€β”€ CHANGELOG.md                      # Recent changes
└── README.md                         # This file

Documentation


Environment Variables

Required in .env.local:

HUGGINGFACE_API_KEY=hf_your_token_here

Get your key: HuggingFace Settings (free tier available)


Deployment

See docs/DEPLOYMENT.md for detailed instructions.


Performance

Metrics

  • Pre-validation: ~1ms (instant rejection)
  • AI response: 1-3 seconds (HuggingFace)
  • Rule-based fallback: ~1ms
  • Client-side filtering: Instant (50 products)

Cost Savings

  • Before: Every query calls AI (~1000 requests/day)
  • After: ~70-80% reach AI (gibberish rejected early)
  • Savings: 20-30% reduction in API calls

Roadmap

Current (POC Phase)

  • βœ… Core functionality working
  • βœ… Pre-validation implemented
  • βœ… Error handling robust
  • βœ… Documentation complete

Phase 2 (If Approved)

  • ⬜ Upgrade to OpenAI GPT-4 or Claude (better accuracy)
  • ⬜ Real product database integration
  • ⬜ User analytics tracking
  • ⬜ A/B testing framework
  • ⬜ Multi-language support

Future Considerations

  • ⬜ Voice input for mobile users
  • ⬜ Query history and suggestions
  • ⬜ Filter presets (save combinations)
  • ⬜ Autocomplete suggestions
  • ⬜ Custom confidence thresholds

Known Limitations

Current POC Limitations

  1. Mock Data - Using generated data, not real products
  2. HuggingFace Free Tier - ~1000 requests/day limit
  3. English Only - No multi-language support yet
  4. Washing Machines Only - Not generalized to other products
  5. No Persistence - Filters don't persist across page reloads

Production Considerations

  • Need real product database
  • Need paid AI tier (OpenAI/Claude recommended)
  • Need analytics tracking
  • Need user authentication (for history)
  • Need caching layer (Redis)

Troubleshooting

Common Issues

Issue: "No valid terms found" error
Solution: Use washing machine keywords (family, budget, WiFi, etc.)

Issue: "Service unavailable" error
Solution: Check HuggingFace API key in .env.local

Issue: Filters not showing in UI
Solution: Verify attribute paths match in available-filters.ts

Issue: Too many logs in console
Solution: Normal in development, minimal in production

See docs/ARCHITECTURE.md for debugging guide.


Testing

Run Test Scenarios

# Test valid queries
- "small family"
- "energy efficient"
- "WiFi enabled"
- "budget friendly big family"

# Test invalid queries (should reject)
- "akndkand random"
- "pizza delivery"
- "" (empty)

Verify Behavior

  • βœ… Valid queries return products
  • βœ… Invalid queries show helpful errors
  • βœ… Capacity inputs show values
  • βœ… Console logs are clean
  • βœ… No deprecation warnings

See docs/TESTING.md for comprehensive test scenarios.


License

MIT Β© 2025 - See LICENSE for details.


Support

For questions or issues:

  1. Check docs/TESTING.md for test scenarios
  2. Check docs/API.md for API details
  3. Check CHANGELOG.md for recent changes
  4. Check docs/ARCHITECTURE.md for technical details

Acknowledgments

  • HuggingFace - Free AI inference API
  • Vercel - Hosting and deployment platform
  • Next.js - React framework
  • Mistral AI - Mistral-7B-Instruct model

About

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages