PostgresEngine(
    key: object,
    pool: sqlalchemy.ext.asyncio.engine.AsyncEngine,
    loop: typing.Optional[asyncio.events.AbstractEventLoop],
    thread: typing.Optional[threading.Thread],
)A class for managing connections to a Cloud SQL for Postgres database.
Methods
PostgresEngine
PostgresEngine(
    key: object,
    pool: sqlalchemy.ext.asyncio.engine.AsyncEngine,
    loop: typing.Optional[asyncio.events.AbstractEventLoop],
    thread: typing.Optional[threading.Thread],
)PostgresEngine constructor.
| Parameters | |
|---|---|
| Name | Description | 
| key | objectPrevent direct constructor usage. | 
| pool | AsyncEngineAsync engine connection pool. | 
| loop | Optional[asyncio.AbstractEventLoop]Async event loop used to create the engine. | 
| thread | Optional[Thread]Thread used to create the engine async. | 
| Exceptions | |
|---|---|
| Type | Description | 
| Exception | If the constructor is called directly by the user. | 
_ainit_chat_history_table
_ainit_chat_history_table(table_name: str, schema_name: str = "public") -> NoneCreate a Cloud SQL table to store chat history.
| Parameters | |
|---|---|
| Name | Description | 
| table_name | strTable name to store chat history. | 
| schema_name | strSchema name to store chat history table. Default: "public". | 
_ainit_checkpoint_table
_ainit_checkpoint_table(
    table_name: str = "checkpoints", schema_name: str = "public"
) -> NoneCreate PgSQL tables to save checkpoints.
| Parameters | |
|---|---|
| Name | Description | 
| schema_name | strThe schema name to store the checkpoint tables. Default: "public". | 
| table_name | strThe PgSQL database table name. Default: "checkpoints". | 
_ainit_vectorstore_table
_ainit_vectorstore_table(
    table_name: str,
    vector_size: int,
    schema_name: str = "public",
    content_column: str = "content",
    embedding_column: str = "embedding",
    metadata_columns: list[langchain_google_cloud_sql_pg.engine.Column] = [],
    metadata_json_column: str = "langchain_metadata",
    id_column: typing.Union[
        str, langchain_google_cloud_sql_pg.engine.Column
    ] = "langchain_id",
    overwrite_existing: bool = False,
    store_metadata: bool = True,
) -> NoneCreate a table for saving of vectors to be used with PostgresVectorStore.
| Parameters | |
|---|---|
| Name | Description | 
| table_name | strThe Postgres database table name. | 
| vector_size | intVector size for the embedding model to be used. | 
| schema_name | strThe schema name to store Postgres database table. Default: "public". | 
| content_column | strName of the column to store document content. Default: "page_content". | 
| embedding_column | strName of the column to store vector embeddings. Default: "embedding". | 
| metadata_columns | list[Column]A list of Columns to create for custom metadata. Default: []. Optional. | 
| metadata_json_column | strThe column to store extra metadata in JSON format. Default: "langchain_metadata". Optional. | 
| id_column | Union[str, Column]Column to store ids. Default: "langchain_id" column name with data type UUID. Optional. | 
| overwrite_existing | boolWhether to drop existing table. Default: False. | 
| store_metadata | boolWhether to store metadata in the table. Default: True. | 
| Exceptions | |
|---|---|
| Type | Description | 
| DuplicateTableErro | |
| UndefinedObjectErro | |
_aload_table_schema
_aload_table_schema(
    table_name: str, schema_name: str = "public"
) -> sqlalchemy.sql.schema.TableLoad table schema from existing table in PgSQL database.
| Returns | |
|---|---|
| Type | Description | 
| (sqlalchemy.Table) | The loaded table. | 
_create
_create(
    project_id: str,
    region: str,
    instance: str,
    database: str,
    ip_type: typing.Union[str, google.cloud.sql.connector.enums.IPTypes],
    user: typing.Optional[str] = None,
    password: typing.Optional[str] = None,
    loop: typing.Optional[asyncio.events.AbstractEventLoop] = None,
    thread: typing.Optional[threading.Thread] = None,
    quota_project: typing.Optional[str] = None,
    iam_account_email: typing.Optional[str] = None,
    engine_args: typing.Mapping = {},
) -> langchain_google_cloud_sql_pg.engine.PostgresEngineCreate a PostgresEngine instance.
| Parameters | |
|---|---|
| Name | Description | 
| project_id | strGCP project ID. | 
| region | strPostgres instance region. | 
| instance | strPostgres instance name. | 
| database | strDatabase name. | 
| ip_type | Union[str, IPTypes]IP address type. Defaults to IPTypes.PUBLIC. | 
| user | Optional[str]Postgres user name. Defaults to None. | 
| password | Optional[str]Postgres user password. Defaults to None. | 
| loop | Optional[asyncio.AbstractEventLoop]Async event loop used to create the engine. | 
| thread | Optional[Thread]Thread used to create the engine async. | 
| quota_project | Optional[str]Project that provides quota for API calls. | 
| iam_account_email | Optional[str]IAM service account email. Defaults to None. | 
| engine_args | MappingAdditional arguments that are passed directly to  | 
| Exceptions | |
|---|---|
| Type | Description | 
| ValueError | If only one of userandpasswordis specified. | 
_run_as_async
_run_as_async(
    coro: typing.Awaitable[langchain_google_cloud_sql_pg.engine.T],
) -> langchain_google_cloud_sql_pg.engine.TRun an async coroutine asynchronously
_run_as_sync
_run_as_sync(
    coro: typing.Awaitable[langchain_google_cloud_sql_pg.engine.T],
) -> langchain_google_cloud_sql_pg.engine.TRun an async coroutine synchronously
afrom_instance
afrom_instance(
    project_id: str,
    region: str,
    instance: str,
    database: str,
    user: typing.Optional[str] = None,
    password: typing.Optional[str] = None,
    ip_type: typing.Union[
        str, google.cloud.sql.connector.enums.IPTypes
    ] = IPTypes.PUBLIC,
    quota_project: typing.Optional[str] = None,
    iam_account_email: typing.Optional[str] = None,
    engine_args: typing.Mapping = {},
) -> langchain_google_cloud_sql_pg.engine.PostgresEngineCreate a PostgresEngine from a Postgres instance.
| Parameters | |
|---|---|
| Name | Description | 
| project_id | strGCP project ID. | 
| region | strPostgres instance region. | 
| instance | strPostgres instance name. | 
| database | strDatabase name. | 
| user | Optional[str], optionalPostgres user name. Defaults to None. | 
| password | Optional[str], optionalPostgres user password. Defaults to None. | 
| ip_type | Union[str, IPTypes], optionalIP address type. Defaults to IPTypes.PUBLIC. | 
| quota_project | Optional[str]Project that provides quota for API calls. | 
| iam_account_email | Optional[str], optionalIAM service account email. Defaults to None. | 
| engine_args | MappingAdditional arguments that are passed directly to  | 
| Returns | |
|---|---|
| Type | Description | 
| PostgresEngine | A newly created PostgresEngine instance. | 
ainit_chat_history_table
ainit_chat_history_table(table_name: str, schema_name: str = "public") -> NoneCreate a Cloud SQL table to store chat history.
| Parameter | |
|---|---|
| Name | Description | 
| table_name | strTable name to store chat history. | 
ainit_checkpoint_table
ainit_checkpoint_table(
    table_name: str = "checkpoints", schema_name: str = "public"
) -> NoneCreate an PgSQL table to save checkpoint messages.
| Parameters | |
|---|---|
| Name | Description | 
| schema_name | strThe schema name to store checkpoint tables. Default: "public". | 
| table_name | strThe PgSQL database table name. Default: "checkpoints". | 
ainit_document_table
ainit_document_table(
    table_name: str,
    schema_name: str = "public",
    content_column: str = "page_content",
    metadata_columns: list[langchain_google_cloud_sql_pg.engine.Column] = [],
    metadata_json_column: str = "langchain_metadata",
    store_metadata: bool = True,
) -> NoneCreate a table for saving of langchain documents.
| Parameters | |
|---|---|
| Name | Description | 
| table_name | strThe PgSQL database table name. | 
| schema_name | strThe schema name to store PgSQL database table. Default: "public". | 
| content_column | strName of the column to store document content. Default: "page_content". | 
| metadata_columns | list[sqlalchemy.Column]A list of SQLAlchemy Columns to create for custom metadata. Optional. | 
| metadata_json_column | strThe column to store extra metadata in JSON format. Default: "langchain_metadata". Optional. | 
| store_metadata | boolWhether to store extra metadata in a metadata column if not described in 'metadata' field list (Default: True). | 
| Exceptions | |
|---|---|
| Type | Description | 
| DuplicateTableErro | |
ainit_vectorstore_table
ainit_vectorstore_table(
    table_name: str,
    vector_size: int,
    schema_name: str = "public",
    content_column: str = "content",
    embedding_column: str = "embedding",
    metadata_columns: list[langchain_google_cloud_sql_pg.engine.Column] = [],
    metadata_json_column: str = "langchain_metadata",
    id_column: typing.Union[
        str, langchain_google_cloud_sql_pg.engine.Column
    ] = "langchain_id",
    overwrite_existing: bool = False,
    store_metadata: bool = True,
) -> NoneCreate a table for saving of vectors to be used with PostgresVectorStore.
| Parameters | |
|---|---|
| Name | Description | 
| table_name | strThe Postgres database table name. | 
| vector_size | intVector size for the embedding model to be used. | 
| schema_name | strThe schema name to store Postgres database table. Default: "public". | 
| content_column | strName of the column to store document content. Default: "page_content". | 
| embedding_column | strName of the column to store vector embeddings. Default: "embedding". | 
| metadata_columns | list[Column]A list of Columns to create for custom metadata. Default: []. Optional. | 
| metadata_json_column | strThe column to store extra metadata in JSON format. Default: "langchain_metadata". Optional. | 
| id_column | Union[str, Column]Column to store ids. Default: "langchain_id" column name with data type UUID. Optional. | 
| overwrite_existing | boolWhether to drop existing table. Default: False. | 
| store_metadata | boolWhether to store metadata in the table. Default: True. | 
close
close() -> NoneDispose of connection pool
from_engine
from_engine(
    engine: sqlalchemy.ext.asyncio.engine.AsyncEngine,
    loop: typing.Optional[asyncio.events.AbstractEventLoop] = None,
) -> langchain_google_cloud_sql_pg.engine.PostgresEngineCreate an PostgresEngine instance from an AsyncEngine.
from_engine_args
from_engine_args(
    url: str | sqlalchemy.engine.url.URL, **kwargs: typing.Any
) -> langchain_google_cloud_sql_pg.engine.PostgresEngineCreate an PostgresEngine instance from arguments. These parameters are pass directly into sqlalchemy's create_async_engine function.
| Parameters | |
|---|---|
| Name | Description | 
| url | Union[str URL]the URL used to connect to a database | 
| \*\*kwargs | Any, optionalsqlalchemy  | 
| Exceptions | |
|---|---|
| Type | Description | 
| ValueError | If postgresql+asyncpgis not specified as the PG driver | 
from_instance
from_instance(
    project_id: str,
    region: str,
    instance: str,
    database: str,
    user: typing.Optional[str] = None,
    password: typing.Optional[str] = None,
    ip_type: typing.Union[
        str, google.cloud.sql.connector.enums.IPTypes
    ] = IPTypes.PUBLIC,
    quota_project: typing.Optional[str] = None,
    iam_account_email: typing.Optional[str] = None,
    engine_args: typing.Mapping = {},
) -> langchain_google_cloud_sql_pg.engine.PostgresEngineCreate a PostgresEngine from a Postgres instance.
| Parameters | |
|---|---|
| Name | Description | 
| project_id | strGCP project ID. | 
| region | strPostgres instance region. | 
| instance | strPostgres instance name. | 
| database | strDatabase name. | 
| user | Optional[str], optionalPostgres user name. Defaults to None. | 
| password | Optional[str], optionalPostgres user password. Defaults to None. | 
| ip_type | Union[str, IPTypes], optionalIP address type. Defaults to IPTypes.PUBLIC. | 
| quota_project | Optional[str]Project that provides quota for API calls. | 
| iam_account_email | Optional[str], optionalIAM service account email. Defaults to None. | 
| engine_args | MappingAdditional arguments that are passed directly to  | 
| Returns | |
|---|---|
| Type | Description | 
| PostgresEngine | A newly created PostgresEngine instance. | 
init_chat_history_table
init_chat_history_table(table_name: str, schema_name: str = "public") -> NoneCreate a Cloud SQL table to store chat history.
| Parameters | |
|---|---|
| Name | Description | 
| table_name | strTable name to store chat history. | 
| schema_name | strSchema name to store chat history table. Default: "public". | 
init_checkpoint_table
init_checkpoint_table(
    table_name: str = "checkpoints", schema_name: str = "public"
) -> NoneCreate Cloud SQL tables to store checkpoints.
| Parameters | |
|---|---|
| Name | Description | 
| schema_name | strThe schema name to store checkpoint tables. Default: "public". | 
| table_name | strThe PgSQL database table name. Default: "checkpoints". | 
init_document_table
init_document_table(
    table_name: str,
    schema_name: str = "public",
    content_column: str = "page_content",
    metadata_columns: list[langchain_google_cloud_sql_pg.engine.Column] = [],
    metadata_json_column: str = "langchain_metadata",
    store_metadata: bool = True,
) -> NoneCreate a table for saving of langchain documents.
| Parameters | |
|---|---|
| Name | Description | 
| table_name | strThe PgSQL database table name. | 
| schema_name | strThe schema name to store PgSQL database table. Default: "public". | 
| content_column | strName of the column to store document content. Default: "page_content". | 
| metadata_columns | list[sqlalchemy.Column]A list of SQLAlchemy Columns to create for custom metadata. Optional. | 
| metadata_json_column | strThe column to store extra metadata in JSON format. Default: "langchain_metadata". Optional. | 
| store_metadata | boolWhether to store extra metadata in a metadata column if not described in 'metadata' field list (Default: True). | 
| Exceptions | |
|---|---|
| Type | Description | 
| DuplicateTableErro | |
init_vectorstore_table
init_vectorstore_table(
    table_name: str,
    vector_size: int,
    schema_name: str = "public",
    content_column: str = "content",
    embedding_column: str = "embedding",
    metadata_columns: list[langchain_google_cloud_sql_pg.engine.Column] = [],
    metadata_json_column: str = "langchain_metadata",
    id_column: typing.Union[
        str, langchain_google_cloud_sql_pg.engine.Column
    ] = "langchain_id",
    overwrite_existing: bool = False,
    store_metadata: bool = True,
) -> NoneCreate a table for saving of vectors to be used with PostgresVectorStore.
| Parameters | |
|---|---|
| Name | Description | 
| table_name | strThe Postgres database table name. | 
| vector_size | intVector size for the embedding model to be used. | 
| schema_name | strThe schema name to store Postgres database table. Default: "public". | 
| content_column | strName of the column to store document content. Default: "page_content". | 
| embedding_column | strName of the column to store vector embeddings. Default: "embedding". | 
| metadata_columns | list[Column]A list of Columns to create for custom metadata. Default: []. Optional. | 
| metadata_json_column | strThe column to store extra metadata in JSON format. Default: "langchain_metadata". Optional. | 
| id_column | Union[str, Column]Column to store ids. Default: "langchain_id" column name with data type UUID. Optional. | 
| overwrite_existing | boolWhether to drop existing table. Default: False. | 
| store_metadata | boolWhether to store metadata in the table. Default: True. | 
| Exceptions | |
|---|---|
| Type | Description | 
| UndefinedObjectErro | |