AI Hints
Home›LangGraph Tutorial›Long-Term Memory
LangGraph · Lesson 74 of 120

Long-Term Memory

The store.

⏱ 2 min read▶ Video at 1:19:23🎓 Free
Watch this lesson in the LangGraph courseWatch on YouTube ↗Full LangGraph course

A checkpointer remembers one conversation. But a returning customer starts a new conversation, on a new thread. To remember them across conversations, like their favourite genre, we need long term memory. LangGraph calls it the store.

Long-Term Memory
From the video: Long-Term Memory
  • Checkpointer: one thread
  • New chat, new thread
  • The store: across threads

The in memory store saves items. Put takes a namespace, a key, and a dictionary value. Get fetches one item by key. Search lists every item in a namespace. Run it. We read back Sam's favourite genre, and see both saved keys.

store.pypython
from langgraph.store.memory import InMemoryStore

store = InMemoryStore()
store.put(("customers", "sam"), "genre", {"value": "science fiction"})
store.put(("customers", "sam"), "format", {"value": "paperback"})

item = store.get(("customers", "sam"), "genre")
print("genre:", item.value["value"])
print("all keys:", [i.key for i in store.search(("customers", "sam"))])
Output
genre: science fiction
all keys: ['genre', 'format']

Checkpointer vs store

So we have two kinds of memory. The checkpointer saves the state of one thread, the conversation. The store saves facts that outlive any one conversation, shared across all threads, like a customer profile.

Checkpointer

  • One threadThe conversationShort-term

Store

  • Across threadsFacts and profilesLong-term

Summary

The store keeps long term memories, shared across threads. Put, get, and search work with namespaces and keys. Next, organising memories with namespaces.

Key takeaways
  • store.put(ns, key, value)
  • store.get
  • store.search(ns)
Next up: Namespaces — organising memories