Updates and deletes
Updates and deletes are the two ways a LangMem memory manager changes memories it already has: PatchDoc rewrites a memory in place and keeps its id, and RemoveDoc marks one for deletion.
Last updated: 30 Sep, 2026 · LangMem 0.0.30
Facts change. Asha asked for email, then decides she prefers text messages. A collection that only adds would now hold both preferences, and the assistant would not know which is current. Passing existing gives the model a PatchDoc tool, as The extraction request showed, and enable_deletes=True adds a RemoveDoc tool.
Syntax:
create_memory_manager(model, enable_updates=True) # the default: PatchDoc is available
create_memory_manager(model, enable_deletes=True) # adds RemoveDoc; off by defaultThe memory to change
The update needs a memory to start from. The first call extracts it, the same as in Collections.
first = manager.invoke({"messages": [
{"role": "user", "content": "Hi, I'm Asha. Order A-1001 arrived broken. Please email me."},
]})
existing = [(memory.id, memory.content) for memory in first]A message that changes a fact
update = manager.invoke({
"messages": [{"role": "user", "content": "Please text me instead of email."}],
"existing": existing,
})Updating a contact preference
from langchain.chat_models import init_chat_model
from langmem import create_memory_manager
model = init_chat_model("groq:openai/gpt-oss-120b", temperature=0)
manager = create_memory_manager(
model,
instructions="Extract what helps support this customer. Record everything in a single Memory call.",
)
first = manager.invoke({"messages": [
{"role": "user", "content": "Hi, I'm Asha. Order A-1001 arrived broken. Please email me."},
]})
existing = [(memory.id, memory.content) for memory in first]
print("before:", first[0].content.content)
update = manager.invoke({
"messages": [{"role": "user", "content": "Please text me instead of email."}],
"existing": existing,
})
for memory in update:
status = "same id" if memory.id in dict(existing) else "new id"
print(f"after: {memory.content.content} ({status})")before: Customer Asha reported that order A-1001 arrived broken and requested to be contacted via email. The support action required is to send an email apology, acknowledge the broken item, and arrange a replacement or refund as per company policy. after: Customer Asha reported that order A-1001 arrived broken and requested to be contacted via text. The support action required is to send a text apology, acknowledge the broken item, and arrange a replacement or refund as per company policy. (same id)
How the update landed
- same id. The model called
PatchDocon the existing memory, so the text changed and the id stayed. Code that stored the memory by id replaces it in place. - Both mentions of email became text, including a sentence Asha never said: "The support action required is to send an email apology..." is the model's own plan, added in the first extraction and carried into the update.
- The result is the whole collection after the change. With one memory, that is the one patched memory.
Deleting memories on request
With enable_deletes=True, a memory the model decides to drop comes back as a RemoveDoc with the id to delete. Removing it from wherever you keep memories is up to your code; the store manager in Store managers does it for you.
from langchain.chat_models import init_chat_model
from langmem import create_memory_manager
model = init_chat_model("groq:openai/gpt-oss-120b", temperature=0)
manager = create_memory_manager(
model,
instructions="Extract what helps support this customer. Record everything in a single Memory call.",
enable_deletes=True,
)
first = manager.invoke({"messages": [
{"role": "user", "content": "Hi, I'm Asha. Order A-1001 arrived broken. Please email me."},
]})
existing = [(memory.id, memory.content) for memory in first]
result = manager.invoke({
"messages": [{"role": "user", "content": "Please delete everything you saved about me."}],
"existing": existing,
})
for memory in result:
print(type(memory.content).__name__, "|", memory.content)RemoveDoc | json_doc_id='1c61a8e5-8a25-4a09-8ea9-a30d0fc7813a'
One RemoveDoc came back, naming the id of the only memory, and no Memory was left: the model deleted everything, as asked. Deleting that id from your own list or database is your code's job.
PatchDoc vs RemoveDoc
| PatchDoc | RemoveDoc | |
|---|---|---|
| Turned on by | Passing existing memories (enable_updates is on by default) | enable_deletes=True |
| Returned as | The same id with new content | A RemoveDoc naming the id |
| Your code | Replaces the memory with that id | Deletes the memory with that id |
When updates and deletes matter
- Contact preferences, addresses and plans, which change and must not pile up.
- Privacy requests, where a customer asks the assistant to forget them.
- Facts the customer corrects ("it was A-1002, not A-1001").
enable_updates=False so the manager only adds.Related
- Previous: Collections
- Next: Profiles
- Reference: create_memory_manager reference
- Send "My name is Priya, not Asha" with the existing memory and read what changed.
- Create the manager with
enable_updates=Falseand send the text-me message again. - Keep memories in a dictionary by id and delete the ids that come back as
RemoveDoc.
Little by little, you're building something great.