Save a checkpoint to the database.
This method saves a checkpoint to the Postgres database. The checkpoint is associated with the provided config and its parent config (if any).
put(
self,
config: RunnableConfig,
checkpoint: Checkpoint,
metadata: CheckpointMetadata,
new_versions: ChannelVersions
) -> RunnableConfigExamples:
from langgraph.checkpoint.postgres import PostgresSaver DB_URI = "postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable" with PostgresSaver.from_conn_string(DB_URI) as memory: config = {"configurable": {"thread_id": "1", "checkpoint_ns": ""}} checkpoint = {"ts": "2024-05-04T06:32:42.235444+00:00", "id": "1ef4f797-8335-6428-8001-8a1503f9b875", "channel_values": {"key": "value"}} saved_config = memory.put(config, checkpoint, {"source": "input", "step": 1, "writes": {"key": "value"}}, {}) print(saved_config) {'configurable': {'thread_id': '1', 'checkpoint_ns': '', 'checkpoint_id': '1ef4f797-8335-6428-8001-8a1503f9b875'}}
| Name | Type | Description |
|---|---|---|
config* | RunnableConfig | The config to associate with the checkpoint. |
checkpoint* | Checkpoint | The checkpoint to save. |
metadata* | CheckpointMetadata | Additional metadata to save with the checkpoint. |
new_versions* | ChannelVersions | New channel versions as of this write. |