Added checkpoint-redis project with tests and code #1189
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Feat: Introduce Redis Checkpoint Saver
Type: New Feature
Summary
This pull request introduces a new checkpoint saver implementation using Redis, named
RedisSaver
. This saver provides a robust and efficient way to persist LangGraph checkpoints, leveraging several Redis best practices to ensure data integrity, performance, and scalability.Attribution
This implementation incorporates and adapts code from the levivoelz/checkpoint-redis project, which is licensed under the MIT License. The original code has been modified to align with LangGraph's architecture and to integrate additional features such as TTL support and enhanced indexing.
Motivation
For LangGraph applications requiring robust and scalable checkpoint management, a persistent and high-performance backend is essential. The
RedisSaver
is designed to meet these demands by leveraging Redis as its storage layer.This
RedisSaver
provides a dedicated solution for users seeking to integrate LangGraph's powerful checkpointing features with the proven capabilities of Redis.Detailed Description
The
RedisSaver
implementation adheres to common Redis best practices and offers the following key features:MULTI
/EXEC
transactions for critical operations like setting checkpoints and their associated index entries. This ensures that checkpoint data and its corresponding index are written atomically, preventing partial writes and maintaining data consistency.ZSET
) by their timestamp (ts
). This allows for efficient chronological listing and retrieval of checkpoints, including pagination capabilities (e.g., fetching checkpointsbefore
a certain ID, andlimit
ing the number of results).checkpoint:<threadId>:<checkpointNs>:<checkpointId>
,writes:<threadId>:<checkpointNs>:<checkpointId>:<taskId>:<idx>
,checkpoint_index:<threadId>:<checkpointNs>
,writes_index:<threadId>:<checkpointNs>:<checkpointId>
) is used for easy debugging and management of data within Redis.RedisSaver
is accompanied by a suite of unit tests (redis-saver.test.ts
) covering various scenarios, including:thread_id
or non-existent checkpoints.The implementation is organized into:
redis-saver.ts
: Contains the mainRedisSaver
class, implementing theBaseCheckpointSaver
interface.checkpoint-redis-repository.ts
: Encapsulates the direct Redis interactions, providing an abstraction layer for CRUD operations on checkpoints and writes. This promotes separation of concerns and makes the main saver logic cleaner.utils.ts
: Includes helper functions for Redis key generation, parsing, and data serialization/deserialization.How to Test
docker-compose.yml
in thelibs/checkpoint-redis
directory, which can be started withdocker-compose up
).libs/checkpoint-redis/src/tests/redis-saver.test.ts
can be run using the standard testing command for the workspace (e.g.,yarn test
oryarn test:single libs/checkpoint-redis/src/tests/redis-saver.test.ts
from within thelibs/checkpoint-redis
directory).RedisSaver
in a LangGraph application and configuring it as the checkpointer.Example Usage:
This contribution aims to provide a high-quality, production-grade checkpointing solution for LangGraph users who prefer or require Redis. I'm open to feedback and further improvements!