Skip to main content

LangGraph checkpointer using LMDB

Project description

LangGraph LMDB Checkpointer

A high-performance, local checkpoint saver for LangGraph using LMDB (Lightning Memory-Mapped Database).

🚀 Why LMDB?

LMDB is a transactional, memory-mapped key-value store. It is incredibly fast because it uses the operating system's memory-map (mmap) to provide zero-copy reads and highly efficient writes. For LangGraph, where state persistence can become a bottleneck during complex agentic loops, LMDB offers a near-memory speed with full persistence.

🏢 When to Use?

  • High-Performance Local Agents: When running agents on a single machine or edge device where network latency to a database (like Postgres) is unacceptable.
  • Embedded Applications: Desktop or mobile apps that need a self-contained, lightweight, and zero-configuration database.
  • Development & Prototyping: Fast startup and easy portability of checkpoints during the R&D phase.

🏆 Where it Excels

  • Read Latency: Since it maps the database file directly into memory, reading a checkpoint is essentially a memory access.
  • Reliability (ACID): Fully ACID compliant with a crash-proof design. If the power fails, your checkpoints stay consistent.
  • Multi-Process/Multi-Thread: Highly concurrent reads without blocking, making it perfect for multi-agent workflows.

Features

  • Blazing Fast Local Storage: Optimized for high-frequency writes and low-latency state retrieval.
  • Binary Key Strategy: Uses a compact binary key layout (thread_id\x00checkpoint_ns\x00checkpoint_id) for efficient multi-index prefix scanning.
  • Flexible Serialization: Supports both msgpack (default) and orjson for high-speed state encoding.
  • Async & Sync Support: Provides both thread-safe synchronous (LMDBSaver) and non-blocking asynchronous (AsyncLMDBSaver) implementations.

Installation

pip install langgraph-checkpoint-lmdb

Quick Start

import lmdb
from langgraph_checkpoint_lmdb import LMDBSaver
from langgraph.graph import StateGraph

# Initialize LMDB environment
env = lmdb.open("./checkpoints", max_dbs=10)
saver = LMDBSaver(env)

# Use in your LangGraph as a checkpointer
graph = builder.compile(checkpointer=saver)

Real-World Examples

  • Customer Support Bot: See examples/customer_support.py for a complete implementation of a multi-turn support agent with state persistence.
  • Interactive Chatbot: See examples/chatbot.py for a simple interactive CLI chatbot that remembers your name across sessions.

Performance

Benchmarks conducted on local hardware comparing LMDBSaver with the default MemorySaver.

Scenario MemorySaver LMDBSaver 🏆 Winner
Sequential Writes (1K) 30,914 ops/s 19,619 ops/s MemorySaver
Concurrent Writes (15T×200) 33,947 ops/s 8,523 ops/s MemorySaver
History Query (list 100) 52,672 ops/s 45,319 ops/s MemorySaver

[!TIP] LMDBSaver handles persistent storage while maintaining performance within the same magnitude as in-memory storage, making it ideal for edge devices and high-load local agents.

Development

Run Tests

pytest

Run Benchmarks

python benchmark.py

License

MIT License. See LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langgraph_checkpoint_lmdb-0.3.1.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langgraph_checkpoint_lmdb-0.3.1-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file langgraph_checkpoint_lmdb-0.3.1.tar.gz.

File metadata

File hashes

Hashes for langgraph_checkpoint_lmdb-0.3.1.tar.gz
Algorithm Hash digest
SHA256 ac4062e80f9823b6152d7615ad4ac02defe49b38ba21156b8d019b250f751daf
MD5 7705a50d16b2168b23d8bb48257dd726
BLAKE2b-256 c1a6cec81b519134eb296a0c38b00376d2d5f3fa6e2603a55bae991b73e17b9e

See more details on using hashes here.

File details

Details for the file langgraph_checkpoint_lmdb-0.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for langgraph_checkpoint_lmdb-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 700fd7586b7f676e7dd84a9bb6a3dcbcc04941bf81c74d5d1a4f54eeafd9b63d
MD5 7d255417ee8d0b71b247980a4e24aaef
BLAKE2b-256 8bad48a4a7767d8e15c7d7e3a95a536f3b318724764ec879d8fe8fd36eacf250

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page