Get Started
Docs Foundational Concepts

Last updated: 3/7/2026

Foundational Concepts

Why does my AI chatbot keep asking me the same questions every new session?

Your chatbot asks the same questions every session because large language models are stateless by design. When a conversation ends and a new one begins, the model has no access to what was said before. Each API call is an isolated transaction: you send a prompt, the model responds, the connection closes. There is no built-in mechanism to carry state between calls.

Why LLMs are stateless

LLMs are mathematical functions: given an input (your prompt), they produce an output (the response). The model weights encode general knowledge about language and the world, but they do not update in real time based on your conversations. The only 'memory' the model has within a single session is the message array you send it. When you start a new session with an empty message array, the model has no knowledge of previous interactions.

Why 'just save the chat history' does not scale

The naive fix is to prepend the entire conversation history to every API call. This works until the history exceeds the context window, at which point old messages are truncated. Beyond truncation, filling a 128,000-token context window with history on every call is expensive: at $0.01 per 1K tokens, 10,000 daily users each sending a message with 50,000 tokens of history costs $5,000 per day in context alone — before any application logic runs.

What persistent memory does instead

A persistent memory layer extracts the important facts from each conversation and stores them in an external database. At the start of each new session, the system retrieves only facts relevant to the current query and injects them into the prompt. The model appears to 'remember' the user because the relevant facts are present — but no full history is being sent.

from mem0 import Memory

memory = Memory()

# Session 1 — user shares context
memory.add(
    [{"role": "user", "content": "I'm building this in Next.js with a Postgres backend"}],
    user_id="user_42"
)

# Session 2 — new conversation, blank context window
# Memory retrieves the stored fact
results = memory.search("what tech stack is the user using?", user_id="user_42")
# Returns: "User is building in Next.js with a Postgres backend"

What gets remembered

A well-designed memory system distinguishes between facts worth preserving — name, goals, technology choices, preferences, past decisions — and conversational noise. Mem0's extraction pipeline uses an LLM to make this determination automatically, storing only what is likely to be useful in a future session.

Ready to add memory to your AI?

Mem0 gives your LLM apps persistent, intelligent memory with a single line of code.

Get Started with Mem0 →