CoolFace
Apppublic

kaigangi/palona-commerce-agent

sourceHugging Faceupdated 11mo agoView on Hugging Face
0likes
App README

AI Commerce Agent ๐Ÿ›๏ธ

An intelligent shopping assistant that handles conversation, text-based product search, and image-based product search through a single unified agent.

API Docs: Available at /docs when running

Features

  • โ€”Natural conversations with the AI assistant
  • โ€”Text-based product recommendations via semantic search
  • โ€”Image-based product search using visual similarity

Architecture

User โ†’ FastAPI โ†’ LLM Agent (GPT-4o-mini) โ†’ Tools
                           โ†“
        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
        โ†“                     โ†“               โ†“
      Chat              Text Search    Image Search
                            โ†“               โ†“
                       Embeddings        CLIP
                            โ†“               โ†“
                      ChromaDB Vector Store

Flow:

  1. 1.User sends request via Streamlit UI
  2. 2.FastAPI receives and routes the request
  3. 3.LLM Agent (GPT-4o-mini) decides which tool to use
  4. 4.Tools execute specific functions:
  5. 5.Chat: Direct conversation
  6. 6.Text Search: Semantic search using embeddings
  7. 7.Image Search: Visual similarity using CLIP
  8. 8.Vector Store (ChromaDB) returns relevant products

Tech Stack Decisions

Backend: FastAPI

  • โ€”Async support for concurrent LLM calls
  • โ€”Automatic API docs
  • โ€”Production-ready
  • โ€”Other Options: Flask (not suitable because of synchronous operations), Django (too heavy for small API layer)

LLM: OpenAI GPT-4o-mini

  • โ€”Fast (~500ms) for real-time chat
  • โ€”Cost-effective ($0.15/1M tokens, about 6x cheaper than GPT-4o)
  • โ€”Excellent function calling

Embeddings: OpenAI text-embedding-3-small

  • โ€”Strong semantic understanding
  • โ€”High speed and cost-efficient ($0.02 / 1M tokens)
  • โ€”Performs well for tasks like semantic similarity, text-to-image retrieval, and query expansion (without high cost of larger embedding models)

Image Search: CLIP (ViT-B/32)

  • โ€”Understands semantic similarity (not just visual)
  • โ€”Zero-shot
  • โ€”Why this size: Good accuracy/speed balance (512-dim, ~300ms CPU)

Vector DB: ChromaDB

  • โ€”Simple setup with no external dependencies
  • โ€”Fast HNSW indexing
  • โ€”Other Options: Better to migrate to Pinecone/Weaviate for 100K+ products

Frontend: Streamlit

  • โ€”Fast to deploy and intuitive
  • โ€”Eliminates lots of boilerplate code (built-in comopnents for chat messages, file uploads, etc.)
  • โ€”Other Options: React or Next.js for more production-based UI, but for this use case Streamlit can achieve what we need with far less code

Quick Start

bash
# Setup
python -m venv venv && source venv/bin/activate
pip install -r requirements.txt
export OPENAI_API_KEY="your-api-key-here"

# Run (2 terminals)
python -m backend.main             # Terminal 1: API on :8000
streamlit run streamlit_app/app.py  # Terminal 2: UI on :8501

Next Steps

Immediate Improvements

With more time, I would focus on three key areas: robustness, user experience, and evaluation.

Robustness:

  • โ€”Add comprehensive error handling and retry logic for API calls
  • โ€”Add option to choose different LLMs
  • โ€”Implement request validation to prevent malformed queries
  • โ€”Introduce structured logging with request IDs for easier debugging

User Experience:

  • โ€”Enhance the UI with product filtering by price and category
  • โ€”Add a shopping cart interface
  • โ€”Maintain conversation context to remember previous searches

Evaluation:

  • โ€”Build a framework to measure search relevance
  • โ€”Compare different embedding models and chunking strategies quantitatively

Improvements for Production-Grade Deployment

For a production-grade deployment, I would:

  • โ€”Implement proper authentication and rate limits
  • โ€”Migrate to a managed vector database (e.g., Pinecone) for scalability
  • โ€”Add Redis caching for frequently searched queries
  • โ€”Set up monitoring with Prometheus and Grafana to track latency, error rates, and tool usage
  • โ€”Develop a comprehensive test suite covering:
  • โ€”Empty or malformed search queries
  • โ€”Corrupted image uploads
  • โ€”Concurrent user requests
  • โ€”Add hybrid search to combine text and image inputs for more accurate product matching
  • โ€”Conversational memory: persist user preferences across sessions for personalized recommendations
  • โ€”Multi-language support
  • โ€”A/B testing framework (to compare prompts, models, and search strategies)