mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-08-20 14:42:28 +02:00
- Instead store sends in a Topic channel, removing the need to fetch sends as writes against the parent checkpoint - Remove deprecated/unused functions in langgraph-checkpoint (will require bumping min range for langgraph-checkpoint in langgraph lib) - Implement migration of old pending sends in langgraph-checkpoint-postgres - Ensure parent config of `checkpoint_during=False` checkpoints always points to checkpoints that were also saved
89 lines
2.1 KiB
Markdown
89 lines
2.1 KiB
Markdown
# LangGraph SQLite Checkpoint
|
|
|
|
Implementation of LangGraph CheckpointSaver that uses SQLite DB (both sync and async, via `aiosqlite`)
|
|
|
|
## Usage
|
|
|
|
```python
|
|
from langgraph.checkpoint.sqlite import SqliteSaver
|
|
|
|
write_config = {"configurable": {"thread_id": "1", "checkpoint_ns": ""}}
|
|
read_config = {"configurable": {"thread_id": "1"}}
|
|
|
|
with SqliteSaver.from_conn_string(":memory:") as checkpointer:
|
|
checkpoint = {
|
|
"v": 4,
|
|
"ts": "2024-07-31T20:14:19.804150+00:00",
|
|
"id": "1ef4f797-8335-6428-8001-8a1503f9b875",
|
|
"channel_values": {
|
|
"my_key": "meow",
|
|
"node": "node"
|
|
},
|
|
"channel_versions": {
|
|
"__start__": 2,
|
|
"my_key": 3,
|
|
"start:node": 3,
|
|
"node": 3
|
|
},
|
|
"versions_seen": {
|
|
"__input__": {},
|
|
"__start__": {
|
|
"__start__": 1
|
|
},
|
|
"node": {
|
|
"start:node": 2
|
|
}
|
|
},
|
|
}
|
|
|
|
# store checkpoint
|
|
checkpointer.put(write_config, checkpoint, {}, {})
|
|
|
|
# load checkpoint
|
|
checkpointer.get(read_config)
|
|
|
|
# list checkpoints
|
|
list(checkpointer.list(read_config))
|
|
```
|
|
|
|
### Async
|
|
|
|
```python
|
|
from langgraph.checkpoint.sqlite.aio import AsyncSqliteSaver
|
|
|
|
async with AsyncSqliteSaver.from_conn_string(":memory:") as checkpointer:
|
|
checkpoint = {
|
|
"v": 4,
|
|
"ts": "2024-07-31T20:14:19.804150+00:00",
|
|
"id": "1ef4f797-8335-6428-8001-8a1503f9b875",
|
|
"channel_values": {
|
|
"my_key": "meow",
|
|
"node": "node"
|
|
},
|
|
"channel_versions": {
|
|
"__start__": 2,
|
|
"my_key": 3,
|
|
"start:node": 3,
|
|
"node": 3
|
|
},
|
|
"versions_seen": {
|
|
"__input__": {},
|
|
"__start__": {
|
|
"__start__": 1
|
|
},
|
|
"node": {
|
|
"start:node": 2
|
|
}
|
|
},
|
|
}
|
|
|
|
# store checkpoint
|
|
await checkpointer.aput(write_config, checkpoint, {}, {})
|
|
|
|
# load checkpoint
|
|
await checkpointer.aget(read_config)
|
|
|
|
# list checkpoints
|
|
[c async for c in checkpointer.alist(read_config)]
|
|
```
|