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 | 
        
          object
          Prevent direct constructor usage.  | 
      
pool | 
        
          AsyncEngine
          Async 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_store_table
_ainit_chat_store_table(
    table_name: str, schema_name: str = "public", overwrite_existing: bool = False
) -> NoneCreate a table to save chat store.
| Parameters | |
|---|---|
| Name | Description | 
table_name | 
        
          str
          The table name to store chat history.  | 
      
schema_name | 
        
          str
          The schema name to store the chat store table. Default: "public".  | 
      
overwrite_existing | 
        
          bool Returns: None
          Whether to drop existing table. Default: False.  | 
      
_ainit_doc_store_table
_ainit_doc_store_table(
    table_name: str, schema_name: str = "public", overwrite_existing: bool = False
) -> NoneCreate an table for the DocumentStore.
| Parameters | |
|---|---|
| Name | Description | 
table_name | 
        
          str
          The table name to store documents.  | 
      
schema_name | 
        
          str
          The schema name to store the documents table. Default: "public".  | 
      
overwrite_existing | 
        
          bool
          Whether to drop existing table. Default: False.  | 
      
_ainit_index_store_table
_ainit_index_store_table(
    table_name: str, schema_name: str = "public", overwrite_existing: bool = False
) -> NoneCreate a table to save Index metadata.
| Parameters | |
|---|---|
| Name | Description | 
table_name | 
        
          str
          The table name to store index metadata.  | 
      
schema_name | 
        
          str
          The schema name to store the index metadata table. Default: "public".  | 
      
overwrite_existing | 
        
          bool
          Whether to drop existing table. Default: False.  | 
      
_ainit_vector_store_table
_ainit_vector_store_table(
    table_name: str,
    vector_size: int,
    schema_name: str = "public",
    id_column: typing.Union[str, llama_index_cloud_sql_pg.engine.Column] = "node_id",
    text_column: str = "text",
    embedding_column: str = "embedding",
    metadata_json_column: str = "li_metadata",
    metadata_columns: list[llama_index_cloud_sql_pg.engine.Column] = [],
    ref_doc_id_column: str = "ref_doc_id",
    node_column: str = "node_data",
    stores_text: bool = True,
    overwrite_existing: bool = False,
) -> NoneCreate a table for the VectorStore.
| Parameters | |
|---|---|
| Name | Description | 
table_name | 
        
          str
          The table name to store nodes with embedding vectors.  | 
      
vector_size | 
        
          int
          Vector size for the embedding model to be used.  | 
      
schema_name | 
        
          str
          The schema name to store the vector store table. Default: "public".  | 
      
id_column | 
        
          str
          Column that represents if of a Node. Defaults to "node_id".  | 
      
text_column | 
        
          str
          Column that represent text content of a Node. Defaults to "text".  | 
      
embedding_column | 
        
          str
          Column for embedding vectors. The embedding is generated from the content of Node. Defaults to "embedding".  | 
      
metadata_json_column | 
        
          str
          Column to store metadata as JSON. Defaults to "li_metadata".  | 
      
metadata_columns | 
        
          list[str]
          Column(s) that represent extracted metadata keys in their own columns.  | 
      
ref_doc_id_column | 
        
          str
          Column that represents id of a node's parent document. Defaults to "ref_doc_id".  | 
      
node_column | 
        
          str
          Column that represents the whole JSON node. Defaults to "node_data".  | 
      
stores_text | 
        
          bool
          Whether the table stores text. Defaults to "True".  | 
      
overwrite_existing | 
        
          bool
          Whether to drop existing table. Default: False.  | 
      
| 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 an existing table in a PgSQL database, potentially from a specific database schema.
| Returns | |
|---|---|
| Type | Description | 
(sqlalchemy.Table) | 
        The loaded table, including its table schema information. | 
_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,
) -> llama_index_cloud_sql_pg.engine.PostgresEngineCreate a PostgresEngine instance.
| Parameters | |
|---|---|
| Name | Description | 
project_id | 
        
          str
          GCP project ID.  | 
      
region | 
        
          str
          Postgres instance region.  | 
      
instance | 
        
          str
          Postgres instance name.  | 
      
database | 
        
          str
          Database 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.  | 
      
| Exceptions | |
|---|---|
| Type | Description | 
ValueError | 
        If only one of user and password is specified. | 
      
_run_as_async
_run_as_async(
    coro: typing.Awaitable[llama_index_cloud_sql_pg.engine.T],
) -> llama_index_cloud_sql_pg.engine.TRun an async coroutine asynchronously
_run_as_sync
_run_as_sync(
    coro: typing.Awaitable[llama_index_cloud_sql_pg.engine.T],
) -> llama_index_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,
) -> llama_index_cloud_sql_pg.engine.PostgresEngineCreate a PostgresEngine from a Postgres instance.
| Parameters | |
|---|---|
| Name | Description | 
project_id | 
        
          str
          GCP project ID.  | 
      
region | 
        
          str
          Postgres instance region.  | 
      
instance | 
        
          str
          Postgres instance name.  | 
      
database | 
        
          str
          Database name.  | 
      
user | 
        
          Optional[str], optional
          Postgres user name. Defaults to None.  | 
      
password | 
        
          Optional[str], optional
          Postgres user password. Defaults to None.  | 
      
ip_type | 
        
          Union[str, IPTypes], optional
          IP address type. Defaults to IPTypes.PUBLIC.  | 
      
quota_project | 
        
          Optional[str]
          Project that provides quota for API calls.  | 
      
iam_account_email | 
        
          Optional[str], optional
          IAM service account email. Defaults to None.  | 
      
| Returns | |
|---|---|
| Type | Description | 
PostgresEngine | 
        A newly created PostgresEngine instance. | 
ainit_chat_store_table
ainit_chat_store_table(
    table_name: str, schema_name: str = "public", overwrite_existing: bool = False
) -> NoneCreate a table to save chat store.
| Parameters | |
|---|---|
| Name | Description | 
table_name | 
        
          str
          The table name to store chat store.  | 
      
schema_name | 
        
          str
          The schema name to store the chat store table. Default: "public".  | 
      
overwrite_existing | 
        
          bool Returns: None
          Whether to drop existing table. Default: False.  | 
      
ainit_doc_store_table
ainit_doc_store_table(
    table_name: str, schema_name: str = "public", overwrite_existing: bool = False
) -> NoneCreate a table for the DocumentStore.
| Parameters | |
|---|---|
| Name | Description | 
table_name | 
        
          str
          The table name to store documents.  | 
      
schema_name | 
        
          str
          The schema name to store the documents table. Default: "public".  | 
      
overwrite_existing | 
        
          bool
          Whether to drop existing table. Default: False.  | 
      
ainit_index_store_table
ainit_index_store_table(
    table_name: str, schema_name: str = "public", overwrite_existing: bool = False
) -> NoneCreate a table to save Index metadata.
| Parameters | |
|---|---|
| Name | Description | 
table_name | 
        
          str
          The table name to store index metadata.  | 
      
schema_name | 
        
          str
          The schema name to store the index metadata table. Default: "public".  | 
      
overwrite_existing | 
        
          bool
          Whether to drop existing table. Default: False.  | 
      
ainit_vector_store_table
ainit_vector_store_table(
    table_name: str,
    vector_size: int,
    schema_name: str = "public",
    id_column: typing.Union[str, llama_index_cloud_sql_pg.engine.Column] = "node_id",
    text_column: str = "text",
    embedding_column: str = "embedding",
    metadata_json_column: str = "li_metadata",
    metadata_columns: list[llama_index_cloud_sql_pg.engine.Column] = [],
    ref_doc_id_column: str = "ref_doc_id",
    node_column: str = "node_data",
    stores_text: bool = True,
    overwrite_existing: bool = False,
) -> NoneCreate a table for the VectorStore.
| Parameters | |
|---|---|
| Name | Description | 
table_name | 
        
          str
          The table name to store nodes with embedding vectors.  | 
      
vector_size | 
        
          int
          Vector size for the embedding model to be used.  | 
      
schema_name | 
        
          str
          The schema name to store the vector store table. Default: "public".  | 
      
id_column | 
        
          str
          Column that represents if of a Node. Defaults to "node_id".  | 
      
text_column | 
        
          str
          Column that represent text content of a Node. Defaults to "text".  | 
      
embedding_column | 
        
          str
          Column for embedding vectors. The embedding is generated from the content of Node. Defaults to "embedding".  | 
      
metadata_json_column | 
        
          str
          Column to store metadata as JSON. Defaults to "li_metadata".  | 
      
metadata_columns | 
        
          list[str]
          Column(s) that represent extracted metadata keys in their own columns.  | 
      
ref_doc_id_column | 
        
          str
          Column that represents id of a node's parent document. Defaults to "ref_doc_id".  | 
      
node_column | 
        
          str
          Column that represents the whole JSON node. Defaults to "node_data".  | 
      
stores_text | 
        
          bool
          Whether the table stores text. Defaults to "True".  | 
      
overwrite_existing | 
        
          bool
          Whether to drop existing table. Default: False.  | 
      
close
close() -> NoneDispose of connection pool
from_engine
from_engine(
    engine: sqlalchemy.ext.asyncio.engine.AsyncEngine,
    loop: typing.Optional[asyncio.events.AbstractEventLoop] = None,
) -> llama_index_cloud_sql_pg.engine.PostgresEngineCreate an PostgresEngine instance from an AsyncEngine.
from_engine_args
from_engine_args(
    url: typing.Union[str, sqlalchemy.engine.url.URL], **kwargs: typing.Any
) -> llama_index_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, optional
          sqlalchemy   | 
      
| Exceptions | |
|---|---|
| Type | Description | 
ValueError | 
        If postgresql+asyncpg is 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,
) -> llama_index_cloud_sql_pg.engine.PostgresEngineCreate a PostgresEngine from a Postgres instance.
| Parameters | |
|---|---|
| Name | Description | 
project_id | 
        
          str
          GCP project ID.  | 
      
region | 
        
          str
          Postgres instance region.  | 
      
instance | 
        
          str
          Postgres instance name.  | 
      
database | 
        
          str
          Database name.  | 
      
user | 
        
          Optional[str], optional
          Postgres user name. Defaults to None.  | 
      
password | 
        
          Optional[str], optional
          Postgres user password. Defaults to None.  | 
      
ip_type | 
        
          Union[str, IPTypes], optional
          IP address type. Defaults to IPTypes.PUBLIC.  | 
      
quota_project | 
        
          Optional[str]
          Project that provides quota for API calls.  | 
      
iam_account_email | 
        
          Optional[str], optional
          IAM service account email. Defaults to None.  | 
      
| Returns | |
|---|---|
| Type | Description | 
PostgresEngine | 
        A newly created PostgresEngine instance. | 
init_chat_store_table
init_chat_store_table(
    table_name: str, schema_name: str = "public", overwrite_existing: bool = False
) -> NoneCreate a table to save chat store.
| Parameters | |
|---|---|
| Name | Description | 
table_name | 
        
          str
          The table name to store chat store.  | 
      
schema_name | 
        
          str
          The schema name to store the chat store table. Default: "public".  | 
      
overwrite_existing | 
        
          bool Returns: None
          Whether to drop existing table. Default: False.  | 
      
init_doc_store_table
init_doc_store_table(
    table_name: str, schema_name: str = "public", overwrite_existing: bool = False
) -> NoneCreate a table for the DocumentStore.
| Parameters | |
|---|---|
| Name | Description | 
table_name | 
        
          str
          The table name to store documents.  | 
      
schema_name | 
        
          str
          The schema name to store the documents table. Default: "public".  | 
      
overwrite_existing | 
        
          bool
          Whether to drop existing table. Default: False.  | 
      
init_index_store_table
init_index_store_table(
    table_name: str, schema_name: str = "public", overwrite_existing: bool = False
) -> NoneCreate a table to save Index metadata.
| Parameters | |
|---|---|
| Name | Description | 
table_name | 
        
          str
          The table name to store index metadata.  | 
      
schema_name | 
        
          str
          The schema name to store the index metadata table. Default: "public".  | 
      
overwrite_existing | 
        
          bool
          Whether to drop existing table. Default: False.  | 
      
init_vector_store_table
init_vector_store_table(
    table_name: str,
    vector_size: int,
    schema_name: str = "public",
    id_column: typing.Union[str, llama_index_cloud_sql_pg.engine.Column] = "node_id",
    text_column: str = "text",
    embedding_column: str = "embedding",
    metadata_json_column: str = "li_metadata",
    metadata_columns: list[llama_index_cloud_sql_pg.engine.Column] = [],
    ref_doc_id_column: str = "ref_doc_id",
    node_column: str = "node_data",
    stores_text: bool = True,
    overwrite_existing: bool = False,
) -> NoneCreate a table for the VectorStore.
| Parameters | |
|---|---|
| Name | Description | 
table_name | 
        
          str
          The table name to store nodes with embedding vectors.  | 
      
vector_size | 
        
          int
          Vector size for the embedding model to be used.  | 
      
schema_name | 
        
          str
          The schema name to store the vector store table. Default: "public".  | 
      
id_column | 
        
          str
          Column that represents if of a Node. Defaults to "node_id".  | 
      
text_column | 
        
          str
          Column that represent text content of a Node. Defaults to "text".  | 
      
embedding_column | 
        
          str
          Column for embedding vectors. The embedding is generated from the content of Node. Defaults to "embedding".  | 
      
metadata_json_column | 
        
          str
          Column to store metadata as JSON. Defaults to "li_metadata".  | 
      
metadata_columns | 
        
          list[str]
          Column(s) that represent extracted metadata keys in their own columns.  | 
      
ref_doc_id_column | 
        
          str
          Column that represents id of a node's parent document. Defaults to "ref_doc_id".  | 
      
node_column | 
        
          str
          Column that represents the whole JSON node. Defaults to "node_data".  | 
      
stores_text | 
        
          bool
          Whether the table stores text. Defaults to "True".  | 
      
overwrite_existing | 
        
          bool
          Whether to drop existing table. Default: False.  |