Skip to content

tinyhumansai/example-ecommerce-brain

Repository files navigation

Example E-commerce Brain

Example Next.js app that demonstrates how to use @tinyhumansai/neocortex for semantic memory and RAG in an e-commerce content workflow. The app generates product descriptions, SEO metadata, and blog content with AI, using the SDK to keep outputs consistent with existing catalog and brand voice.

How the SDK is used

This app uses the Neocortex SDK in two ways:

1. Catalog / product memory

  • Namespace: products (configurable via ALPHAHUMAN_PRODUCTS_NAMESPACE).
  • Insert: When products are created (e.g. bulk CSV upload) or after AI generates descriptions, the app calls insertMemory with title, features, short/long description, and optional SEO fields. Each product uses a stable documentId so updates overwrite the same logical document.
  • Query: Before generating product descriptions or SEO metadata, the app calls queryMemory with a query like “similar products and consistent phrasing” or “catalog keyword themes.” The returned context is injected into the AI system prompt so new copy matches existing catalog style and themes.

2. Brand / style memory

  • Namespace: brand (configurable via ALPHAHUMAN_BRAND_NAMESPACE).
  • Insert: When brand settings (tone and style guidelines) are saved in the Settings UI, the app calls insertMemory with a single “Brand voice” document so it can be retrieved via RAG.
  • Query: Before any AI generation (product descriptions, SEO, blog titles/outline/article), the app calls queryMemory on the brand namespace (e.g. “What is our brand tone and style guidelines?”). The context is passed into the prompts alongside the existing brand-voice block so all content stays on-brand.

SDK usage summary

Use case SDK method When Purpose
Catalog ingest insertMemory Bulk upload; after description generation in worker Store product text for RAG
Catalog RAG queryMemory Product description + SEO metadata generation Retrieve similar products/themes for prompts
Brand ingest insertMemory Save brand settings (Settings page) Store tone + guidelines for RAG
Brand RAG queryMemory All generation routes + worker Retrieve brand context for prompts

The app uses a thin wrapper in src/lib/memory/alphahuman.ts that builds an AlphahumanMemoryClient from env, then exposes upsertProductToCatalogMemory, queryCatalogMemory, upsertBrandToMemory, and queryBrandMemory. If the SDK token is not set, all calls are no-ops so the app still runs without memory.

Tech stack

  • Next.js, React, TypeScript
  • MongoDB (products, brand settings)
  • Redis + BullMQ (background description jobs)
  • OpenAI (descriptions, SEO, blog)
  • @tinyhumansai/neocortex (memory insert + RAG query)

Setup

  1. Install dependencies: npm install
  2. Create a .env file with:
    • MONGODB_URI, REDIS_URL, OPENAI_API_KEY for core features
    • ALPHAHUMAN_TOKEN to enable Neocortex memory (optional; app works without it)
    • Optionally: ALPHAHUMAN_BASE_URL, ALPHAHUMAN_PRODUCTS_NAMESPACE, ALPHAHUMAN_BRAND_NAMESPACE, ALPHAHUMAN_MEMORY_ENABLED
  3. Start MongoDB and Redis.
  4. Run the app: npm run dev
  5. Run the background worker: npm run worker:ai

Scripts

  • npm run dev — Next.js dev server
  • npm run worker:ai — BullMQ worker for product description jobs
  • npm run build / npm run start — Production build and start
  • npm run lint — ESLint

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages