Class PostgresChatMessageHistory (0.7.0)

PostgresChatMessageHistory(
    key,
    engine: langchain_google_cloud_sql_pg.engine.PostgresEngine,
    session_id: str,
    table_name: str,
    messages: typing.List[langchain_core.messages.base.BaseMessage],
)

Chat message history stored in an Cloud SQL for PostgreSQL database.

Methods

PostgresChatMessageHistory

PostgresChatMessageHistory(
    key,
    engine: langchain_google_cloud_sql_pg.engine.PostgresEngine,
    session_id: str,
    table_name: str,
    messages: typing.List[langchain_core.messages.base.BaseMessage],
)

PostgresChatMessageHistory constructor.

Parameters
Name Description
key object

Key to prevent direct constructor usage.

engine PostgresEngine

Database connection pool.

session_id str

Retrieve the table content with this session ID.

table_name str

Table name that stores the chat message history.

messages List[BaseMessage]

Messages to store.

Exceptions
Type Description
Exception If constructor is directly called by the user.

aadd_message

aadd_message(message: langchain_core.messages.base.BaseMessage) -> None

Append the message to the record in PostgreSQL

aadd_messages

aadd_messages(
    messages: typing.Sequence[langchain_core.messages.base.BaseMessage],
) -> None

Append a list of messages to the record in PostgreSQL

aclear

aclear() -> None

Clear session memory from PostgreSQL

add_message

add_message(message: langchain_core.messages.base.BaseMessage) -> None

Append the message to the record in PostgreSQL

add_messages

add_messages(
    messages: typing.Sequence[langchain_core.messages.base.BaseMessage],
) -> None

Append a list of messages to the record in PostgreSQL

async_messages

async_messages() -> None

Retrieve the messages from Postgres.

clear

clear() -> None

Clear session memory from PostgreSQL

create

create(
    engine: langchain_google_cloud_sql_pg.engine.PostgresEngine,
    session_id: str,
    table_name: str,
)

Create a new PostgresChatMessageHistory instance.

Parameters
Name Description
engine PostgresEngine

Postgres engine to use.

session_id str

Retrieve the table content with this session ID.

table_name str

Table name that stores the chat message history.

Exceptions
Type Description
IndexError If the table provided does not contain required schema.
Returns
Type Description
PostgresChatMessageHistory A newly created instance of PostgresChatMessageHistory.

create_sync

create_sync(
    engine: langchain_google_cloud_sql_pg.engine.PostgresEngine,
    session_id: str,
    table_name: str,
)

Create a new PostgresChatMessageHistory instance.

Parameters
Name Description
engine PostgresEngine

Postgres engine to use.

session_id str

Retrieve the table content with this session ID.

table_name str

Table name that stores the chat message history.

Exceptions
Type Description
IndexError If the table provided does not contain required schema.
Returns
Type Description
PostgresChatMessageHistory A newly created instance of PostgresChatMessageHistory.

sync_messages

sync_messages() -> None

Retrieve the messages from Postgres.