Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checkpoint postgres: allow passing custom serde #1699

Merged
merged 6 commits into from
Sep 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions libs/checkpoint-postgres/langgraph/checkpoint/postgres/aio.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import asyncio

Check notice on line 1 in libs/checkpoint-postgres/langgraph/checkpoint/postgres/aio.py

View workflow job for this annotation

GitHub Actions / benchmark

Benchmark results

......................................... fanout_to_subgraph_10x: Mean +- std dev: 60.2 ms +- 1.9 ms ......................................... fanout_to_subgraph_10x_checkpoint: Mean +- std dev: 108 ms +- 10 ms ......................................... fanout_to_subgraph_100x: Mean +- std dev: 601 ms +- 28 ms ......................................... fanout_to_subgraph_100x_checkpoint: Mean +- std dev: 1.05 sec +- 0.04 sec ......................................... react_agent_10x: Mean +- std dev: 43.7 ms +- 0.7 ms ......................................... react_agent_10x_checkpoint: Mean +- std dev: 80.5 ms +- 0.7 ms ......................................... react_agent_100x: Mean +- std dev: 779 ms +- 6 ms ......................................... react_agent_100x_checkpoint: Mean +- std dev: 2.80 sec +- 0.09 sec ......................................... wide_state_25x300: Mean +- std dev: 21.3 ms +- 0.3 ms ......................................... wide_state_25x300_checkpoint: Mean +- std dev: 657 ms +- 6 ms ......................................... wide_state_15x600: Mean +- std dev: 24.8 ms +- 0.4 ms ......................................... wide_state_15x600_checkpoint: Mean +- std dev: 1.20 sec +- 0.01 sec ......................................... wide_state_9x1200: Mean +- std dev: 24.8 ms +- 0.3 ms ......................................... wide_state_9x1200_checkpoint: Mean +- std dev: 754 ms +- 7 ms

Check notice on line 1 in libs/checkpoint-postgres/langgraph/checkpoint/postgres/aio.py

View workflow job for this annotation

GitHub Actions / benchmark

Comparison against main

+------------------------------------+----------+------------------------+ | Benchmark | main | changes | +====================================+==========+========================+ | fanout_to_subgraph_100x_checkpoint | 1.15 sec | 1.05 sec: 1.10x faster | +------------------------------------+----------+------------------------+ | fanout_to_subgraph_100x | 636 ms | 601 ms: 1.06x faster | +------------------------------------+----------+------------------------+ | fanout_to_subgraph_10x | 61.4 ms | 60.2 ms: 1.02x faster | +------------------------------------+----------+------------------------+ | Geometric mean | (ref) | 1.04x faster | +------------------------------------+----------+------------------------+ Benchmark hidden because not significant (1): fanout_to_subgraph_10x_checkpoint Ignored benchmarks (10) of out/changes.json: react_agent_100x, react_agent_100x_checkpoint, react_agent_10x, react_agent_10x_checkpoint, wide_state_15x600, wide_state_15x600_checkpoint, wide_state_25x300, wide_state_25x300_checkpoint, wide_state_9x1200, wide_state_9x1200_checkpoint
from contextlib import asynccontextmanager
from typing import Any, AsyncIterator, Iterator, List, Optional, Union

Expand Down Expand Up @@ -57,7 +57,11 @@
@classmethod
@asynccontextmanager
async def from_conn_string(
cls, conn_string: str, *, pipeline: bool = False
cls,
conn_string: str,
*,
pipeline: bool = False,
serde: Optional[SerializerProtocol] = None,
) -> AsyncIterator["AsyncPostgresSaver"]:
"""Create a new PostgresSaver instance from a connection string.

Expand All @@ -73,9 +77,9 @@
) as conn:
if pipeline:
async with conn.pipeline() as pipe:
yield AsyncPostgresSaver(conn, pipe)
yield AsyncPostgresSaver(conn=conn, pipe=pipe, serde=serde)
else:
yield AsyncPostgresSaver(conn)
yield AsyncPostgresSaver(conn=conn, serde=serde)

async def setup(self) -> None:
"""Set up the checkpoint database asynchronously.
Expand Down
Loading