@langchain/langgraph-checkpoint-redis 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,189 @@
1
+ # @langchain/langgraph-checkpoint-redis
2
+
3
+ Redis checkpoint and store implementation for LangGraph.
4
+
5
+ ## Overview
6
+
7
+ This package provides Redis-based implementations for:
8
+
9
+ 1. **Checkpoint Savers**: Store and manage LangGraph checkpoints using Redis
10
+ - **RedisSaver**: Standard checkpoint saver that maintains full checkpoint history
11
+ - **ShallowRedisSaver**: Memory-optimized saver that only keeps the latest checkpoint per thread
12
+ 2. **RedisStore**: Redis-backed key-value store with optional vector search capabilities
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install @langchain/langgraph-checkpoint-redis
18
+ ```
19
+
20
+ ## Dependencies
21
+
22
+ ### Redis Requirements
23
+
24
+ This library requires Redis with the following modules:
25
+
26
+ - **RedisJSON** - For storing and manipulating JSON data
27
+ - **RediSearch** - For search and indexing capabilities
28
+
29
+ #### Redis 8.0+
30
+
31
+ If you're using Redis 8.0 or higher, both RedisJSON and RediSearch modules are included by default.
32
+
33
+ #### Redis < 8.0
34
+
35
+ For Redis versions lower than 8.0, you'll need to:
36
+
37
+ - Use [Redis Stack](https://redis.io/docs/stack/), which bundles Redis with these modules
38
+ - Or install the modules separately in your Redis instance
39
+
40
+ ## Usage
41
+
42
+ ### Standard Checkpoint Saver
43
+
44
+ ```typescript
45
+ import { RedisSaver } from "@langchain/langgraph-checkpoint-redis";
46
+
47
+ const checkpointer = await RedisSaver.fromUrl(
48
+ "redis://localhost:6379",
49
+ {
50
+ defaultTTL: 60, // TTL in minutes
51
+ refreshOnRead: true
52
+ }
53
+ );
54
+
55
+ // Indices are automatically created by fromUrl()
56
+
57
+ // Use with your graph
58
+ const config = {configurable: {thread_id: "1"}};
59
+
60
+ // Metadata must include required fields
61
+ const metadata = {
62
+ source: "update", // "update" | "input" | "loop" | "fork"
63
+ step: 0,
64
+ parents: {}
65
+ };
66
+
67
+ await checkpointer.put(config, checkpoint, metadata, {});
68
+ const loaded = await checkpointer.get(config);
69
+ ```
70
+
71
+ ### Shallow Checkpoint Saver
72
+
73
+ The `ShallowRedisSaver` is a memory-optimized variant that only keeps the latest checkpoint per thread:
74
+
75
+ ```typescript
76
+ import { ShallowRedisSaver } from "@langchain/langgraph-checkpoint-redis/shallow";
77
+
78
+ // Create a shallow saver that only keeps the latest checkpoint
79
+ const shallowSaver = await ShallowRedisSaver.fromUrl("redis://localhost:6379");
80
+
81
+ // Use it the same way as RedisSaver
82
+ const config = {
83
+ configurable: {
84
+ thread_id: "my-thread",
85
+ checkpoint_ns: "my-namespace"
86
+ }
87
+ };
88
+
89
+ const metadata = {
90
+ source: "update",
91
+ step: 0,
92
+ parents: {}
93
+ };
94
+
95
+ await shallowSaver.put(config, checkpoint, metadata, versions);
96
+
97
+ // Only the latest checkpoint is kept - older ones are automatically cleaned up
98
+ const latest = await shallowSaver.getTuple(config);
99
+ ```
100
+
101
+ Key differences from RedisSaver:
102
+
103
+ - **Storage**: Only keeps the latest checkpoint per thread (no history)
104
+ - **Performance**: Reduced storage usage and faster operations
105
+ - **Inline storage**: Channel values are stored inline (no separate blob storage)
106
+ - **Automatic cleanup**: Old checkpoints and writes are automatically removed
107
+
108
+ ### RedisStore
109
+
110
+ The `RedisStore` provides a key-value store with optional vector search capabilities:
111
+
112
+ ```typescript
113
+ import { RedisStore } from "@langchain/langgraph-checkpoint-redis/store";
114
+
115
+ // Basic key-value store
116
+ const store = await RedisStore.fromConnString("redis://localhost:6379");
117
+
118
+ // Store with vector search
119
+ const vectorStore = await RedisStore.fromConnString("redis://localhost:6379", {
120
+ index: {
121
+ dims: 1536, // Embedding dimensions
122
+ embed: embeddings, // Your embeddings instance
123
+ distanceType: "cosine", // or "l2", "ip"
124
+ fields: ["text"], // Fields to embed
125
+ },
126
+ ttl: {
127
+ defaultTTL: 60, // TTL in minutes
128
+ refreshOnRead: true,
129
+ }
130
+ });
131
+
132
+ // Put and get items
133
+ await store.put(["namespace", "nested"], "key1", {text: "Hello world"});
134
+ const item = await store.get(["namespace", "nested"], "key1");
135
+
136
+ // Search with namespace filtering
137
+ const results = await store.search(["namespace"], {
138
+ filter: {category: "docs"},
139
+ limit: 10,
140
+ });
141
+
142
+ // Vector search
143
+ const semanticResults = await vectorStore.search(["namespace"], {
144
+ query: "semantic search query",
145
+ filter: {type: "article"},
146
+ limit: 5,
147
+ });
148
+
149
+ // Batch operations
150
+ const ops = [
151
+ {type: "get", namespace: ["ns"], key: "key1"},
152
+ {type: "put", namespace: ["ns"], key: "key2", value: {data: "value"}},
153
+ {type: "search", namespacePrefix: ["ns"], limit: 10},
154
+ {type: "list_namespaces", matchConditions: [{matchType: "prefix", path: ["ns"]}], limit: 10},
155
+ ];
156
+ const results = await store.batch(ops);
157
+ ```
158
+
159
+ ## TTL Support
160
+
161
+ Both checkpoint savers and stores support Time-To-Live (TTL) functionality:
162
+
163
+ ```typescript
164
+ const ttlConfig = {
165
+ defaultTTL: 60, // Default TTL in minutes
166
+ refreshOnRead: true, // Refresh TTL when items are read
167
+ };
168
+
169
+ const checkpointer = await RedisSaver.fromUrl("redis://localhost:6379", ttlConfig);
170
+ ```
171
+
172
+ ## Development
173
+
174
+ ### Running Tests
175
+
176
+ ```bash
177
+ # Run tests (uses TestContainers)
178
+ yarn test
179
+
180
+ # Run tests in watch mode
181
+ yarn test:watch
182
+
183
+ # Run integration tests
184
+ yarn test:int
185
+ ```
186
+
187
+ ## License
188
+
189
+ MIT