fleet-memory/memora-docs/docs/sdks/langgraph.md
2025-11-24 14:54:57 +01:00

2.5 KiB

sidebar_position
3

LangGraph

Memora provides a BaseStore implementation for LangGraph's memory system.

Installation

cd memora-langmem && uv pip install -e .

Quick Start

from memora_langmem import MemoraStore

# Create store
store = MemoraStore(
    base_url="http://localhost:8080",
    default_agent_id="my-agent",
)

# Store data
store.put(
    namespace=("user", "preferences"),
    key="language",
    value={"language": "Python", "reason": "data science"}
)

# Retrieve data
item = store.get(namespace=("user", "preferences"), key="language")
print(item.value)  # {"language": "Python", "reason": "data science"}

# Search
results = store.search(
    namespace_prefix=("user",),
    query="programming language",
    limit=10
)

How It Works

MemoraStore implements LangGraph's BaseStore interface:

  • Namespaces map to Memora agent IDs (joined with __)
  • Keys map to document IDs
  • Values are stored as JSON in memory content

BaseStore Interface

put

Store an item:

store.put(
    namespace=("user", "session-123"),
    key="preferences",
    value={"theme": "dark", "language": "en"}
)

get

Retrieve an item:

item = store.get(namespace=("user", "session-123"), key="preferences")
if item:
    print(item.value)  # {"theme": "dark", "language": "en"}
    print(item.created_at)
    print(item.updated_at)

Search within a namespace:

results = store.search(
    namespace_prefix=("user",),
    query="theme preferences",
    limit=10,
    offset=0
)

for item in results:
    print(f"{item.key}: {item.value}")

delete

Delete an item:

store.delete(namespace=("user", "session-123"), key="preferences")

Async Support

All operations have async variants:

await store.aput(namespace, key, value)
item = await store.aget(namespace, key)
results = await store.asearch(namespace_prefix, query)
await store.adelete(namespace, key)

With LangGraph

from langgraph.graph import StateGraph
from memora_langmem import MemoraStore

store = MemoraStore(base_url="http://localhost:8080")

# Use store in your graph
graph = StateGraph()
# ... configure graph with store

Namespace Mapping

Namespaces are converted to Memora agent IDs:

Namespace Agent ID
("user",) user
("user", "session") user__session
("app", "v1", "data") app__v1__data
() default_agent_id

Agents are created automatically if they don't exist.