Skip to content

RetainDB/retaindb-python-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

retaindb-python-starter

FastAPI chatbot with persistent memory powered by RetainDB.

Memories survive server restarts, redeployments, and new sessions — the AI remembers your users across every conversation.

Stack

  • FastAPI — REST API
  • OpenAI gpt-4o-mini — chat completions
  • RetainDB — persistent memory (no SDK required, direct REST calls)

Quickstart

# 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 --reload

API

POST /chat

Send 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
}

GET /memories/{user_id}

List all stored memories for a user.

curl http://localhost:8000/memories/alice

How it works

POST /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

Environment variables

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)

Related starters

About

FastAPI + OpenAI + RetainDB persistent memory starter for Python.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages