Skip to content
Merged
Show file tree
Hide file tree
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
91 changes: 0 additions & 91 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,97 +25,6 @@ pip install -U langchain-postgres

## Usage

### PostgresSaver (LangGraph Checkpointer)

The LangGraph checkpointer can be used to add memory to your LangGraph application.

`PostgresSaver` is an implementation of the checkpointer saver using
Postgres as the backend.

Currently, only the psycopg3 driver is supported.

Sync usage:

```python
from psycopg_pool import ConnectionPool
from langchain_postgres import (
PostgresSaver, PickleCheckpointSerializer
)

pool = ConnectionPool(
# Example configuration
conninfo="postgresql://langchain:langchain@localhost:6024/langchain",
max_size=20,
)

PostgresSaver.create_tables(pool)

checkpointer = PostgresSaver(
serializer=PickleCheckpointSerializer(),
sync_connection=pool,
)

# Set up the langgraph workflow with the checkpointer
workflow = ... # Fill in with your workflow
app = workflow.compile(checkpointer=checkpointer)

# Use with the sync methods of `app` (e.g., `app.stream())

pool.close() # Remember to close the connection pool.
```

Async usage:

```python
from psycopg_pool import AsyncConnectionPool
from langchain_postgres import (
PostgresSaver, PickleCheckpointSerializer
)

pool = AsyncConnectionPool(
# Example configuration
conninfo="postgresql://langchain:langchain@localhost:6024/langchain",
max_size=20,
)

# Create the tables in postgres (only needs to be done once)
await PostgresSaver.acreate_tables(pool)

checkpointer = PostgresSaver(
serializer=PickleCheckpointSerializer(),
async_connection=pool,
)

# Set up the langgraph workflow with the checkpointer
workflow = ... # Fill in with your workflow
app = workflow.compile(checkpointer=checkpointer)

# Use with the async methods of `app` (e.g., `app.astream()`)

await pool.close() # Remember to close the connection pool.
```

#### Testing

If testing with the postgres checkpointer it may be useful to both create and
drop the tables before and after the tests.

```python
from psycopg_pool import ConnectionPool
from langchain_postgres import (
PostgresSaver
)
with ConnectionPool(
# Example configuration
conninfo="postgresql://langchain:langchain@localhost:6024/langchain",
max_size=20,
) as conn:
PostgresSaver.create_tables(conn)
PostgresSaver.drop_tables(conn)
# Run your unit tests with langgraph
```


### ChatMessageHistory

The chat message history abstraction helps to persist chat message history
Expand Down
Loading