LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangGraph
  • Web
  • Channels
  • Pregel
  • Prebuilt
  • Remote
  • Stream
LangGraph SDK
  • Client
  • Auth
  • React
  • Logging
  • React Ui
  • Server
LangGraph Checkpoint
LangGraph Checkpoint MongoDB
LangGraph Checkpoint Postgres
LangGraph Checkpoint Redis
  • Shallow
  • Store
LangGraph Checkpoint SQLite
LangGraph Checkpoint Validation
  • Cli
LangGraph API
LangGraph CLI
LangGraph CUA
  • Utils
LangGraph Supervisor
LangGraph Swarm
โŒ˜I

Chat LangChain

What can I help with?

Enter to sendยทShift+Enter new line

Menu

LangGraph
WebChannelsPregelPrebuiltRemoteStream
LangGraph SDK
ClientAuthReactLoggingReact UiServer
LangGraph Checkpoint
LangGraph Checkpoint MongoDB
LangGraph Checkpoint Postgres
LangGraph Checkpoint Redis
ShallowStore
LangGraph Checkpoint SQLite
LangGraph Checkpoint Validation
Cli
LangGraph API
LangGraph CLI
LangGraph CUA
Utils
LangGraph Supervisor
LangGraph Swarm
Language
Theme
JavaScript@langchain/langgraph-checkpoint-postgresindexPostgresSaver
Classโ—Since v0.0

PostgresSaver

LangGraph checkpointer that uses a Postgres instance as the backing store. Uses the node-postgres package internally to connect to a Postgres instance.

Copy
class PostgresSaver

Bases

BaseCheckpointSaver

Used in Docs

  • Short-term memory

Example

Copy
import { ChatOpenAI } from "@langchain/openai";
import { PostgresSaver } from "@langchain/langgraph-checkpoint-postgres";
import { createReactAgent } from "@langchain/langgraph/prebuilt";

const checkpointer = PostgresSaver.fromConnString(
  "postgresql://user:password@localhost:5432/db",
  // optional configuration object
  {
    schema: "custom_schema" // defaults to "public"
  }
);

// NOTE: you need to call .setup() the first time you're using your checkpointer
await checkpointer.setup();

const graph = createReactAgent({
  tools: [getWeather],
  llm: new ChatOpenAI({
    model: "gpt-4o-mini",
  }),
  checkpointSaver: checkpointer,
});
const config = { configurable: { thread_id: "1" } };

await graph.invoke({
  messages: [{
    role: "user",
    content: "what's the weather in sf"
  }],
}, config);

Constructors

constructor
constructorโ†’ PostgresSaver

Properties

property
isSetup: boolean

Methods

method
_dumpBlobsโ†’ [string, string, string, string, string, Uint8Array<ArrayBufferLike> | undefined][]
method
_dumpCheckpointโ†’ Record<string, unknown>
method
_dumpMetadataโ†’ any
method
_dumpWritesโ†’ [string, string, string, string, number, string, string, Uint8Array<ArrayBufferLike>][]
method
_loadBlobsโ†’ Promise<Record<string, unknown>>
method
_loadCheckpointโ†’ Promise<Checkpoint>
method
_loadMetadataโ†’ Promise<any>
method
_loadWritesโ†’ Promise<[string, string, unknown][]>
method
_searchWhereโ†’ [string, unknown[]]

Return WHERE clause predicates for a given list() config, filter, cursor.

This method returns a tuple of a string and a tuple of values. The string is the parameterized WHERE clause predicate (including the WHERE keyword): "WHERE column1 = $1 AND column2 IS $2". The list of values contains the values for each of the corresponding parameters.

method
endโ†’ Promise<void>
method
getTupleโ†’ Promise<any>

Get a checkpoint tuple from the database. This method retrieves a checkpoint tuple from the Postgres database based on the provided config. If the config's configurable field contains a "checkpoint_id" key, the checkpoint with the matching thread_id and namespace is retrieved. Otherwise, the latest checkpoint for the given thread_id is retrieved.

method
listโ†’ AsyncGenerator<CheckpointTuple>

List checkpoints from the database.

This method retrieves a list of checkpoint tuples from the Postgres database based on the provided config. The checkpoints are ordered by checkpoint ID in descending order (newest first).

method
putโ†’ Promise<RunnableConfig<Record<string, any>>>

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).

method
putWritesโ†’ Promise<void>

Store intermediate writes linked to a checkpoint.

This method saves intermediate writes associated with a checkpoint to the Postgres database.

method
setupโ†’ Promise<void>

Set up the checkpoint database asynchronously.

This method creates the necessary tables in the Postgres database if they don't already exist and runs database migrations. It MUST be called directly by the user the first time checkpointer is used.

method
fromConnStringโ†’ PostgresSaver

Creates a new instance of PostgresSaver from a connection string.

View source on GitHub