@@ -25,97 +25,6 @@ pip install -U langchain-postgres
2525
2626## Usage
2727
28- ### PostgresSaver (LangGraph Checkpointer)
29-
30- The LangGraph checkpointer can be used to add memory to your LangGraph application.
31-
32- ` PostgresSaver ` is an implementation of the checkpointer saver using
33- Postgres as the backend.
34-
35- Currently, only the psycopg3 driver is supported.
36-
37- Sync usage:
38-
39- ``` python
40- from psycopg_pool import ConnectionPool
41- from langchain_postgres import (
42- PostgresSaver, PickleCheckpointSerializer
43- )
44-
45- pool = ConnectionPool(
46- # Example configuration
47- conninfo = " postgresql://langchain:langchain@localhost:6024/langchain" ,
48- max_size = 20 ,
49- )
50-
51- PostgresSaver.create_tables(pool)
52-
53- checkpointer = PostgresSaver(
54- serializer = PickleCheckpointSerializer(),
55- sync_connection = pool,
56- )
57-
58- # Set up the langgraph workflow with the checkpointer
59- workflow = ... # Fill in with your workflow
60- app = workflow.compile(checkpointer = checkpointer)
61-
62- # Use with the sync methods of `app` (e.g., `app.stream())
63-
64- pool.close() # Remember to close the connection pool.
65- ```
66-
67- Async usage:
68-
69- ``` python
70- from psycopg_pool import AsyncConnectionPool
71- from langchain_postgres import (
72- PostgresSaver, PickleCheckpointSerializer
73- )
74-
75- pool = AsyncConnectionPool(
76- # Example configuration
77- conninfo = " postgresql://langchain:langchain@localhost:6024/langchain" ,
78- max_size = 20 ,
79- )
80-
81- # Create the tables in postgres (only needs to be done once)
82- await PostgresSaver.acreate_tables(pool)
83-
84- checkpointer = PostgresSaver(
85- serializer = PickleCheckpointSerializer(),
86- async_connection = pool,
87- )
88-
89- # Set up the langgraph workflow with the checkpointer
90- workflow = ... # Fill in with your workflow
91- app = workflow.compile(checkpointer = checkpointer)
92-
93- # Use with the async methods of `app` (e.g., `app.astream()`)
94-
95- await pool.close() # Remember to close the connection pool.
96- ```
97-
98- #### Testing
99-
100- If testing with the postgres checkpointer it may be useful to both create and
101- drop the tables before and after the tests.
102-
103- ``` python
104- from psycopg_pool import ConnectionPool
105- from langchain_postgres import (
106- PostgresSaver
107- )
108- with ConnectionPool(
109- # Example configuration
110- conninfo = " postgresql://langchain:langchain@localhost:6024/langchain" ,
111- max_size = 20 ,
112- ) as conn:
113- PostgresSaver.create_tables(conn)
114- PostgresSaver.drop_tables(conn)
115- # Run your unit tests with langgraph
116- ```
117-
118-
11928### ChatMessageHistory
12029
12130The chat message history abstraction helps to persist chat message history
0 commit comments