Class AlloyDBEngine (0.2.1)

AlloyDBEngine(
    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 AlloyDB database.

Methods

AlloyDBEngine

AlloyDBEngine(
    key: object,
    pool: sqlalchemy.ext.asyncio.engine.AsyncEngine,
    loop: typing.Optional[asyncio.events.AbstractEventLoop],
    thread: typing.Optional[threading.Thread],
)

AlloyDBEngine constructor.

Parameters
Name Description
key object

Prevent direct constructor usage.

engine 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
) -> None

Create an AlloyDB 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

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

Create an AlloyDB 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
) -> None

Create an AlloyDB 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_alloydb_pg.engine.Column] = "node_id",
    text_column: str = "text",
    embedding_column: str = "embedding",
    metadata_json_column: str = "li_metadata",
    metadata_columns: list[llama_index_alloydb_pg.engine.Column] = [],
    ref_doc_id_column: str = "ref_doc_id",
    node_column: str = "node_data",
    stores_text: bool = True,
    overwrite_existing: bool = False,
) -> None

Create an AlloyDB 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.Table

Load 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,
    cluster: str,
    instance: str,
    database: str,
    ip_type: typing.Union[str, google.cloud.alloydb.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,
    iam_account_email: typing.Optional[str] = None,
) -> llama_index_alloydb_pg.engine.AlloyDBEngine

Create an AlloyDBEngine from an AlloyDB instance.

Parameters
Name Description
project_id str

GCP project ID.

region str

Cloud AlloyDB instance region.

cluster str

Cloud AlloyDB cluster name.

instance str

Cloud AlloyDB instance name.

database str

Database name.

ip_type Union[str, IPTypes]

IP address type. Defaults to IPTypes.PUBLIC.

user Optional[str]

Cloud AlloyDB user name. Defaults to None.

password Optional[str]

Cloud AlloyDB 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.

iam_account_email Optional[str]

IAM service account email.

Exceptions
Type Description
ValueError Raises error if only one of 'user' or 'password' is specified.
Returns
Type Description
AlloyDBEngine A newly created AlloyDBEngine instance.

_run_as_async

_run_as_async(
    coro: typing.Awaitable[llama_index_alloydb_pg.engine.T],
) -> llama_index_alloydb_pg.engine.T

Run an async coroutine asynchronously

_run_as_sync

_run_as_sync(
    coro: typing.Awaitable[llama_index_alloydb_pg.engine.T],
) -> llama_index_alloydb_pg.engine.T

Run an async coroutine synchronously

afrom_instance

afrom_instance(
    project_id: str,
    region: str,
    cluster: str,
    instance: str,
    database: str,
    user: typing.Optional[str] = None,
    password: typing.Optional[str] = None,
    ip_type: typing.Union[
        str, google.cloud.alloydb.connector.enums.IPTypes
    ] = IPTypes.PUBLIC,
    iam_account_email: typing.Optional[str] = None,
) -> llama_index_alloydb_pg.engine.AlloyDBEngine

Create an AlloyDBEngine from an AlloyDB instance.

Parameters
Name Description
project_id str

GCP project ID.

region str

Cloud AlloyDB instance region.

cluster str

Cloud AlloyDB cluster name.

instance str

Cloud AlloyDB instance name.

database str

Cloud AlloyDB database name.

user Optional[str], optional

Cloud AlloyDB user name. Defaults to None.

password Optional[str], optional

Cloud AlloyDB user password. Defaults to None.

ip_type Union[str, IPTypes], optional

IP address type. Defaults to IPTypes.PUBLIC.

iam_account_email Optional[str], optional

IAM service account email. Defaults to None.

Returns
Type Description
AlloyDBEngine A newly created AlloyDBEngine instance.

ainit_chat_store_table

ainit_chat_store_table(
    table_name: str, schema_name: str = "public", overwrite_existing: bool = False
) -> None

Create an AlloyDB 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

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

Create an AlloyDB 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
) -> None

Create an AlloyDB 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_alloydb_pg.engine.Column] = "node_id",
    text_column: str = "text",
    embedding_column: str = "embedding",
    metadata_json_column: str = "li_metadata",
    metadata_columns: list[llama_index_alloydb_pg.engine.Column] = [],
    ref_doc_id_column: str = "ref_doc_id",
    node_column: str = "node_data",
    stores_text: bool = True,
    overwrite_existing: bool = False,
) -> None

Create an AlloyDB 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() -> None

Dispose of connection pool

from_connection_string

from_connection_string(
    url: typing.Union[str, sqlalchemy.engine.url.URL], **kwargs: typing.Any
) -> llama_index_alloydb_pg.engine.AlloyDBEngine

Create an AlloyDBEngine instance from arguments

Parameter
Name Description
url Optional[str]

the URL used to connect to a database. Use url or set other arguments.

Exceptions
Type Description
ValueError If not all database url arguments are specified

from_engine

from_engine(
    engine: sqlalchemy.ext.asyncio.engine.AsyncEngine,
    loop: typing.Optional[asyncio.events.AbstractEventLoop] = None,
) -> llama_index_alloydb_pg.engine.AlloyDBEngine

Create an AlloyDBEngine instance from an AsyncEngine.

from_instance

from_instance(
    project_id: str,
    region: str,
    cluster: str,
    instance: str,
    database: str,
    user: typing.Optional[str] = None,
    password: typing.Optional[str] = None,
    ip_type: typing.Union[
        str, google.cloud.alloydb.connector.enums.IPTypes
    ] = IPTypes.PUBLIC,
    iam_account_email: typing.Optional[str] = None,
) -> llama_index_alloydb_pg.engine.AlloyDBEngine

Create an AlloyDBEngine from an AlloyDB instance.

Parameters
Name Description
project_id str

GCP project ID.

region str

Cloud AlloyDB instance region.

cluster str

Cloud AlloyDB cluster name.

instance str

Cloud AlloyDB instance name.

database str

Database name.

user Optional[str]

Cloud AlloyDB user name. Defaults to None.

password Optional[str]

Cloud AlloyDB user password. Defaults to None.

ip_type Union[str, IPTypes], optional

IP address type. Defaults to IPTypes.PUBLIC.

iam_account_email Optional[str], optional

IAM service account email. Defaults to None.

Returns
Type Description
AlloyDBEngine A newly created AlloyDBEngine instance.

init_chat_store_table

init_chat_store_table(
    table_name: str, schema_name: str = "public", overwrite_existing: bool = False
) -> None

Create an AlloyDB 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

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

Create an AlloyDB 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
) -> None

Create an AlloyDB 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_alloydb_pg.engine.Column] = "node_id",
    text_column: str = "text",
    embedding_column: str = "embedding",
    metadata_json_column: str = "li_metadata",
    metadata_columns: list[llama_index_alloydb_pg.engine.Column] = [],
    ref_doc_id_column: str = "ref_doc_id",
    node_column: str = "node_data",
    stores_text: bool = True,
    overwrite_existing: bool = False,
) -> None

Create an AlloyDB 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.