langchain.js
    Preparing search index...

    Class for managing chat message history using a Postgres Database as a storage backend. Extends the BaseListChatMessageHistory class.

    const chatHistory = new PostgresChatMessageHistory({
    tableName: "langchain_chat_histories",
    sessionId: "lc-example",
    pool: new pg.Pool({
    host: "127.0.0.1",
    port: 5432,
    user: "myuser",
    password: "ChangeMe",
    database: "api",
    }),
    });

    Hierarchy (View Summary)

    Index

    Constructors

    • Creates a new PostgresChatMessageHistory.

      Parameters

      • fields: PostgresChatMessageHistoryInput

        The input fields for the PostgresChatMessageHistory.

        Type definition for the input parameters required when instantiating a PostgresChatMessageHistory object.

        • OptionalescapeTableName?: boolean

          If true, the table name will be escaped. ('lAnGcHaIn' will be escaped to '"lAnGcHaIn"')

        • Optionalpool?: pg.Pool

          Postgres pool to use. If provided the PostgresChatMessageHistory object will use the provided pool. Otherwise it will create a new pool using the provided configuration.

        • OptionalpoolConfig?: pg.PoolConfig

          Configuration object for the Postgres pool. If provided the PostgresChatMessageHistory object will create a new pool using the provided configuration. Otherwise it will use the provided pool.

        • sessionId: string

          Session ID to use when storing and retrieving chat message history.

        • OptionaltableName?: string

          Name of the table to use when storing and retrieving chat message

      Returns PostgresChatMessageHistory

      If neither pool nor poolConfig is provided.

    Properties

    lc_namespace: string[] = ...
    pool: Pool
    sessionId: string
    tableName: string = "langchain_chat_histories"

    Methods

    • Parameters

      • message: BaseMessage

      Returns Promise<void>

    • Returns Promise<void>

    • End the Postgres pool.

      Returns Promise<void>

    • Returns Promise<BaseMessage[]>