Memory gives an AI agent continuity across otherwise stateless model calls. Parametric memory is knowledge encoded in model weights during training. Non-parametric memory is maintained outside the model, updated at runtime, and selectively supplied in the context window. It enables the agent to reuse past facts, preferences, and outcomes without retraining the model. section 1.5.4 section 5.1
Non-parametric memory has two complementary lifetimes:
- Short-term memory preserves the current session’s conversation and actions. The application replays a curated view on each call; the session memory ends with the session. section 1.5.4
- Long-term memory stores searchable information across sessions, in databases, vector databases, knowledge graphs, or files. The agent explicitly queries it, and matching entries—not the whole store—enter context. section 5.1.2 section 1.5.4
Figure 5.1 Memory in an AI agent: parametric memory inside the model, and non-parametric memory kept in persistent and ephemeral storage, surfaced in the context window as long-term memory, short-term memory, and state
The diagram maps persistent and ephemeral storage to the context window, including loading stored knowledge and promoting durable results. section 5.1
Memory differs from state. Short-term memory records what was said and done; state holds structured operational variables such as the active goal, progress, and collected parameters. Long-term memory sits outside the active session. Frameworks may combine these concepts in one object or expose separate abstractions. section 5.1.3
Long-term memories can be organized by what they retain:
- Semantic memory holds facts and stable knowledge, such as a user profile or domain information. section 5.1.2
- Episodic memory records past interactions and outcomes, which can serve as historical references or in-context examples. section 5.1.2
- Procedural memory encodes routines, workflows, and action patterns for carrying out tasks. section 5.1.2
A preference across sessions
A travel agent retains a user’s preference for evening flights in the current session. If the preference is saved to long-term memory, a later session can retrieve it and use it when proposing flights. section 1.5.4
A practical request flow retrieves relevant memories, adds a selected subset to the model’s instructions, produces a response, and writes useful information from the interaction back to storage. With Mem0 and Qdrant, Mem0 manages conversational memories and Qdrant supports semantic retrieval. Retrieved entries should not be assumed correct. section 5.5.1
Listing 5.2 Python excerpt using Mem0 and Qdrant to illustrate long-term memory retrieval and persistence
from mem0 import Memory
def build_mem0_config() -> Dict[str, Any]: #1
return {
"vector_store": {
"provider": "qdrant",
"config": {
"collection_name": os.getenv("MEM0_COLLECTION", "mem0_demo"),
"host": os.getenv("QDRANT_HOST", "localhost"),
"port": int(os.getenv("QDRANT_PORT", "6333")),
},
},
}
mem0 = Memory.from_config(build_mem0_config())
retrieved = mem0.search(user_message, user_id=user_id) #2
instructions = f"""
You are a helpful assistant. The following items are retrieved from
long-term memories from previous sessions. Use them when relevant,
but do not assume they are always correct.
MEMORIES: {format_memories(retrieved)} #3
"""
response = client.responses.create(
model="gpt-5",
instructions=instructions,
input=[ {"role": "user", "content": user_message} ],
)
assistant_reply = response.output_text
mem0.add( #4
messages=[
{"role": "user", "content": user_message},
{"role": "assistant", "content": assistant_reply},
],
user_id=user_id,
)
The Python excerpt shows user-scoped memory search and injection into model instructions. section 5.5.1
An alternative is to transform raw information into a searchable structure. Cognee chunks and embeds text, extracts entities and relations, and builds graph and vector representations for hybrid search. The minimal example leaves user identity, conflict resolution, and selective prompt injection to the surrounding architecture. section 5.5.2
Memory policies should control what is written, retrieved, consolidated, and expired. Selective retrieval limits irrelevant context and token use; ingestion also consumes tokens. Guard against stale, conflicting, or poisoned entries. For coding agents, retain durable project knowledge such as build commands and architecture decisions, rather than every session transcript; exclude secrets, personal data, temporary errors, and unverified guesses. section 5.5.1 section 5.6 section 11.3.5

























