Agent Memory EXPLAINED - Complete Architecture
Video by Hugging Face on YouTube · 29 min · uploaded August 2026
Notes and analysis by BrainTube, written from the video. Not affiliated with Hugging Face. Watch on YouTube
In short
The video explains long-term agent memory by dissecting Mem0: three stores (a memory vector store, an entity vector store and SQLite), an LLM extraction step after each turn, and a retrieval score that blends vector similarity, BM25 keyword overlap and an entity boost. The walkthrough of retrieval scoring is clear and unusually concrete. It is thinner on what makes memory hard in practice: updating and deleting facts, which it promises at the start and never covers.
The argument
LLMs are stateless, and the conversation history a harness resends each turn only lasts one session. Long-term memory is a separate, persistent service that sits outside the session store, ingests facts from every conversation and is queried on each turn, either automatically or through a search tool. Because it lives outside any one agent, the same user-centred memory can serve several agents. The video uses Mem0 as the worked example and argues the whole pipeline is simple enough to rebuild yourself with small local models: a 1B to 12B model for extraction and an open embedding model for search.
Key ideas, with timestamps
- 1:02
Conversational memory is not long-term memory
The harness keeps the message history and resends it with every prompt, which is why an agent remembers what you said earlier in a thread. Start a new thread and that history is gone. Long-term memory is a second service that stores facts across all conversations and is consulted on every turn.
- 3:38
Keep memory outside the session
The memory store must persist independently of session files. A side effect he points out: if memory is centred on the user, the same store can be shared by different agents, such as ChatGPT, Claude or Pi, so your tastes and current projects follow you between tools.
- 4:43
Three stores
The main vector store holds each memory sentence with metadata: created and updated dates, whether it is about the user or the agent, a hash for deduplication, a lemmatised copy for keyword search, an expiry date and which agent wrote it. An entity store holds extracted names and places, each linked to memories. A SQLite database logs every change and keeps the last 10 messages.
- 8:56
Three ways to ingest
Procedural mode summarises the steps an agent took so it can repeat them, which he thinks is now better served by turning a transcript into a skill. With infer set to false, raw messages are embedded and stored as is. With infer set to true, an LLM extracts memories, and that is the mode the video follows.
- 11:03
What the extraction prompt sees
The extractor gets a memory-extractor role, a user summary, the new messages, recent memories, relevant existing memories found by embedding the flattened messages, the last 10 messages from SQLite and the conversation and current dates. The last 10 messages exist mainly to resolve pronouns such as "it is great". It returns structured JSON memories.
- 14:11
Deduplication is exact-match only
New memories are hashed and checked against the store, which only catches identical wording. He says plainly that this is not the most useful deduplication. As he understands it, Mem0 runs extraction with GPT-5 mini by default, but a small open model can do it.
- 18:23
Over-fetch, then rerank
Retrieval embeds the query with the same model used at ingestion and runs an approximate nearest neighbour search. It does not fetch just top k: it fetches the larger of 4 times k or 60 candidates, so a top k of 10 pulls 60. Only those candidates can be reranked; later steps never add new ones.
- 21:01
The combined score
Each candidate gets a vector score from 0 to 1, a BM25 keyword score from 0 to 1 on the lemmatised text, and an entity boost that is higher when the matched entity links to few memories. The sum is divided by 2.5 and the top k are returned. At 25:15 he recommends adding query rewriting in the harness, which Mem0 does not do by default as far as he knows.
What it gets right
Most explainers of agent memory stop at "store facts in a vector database". This one shows the actual mechanics, and they are worth knowing. Over-fetching candidates before reranking is standard retrieval practice, and the detail that reranking can only reorder the initial pool explains a whole class of misses: if vector search never surfaces a memory, no keyword or entity boost will rescue it.
The entity boost is a nice idea, explained well. Weighting an entity match by how rare the entity is (two memories about Paris count for more than a thousand) is an inverse-frequency trick, the same intuition behind IDF in keyword search.
The local-model advice is sensible. Extraction is a narrow structured task, and a model in the 1B to 12B range (he suggests something like an 8B Qwen) is a reasonable starting point. Picking embedding models from a public leaderboard, filtered by domain, is also the right habit.
What it leaves out
- Updates and deletes. At 0:32 he promises to show what Mem0 does when it deletes one memory. That section never comes. It matters most: a memory store that only adds, with exact-hash dedup, will collect "user lives in Berlin" and "user moved to Lisbon" side by side. Earlier Mem0 write-ups described an LLM step that chooses to add, update or delete; the version shown here does not include one, so check your version.
- A numbers slip. He first says the entity boost runs from 0 to 5, then uses 0 to 0.5 when adding up the 2.5 maximum. The 0.5 figure is the one consistent with his formula.
- Evaluation. There is no measure of whether retrieval returns the right memories. Without a small test set of questions and expected memories, tuning top k, thresholds or rewriting is guesswork.
- What gets lost in extraction. Turning conversations into short sentences throws away the source. You can no longer check where a fact came from or what context it had. For personal preferences that is fine; for anything you need to cite or verify, keep the original.
- Privacy. A store of extracted facts about a user, shared across agents, needs access control and a way for the user to see and remove entries. The video does not discuss it.
How this applies to memory across AI tools
The video's best point for everyday users is at 3:38: memory that lives outside any one app can be shared by all of them. That is the idea behind a persistent memory layer that works across tools. The design choice that follows is what you store. Mem0's approach stores short extracted facts, which suits preferences. For things you learned from videos, articles and papers, storing the full source and searching it is safer, because you can always go back to what was actually said.
BrainTube is built on the second approach: it saves YouTube videos with their transcripts, articles, PDFs and podcasts into one compiled knowledge base and exposes it as an MCP server, so Claude, ChatGPT, Cursor and other MCP clients can search it. For a direct comparison of the two approaches, see our Mem0 comparison.
Who should watch it
Watch it if you are building an agent and want to understand, or copy, how a popular memory library ranks memories. The first three minutes cover basics most developers know; skip to 4:12 for the stores, 10:31 for the extraction prompt and 18:23 to 24:43 for retrieval and scoring, which is the most valuable stretch. The last few minutes, from 25:45, are a quick tour of picking local models on Hugging Face. Skip it if you want a comparison of memory tools, a coding tutorial or guidance on updating and forgetting memories, since none of those are covered.
Frequently asked
- How does Mem0 store memories?
- According to the video, Mem0 uses a vector store for memory sentences and their metadata, a second vector store for extracted entities linked to those memories, and a SQLite database that logs changes and keeps the last 10 messages. Metadata includes dates, a hash, a lemmatised copy and whether the memory is about the user or the agent.
- How does Mem0 rank memories during retrieval?
- It fetches a larger pool of candidates by vector search (at least 60), then adds a BM25 keyword score and an entity boost to each candidate's vector score. The total is normalised by dividing by 2.5, and the top k are returned. Memories outside the initial pool are never added.
- What is the difference between conversational memory and long-term memory for agents?
- Conversational memory is the message history the agent harness resends to the model each turn, and it ends with the session. Long-term memory is a separate persistent store of facts gathered from many conversations and queried on each turn. It can also be shared by several agents.
Keep videos like this one searchable
BrainTube saves YouTube videos with their transcripts into one compiled knowledge base that Claude, ChatGPT, Cursor and other MCP clients can search.
Go deeper
More video notes
- AI Agent Memory Architecture: Structured SQL, Semantic Vector Search & Memory Bank · Google Cloud Tech
- Skills vs MCP vs RAG vs Memory: What AI Agents Need to Know · IBM Technology
- Improved AI Memory? 🧠 Full Hermes Tutorial (Mnemosyne & Hindsight) · Wanderloots
- You Can Learn AI Agent Memory System In 12 Min | Semantic & Episodic Memory, RAG, Vector Database · Sean‘s AI Stories
Are you the creator and want this page changed or removed? Contact us and we will act within 48 hours.