An asynchronous checkpoint saver that stores checkpoints in a SQLite database.
This class provides an asynchronous interface for saving and retrieving checkpoints using a SQLite database. It's designed for use in asynchronous environments and offers better performance for I/O-bound operations compared to synchronous alternatives.
AsyncSqliteSaver(
self,
conn: aiosqlite.Connection,
*,
serde: SerializerProtocol | None = None
)BaseCheckpointSaver[str]Tip:
Requires the aiosqlite package.
Install it with pip install aiosqlite.
Warning:
While this class supports asynchronous checkpointing, it is not recommended for production workloads due to limitations in SQLite's write performance. For production use, consider a more robust database like PostgreSQL.
Tip:
Remember to close the database connection after executing your code, otherwise, you may see the graph "hang" after execution (since the program will not exit until the connection is closed).
The easiest way is to use the async with statement as shown in the examples.
async with AsyncSqliteSaver.from_conn_string("checkpoints.sqlite") as saver:
# Your code here
graph = builder.compile(checkpointer=saver)
config = {"configurable": {"thread_id": "thread-1"}}
async for event in graph.astream_events(..., config, version="v1"):
print(event)| Name | Type |
|---|---|
| conn | aiosqlite.Connection |
| serde | SerializerProtocol | None |
Create a new AsyncSqliteSaver instance from a connection string.
Get a checkpoint tuple from the database.
This method retrieves a checkpoint tuple from the SQLite database based on the
provided config. If the config contains a checkpoint_id key, the checkpoint with
the matching thread ID and checkpoint ID is retrieved. Otherwise, the latest checkpoint
for the given thread ID is retrieved.
List checkpoints from the database asynchronously.
This method retrieves a list of checkpoint tuples from the SQLite database based on the provided config. The checkpoints are ordered by checkpoint ID in descending order (newest first).
Save a checkpoint to the database.
This method saves a checkpoint to the SQLite database. The checkpoint is associated with the provided config and its parent config (if any).
Delete all checkpoints and writes associated with a thread ID.
Set up the checkpoint database asynchronously.
This method creates the necessary tables in the SQLite database if they don't already exist. It is called automatically when needed and should not be called directly by the user.
Get a checkpoint tuple from the database asynchronously.
This method retrieves a checkpoint tuple from the SQLite database based on the
provided config. If the config contains a checkpoint_id key, the checkpoint with
the matching thread ID and checkpoint ID is retrieved. Otherwise, the latest checkpoint
for the given thread ID is retrieved.
List checkpoints from the database asynchronously.
This method retrieves a list of checkpoint tuples from the SQLite database based on the provided config. The checkpoints are ordered by checkpoint ID in descending order (newest first).
Save a checkpoint to the database asynchronously.
This method saves a checkpoint to the SQLite database. The checkpoint is associated with the provided config and its parent config (if any).
Store intermediate writes linked to a checkpoint asynchronously.
This method saves intermediate writes associated with a checkpoint to the database.
Delete all checkpoints and writes associated with a thread ID.
Generate the next version ID for a channel.
This method creates a new version identifier for a channel based on its current version.