Overview
| Layer | Technology | Scope | Expires |
|---|---|---|---|
| Short-Term Memory (STM) | Redis | Session | 30 minutes of inactivity |
| Long-Term Memory (LTM) | Mem0 | User | Never |
| Chat history | SQLite | Local device | Never |
- Short-term memory (STM)
- Long-term memory (LTM)
STM stores the recent message history for a single session in Redis. It is the primary source of conversational context during an active chat.Key format:Each key holds a Redis list of serialized Appends a message and immediately calls Fetches the full list for the session and deserializes each entry.Trims the list to the most recent
ChatMessage objects. Three functions manage the list:lTrim to keep the list within MAX_MESSAGES. Then sets the TTL to TTL_SECONDS to start (or reset) the inactivity clock.TRIM_TO messages. Called automatically during memory compression (see below).STM constants:| Constant | Value | Meaning |
|---|---|---|
STM_PREFIX | "stm:" | Redis key namespace |
MAX_MESSAGES | 20 | List length before compression is triggered |
TRIM_TO | 10 | Messages retained after compression |
TTL_SECONDS | 1800 | Inactivity TTL in seconds (30 minutes) |
STM is session-scoped. If a session is idle for 30 minutes, Redis expires the key and the next message starts a fresh context window. Long-term facts are preserved in Mem0 and are not affected by expiry.
How memory is assembled at query time
InsideretriveContext in retrival.ts, all three memory sources are fetched and combined before the LLM call:
- STM context — the recent conversation turns formatted as
role: contentlines. - LTM context — summarized long-term facts from Mem0.
- Vector search results — the re-ranked document chunks most relevant to the current question.
Local chat history (SQLite)
Separately from STM and LTM, every exchange is written to a local SQLite database. This store:- Never expires — it is a permanent audit log of all conversations.
- Stays on your device — no data leaves your local machine.
- Is not used as retrieval context; it exists for user-facing chat history display.
The SQLite history and the Redis STM are independent. Clearing your Redis instance (or waiting for the TTL to expire) does not delete your chat history from SQLite.