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.
This app uses the Neocortex SDK in two ways:
- Namespace:
products(configurable viaALPHAHUMAN_PRODUCTS_NAMESPACE). - Insert: When products are created (e.g. bulk CSV upload) or after AI generates descriptions, the app calls
insertMemorywith title, features, short/long description, and optional SEO fields. Each product uses a stabledocumentIdso updates overwrite the same logical document. - Query: Before generating product descriptions or SEO metadata, the app calls
queryMemorywith 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.
- Namespace:
brand(configurable viaALPHAHUMAN_BRAND_NAMESPACE). - Insert: When brand settings (tone and style guidelines) are saved in the Settings UI, the app calls
insertMemorywith 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
queryMemoryon 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.
| 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.
- Next.js, React, TypeScript
- MongoDB (products, brand settings)
- Redis + BullMQ (background description jobs)
- OpenAI (descriptions, SEO, blog)
- @tinyhumansai/neocortex (memory insert + RAG query)
- Install dependencies:
npm install - Create a
.envfile with:MONGODB_URI,REDIS_URL,OPENAI_API_KEYfor core featuresALPHAHUMAN_TOKENto enable Neocortex memory (optional; app works without it)- Optionally:
ALPHAHUMAN_BASE_URL,ALPHAHUMAN_PRODUCTS_NAMESPACE,ALPHAHUMAN_BRAND_NAMESPACE,ALPHAHUMAN_MEMORY_ENABLED
- Start MongoDB and Redis.
- Run the app:
npm run dev - Run the background worker:
npm run worker:ai
npm run dev— Next.js dev servernpm run worker:ai— BullMQ worker for product description jobsnpm run build/npm run start— Production build and startnpm run lint— ESLint