FastAPI chatbot with persistent memory powered by RetainDB.
Memories survive server restarts, redeployments, and new sessions — the AI remembers your users across every conversation.
- FastAPI — REST API
- OpenAI
gpt-4o-mini— chat completions - RetainDB — persistent memory (no SDK required, direct REST calls)
# 1. Clone
git clone https://github.com/Alinxus/retaindb-python-starter
cd retaindb-python-starter
# 2. Install
pip install -r requirements.txt
# 3. Configure
cp .env.example .env
# Edit .env with your keys
# 4. Run
uvicorn main:app --reloadSend a message and get a reply. Memories are retrieved and stored automatically.
curl -X POST http://localhost:8000/chat \
-H "Content-Type: application/json" \
-d '{"user_id": "alice", "message": "My name is Alice and I love hiking"}'{
"reply": "Nice to meet you, Alice! Any favourite trails?",
"context_used": false
}On the next request (even after a server restart):
curl -X POST http://localhost:8000/chat \
-H "Content-Type: application/json" \
-d '{"user_id": "alice", "message": "What do you know about me?"}'{
"reply": "You're Alice and you love hiking!",
"context_used": true
}List all stored memories for a user.
curl http://localhost:8000/memories/alicePOST /chat
│
├─► POST /v1/context/query ──► RetainDB retrieves relevant memories
│
├─► OpenAI gpt-4o-mini (memories injected as system prompt)
│
└─► POST /v1/learn ──► Stores the turn for future sessions
| Variable | Description |
|---|---|
RETAINDB_API_KEY |
Get free at retaindb.com |
OPENAI_API_KEY |
Get at platform.openai.com |
RETAINDB_BASE_URL |
Override API base (optional, default https://api.retaindb.com) |
- retaindb-nextjs-starter — Next.js + Vercel AI SDK
- retaindb-express-starter — Express.js + Vercel AI SDK
- retaindb-langchain-starter — Python LangChain + LangGraph