Skip to content

techsplot/mem0-express-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mem0-express-api

A TypeScript Express REST API that demonstrates how to add persistent memory to an AI assistant using Mem0 and Groq.

What it does

Most AI APIs are stateless — every request starts from zero. This project shows how to fix that by integrating Mem0 as a memory layer, so your AI assistant remembers users across conversations.

Stack

  • Express.js — REST API framework
  • TypeScript — type safety
  • Mem0 — persistent memory layer
  • Groq — LLM inference (llama-3.3-70b-versatile)

Endpoints

Method Endpoint Description
POST /chat/:userId Send a message and get a memory-aware response
GET /chat/:userId/memories Retrieve all stored memories for a user
DELETE /chat/:userId/memories Clear all memories for a user
POST /chat/:userId/no-memory Send a message with no memory context (for comparison)

Getting started

Prerequisites

Installation

git clone https://github.com/yourusername/mem0-express-api.git
cd mem0-express-api
npm install

Environment variables

Create a .env file in the root:

GROQ_API_KEY=your_groq_key_here
MEM0_API_KEY=your_mem0_key_here
PORT=3000

Run

npm run dev

Usage

Send a message:

curl -X POST http://localhost:3000/chat/user123 \
  -H "Content-Type: application/json" \
  -d '{"message": "My name is Ayomide and I am building an API platform called APIblok"}'

Check stored memories:

curl http://localhost:3000/chat/user123/memories

Compare with no memory:

curl -X POST http://localhost:3000/chat/user123/no-memory \
  -H "Content-Type: application/json" \
  -d '{"message": "What do you know about me?"}'

Clear memories:

curl -X DELETE http://localhost:3000/chat/user123/memories

How it works

  1. User sends a message to /chat/:userId
  2. Mem0 searches for relevant memories for that user
  3. Memories are injected into the system prompt
  4. Groq generates a context-aware response
  5. The exchange is stored in Mem0 for future requests

Article

Read the full tutorial: [link to article]

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors