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],
)PGEngine 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. |
_aapply_vector_assist_spec
_aapply_vector_assist_spec(
table_name: str,
embedding_column: str,
schema_name: str = "public",
spec_id: typing.Optional[str] = None,
) -> typing.Optional[bool]Call vector_assist.apply_spec.
See aapply_vector_assist_spec for the full description.
_adefine_vector_assist_spec
_adefine_vector_assist_spec(
table_name: str,
embedding_column: str,
schema_name: str = "public",
embedding_model: typing.Optional[str] = None,
) -> list[dict]Call vector_assist.define_spec.
See adefine_vector_assist_spec for the full description.
_aenable_columnar_engine
_aenable_columnar_engine(
table_name: str,
columns: typing.Optional[list[str]] = None,
schema_name: str = "public",
) -> NoneCall google_columnar_engine_add for a table.
See aenable_columnar_engine for the full description.
_afetch_latest_vector_assist_spec_id
_afetch_latest_vector_assist_spec_id(
conn: sqlalchemy.ext.asyncio.engine.AsyncConnection,
table_name: str,
embedding_column: str,
schema_name: str,
) -> typing.Optional[str]Return the id of the most recently defined spec, or None.
_aforecast
_aforecast(
model_id: str,
*,
timestamp_column: str,
data_column: str,
horizon: int,
conf_level: float,
table_name: typing.Optional[str] = None,
schema_name: str = "public",
query: typing.Optional[str] = None
) -> list[dict]Run google_ml.forecast on the engine's loop. See aforecast.
_aget_vector_assist_recommendations
_aget_vector_assist_recommendations(
table_name: str, embedding_column: str, schema_name: str = "public"
) -> list[dict]Call vector_assist.get_recommendations for the latest spec.
See aget_vector_assist_recommendations for the full description.
_ainit_chat_history_table
_ainit_chat_history_table(table_name: str, schema_name: str = "public") -> NoneCreate an AlloyDB table to save chat history messages.
| Parameters | |
|---|---|
| Name | Description |
table_name |
str
The table name to store chat history. |
schema_name |
str
The schema name to store the chat history table. Default: "public". |
_ainit_checkpoint_table
_ainit_checkpoint_table(
table_name: str = "checkpoints", schema_name: str = "public"
) -> NoneCreate AlloyDB tables to save checkpoints.
| Parameter | |
|---|---|
| Name | Description |
schema_name |
str
The schema name to store the checkpoint tables. Default: "public". |
_ainit_document_table
_ainit_document_table(
table_name: str,
schema_name: str = "public",
content_column: str = "page_content",
metadata_columns: typing.Optional[list[langchain_postgres.v2.engine.Column]] = None,
metadata_json_column: str = "langchain_metadata",
store_metadata: bool = True,
) -> NoneCreates a table for storing LangChain documents.
| Parameters | |
|---|---|
| Name | Description |
table_name |
str
The PgSQL database table name. |
schema_name |
str
The schema name. Default: "public". |
content_column |
str
Name of the column to store document content. Default: "page_content". |
metadata_columns |
Optional[list[Column]]
A list of Columns to create for custom metadata. Optional. |
metadata_json_column |
str
The column to store extra metadata in JSON format. Default: "langchain_metadata". Optional. |
store_metadata |
bool
Whether to store extra metadata in a metadata column if not described in 'metadata' field list (Default: True). |
_ainitialize_embeddings
_ainitialize_embeddings(
table_name: str,
model_id: str,
content_column: str,
embedding_column: str,
schema_name: str = "public",
overwrite: bool = False,
) -> NoneCall ai.initialize_embeddings for a table.
See ainitialize_embeddings for the full description.
_ais_function_missing
_ais_function_missing(
error: BaseException,
sqlstates: set[str],
schema: typing.Optional[str],
function: str,
) -> boolReturn True if error means the extension function is not installed.
The error must carry one of sqlstates and function (in
schema, or in any schema if None) must be absent from the catalog.
The same SQLSTATEs are raised for other missing objects (for example a
nonexistent schema passed by the caller), which must not be reported as
a missing extension. If the catalog lookup itself fails, the SQLSTATE
alone decides.
_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. |
_arun_auto_columnarization
_arun_auto_columnarization() -> list[dict]Call google_columnar_engine_recommend('AUTO_COLUMNARIZATION').
See arun_auto_columnarization for the full description.
_create
_create(
project_id: str,
region: str,
cluster: str,
instance: str,
database: str,
ip_type: typing.Union[str, google.cloud.alloydbconnector.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,
engine_args: typing.Optional[typing.Mapping[str, typing.Any]] = None,
) -> langchain_google_alloydb_pg.engine.AlloyDBEngineCreate 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. |
engine_args |
Optional[Mapping[str, Any]]
Additional arguments that are passed directly to |
| Exceptions | |
|---|---|
| Type | Description |
ValueError |
Raises error if only one of 'user' or 'password' is specified. |
| Returns | |
|---|---|
| Type | Description |
AlloyDBEngine |
A newly created AlloyDBEngine instance. |
aapply_vector_assist_spec
aapply_vector_assist_spec(
table_name: str,
embedding_column: str,
schema_name: str = "public",
spec_id: typing.Optional[str] = None,
) -> typing.Optional[bool]Apply a Vector Assist spec.
Applying a spec executes every recommendation of the spec. Depending on
the spec these can include database-wide statements (for example
ALTER EXTENSION vector UPDATE) in addition to table-level ones such
as CREATE INDEX. Review them with
aget_vector_assist_recommendations first.
| Parameters | |
|---|---|
| Name | Description |
table_name |
str
The table the spec was defined for. |
embedding_column |
str
The vector column the spec was defined for. |
schema_name |
str
The schema of the table. Default: "public". |
spec_id |
Optional[str]
The spec to apply. If None, the most recently defined spec for |
| Exceptions | |
|---|---|
| Type | Description |
ValueError |
If table_name, embedding_column or schema_name is empty, or if spec_id is None and no spec has been defined for the table and column. |
RuntimeError |
If the Vector Assist extension is not installed. |
| Returns | |
|---|---|
| Type | Description |
Optional[bool] |
The value returned by vector_assist.apply_spec: True if all recommendations were applied, False otherwise, or None if the spec has no recommendations. |
adefine_vector_assist_spec
adefine_vector_assist_spec(
table_name: str,
embedding_column: str,
schema_name: str = "public",
embedding_model: typing.Optional[str] = None,
) -> list[dict]Define a Vector Assist spec for a table's vector column.
| Parameters | |
|---|---|
| Name | Description |
table_name |
str
The table containing the vector column. |
embedding_column |
str
The vector column. |
schema_name |
str
The schema of the table. Default: "public". |
embedding_model |
Optional[str]
The model ID (as registered in |
| Exceptions | |
|---|---|
| Type | Description |
ValueError |
If table_name, embedding_column or schema_name is empty. |
RuntimeError |
If the Vector Assist extension is not installed. |
| Returns | |
|---|---|
| Type | Description |
list[dict] |
The recommendation rows returned by vector_assist.define_spec (columns of vector_assist.recommendations, e.g. recommendation_id, vector_spec_id, query). |
aenable_columnar_engine
aenable_columnar_engine(
table_name: str,
columns: typing.Optional[list[str]] = None,
schema_name: str = "public",
) -> NoneAdd a table's columns to the AlloyDB columnar engine.
Calls google_columnar_engine_add. This is a one-time action on
the node the engine is connected to: the columns are not added on
other nodes (for example read pool instances), and they are not kept
across instance restarts. To keep columns in the columnar engine
durably, list them in the google_columnar_engine.relations
instance flag instead.
The server reports most failures (columnar engine disabled, lock not available, ...) as a WARNING and returns 0 instead of raising; when it returns 0 this method logs a warning. A 0 result can also mean the populated data rounds down to 0 MB (very small tables), so it is not treated as an error.
| Parameters | |
|---|---|
| Name | Description |
table_name |
str
The table to add to the columnar engine. |
columns |
Optional[list[str]]
The columns to add. If None, every column of the table is added except pgvector-typed columns ( |
schema_name |
str
The schema of the table. Default: "public". |
| Exceptions | |
|---|---|
| Type | Description |
ValueError |
If table_name or schema_name is empty, if columns is not a list of strings or is an empty list, if a column name contains ',' or ':' or has leading/trailing whitespace (the columnar engine's column list format cannot express such names), or if columns is None and the table has no eligible column (or is not visible). |
RuntimeError |
If the columnar engine is not available on the instance. |
aforecast
aforecast(
model_id: str,
*,
timestamp_column: str,
data_column: str,
horizon: int,
conf_level: float,
table_name: typing.Optional[str] = None,
schema_name: str = "public",
query: typing.Optional[str] = None
) -> list[dict]Asynchronously get forecasting from AlloyDB AI.
Requires the google_ml_integration extension (google_ml.forecast)
in the database. All arguments after model_id are keyword-only.
Names and values are passed to the server exactly as given: they are
not stripped, and quoted names are case-sensitive.
| Exceptions | |
|---|---|
| Type | Description |
ValueError |
If neither or both of table_name and query are given, if model_id, timestamp_column, data_column, table_name, schema_name or query is empty, blank or not a string, if horizon is not between 1 and 128, or if conf_level is not strictly between 0 and 1. |
sqlalchemy.exc.DBAPIError |
Database errors (for example, a missing extension or table, an unregistered model, forecasting disabled on the instance, or an error from the model endpoint) are raised unchanged. |
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.alloydbconnector.enums.IPTypes
] = IPTypes.PUBLIC,
iam_account_email: typing.Optional[str] = None,
engine_args: typing.Optional[typing.Mapping[str, typing.Any]] = None,
) -> langchain_google_alloydb_pg.engine.AlloyDBEngineCreate 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. |
engine_args |
Optional[Mapping[str, Any]]
Additional arguments that are passed directly to |
| Returns | |
|---|---|
| Type | Description |
AlloyDBEngine |
A newly created AlloyDBEngine instance. |
aget_vector_assist_recommendations
aget_vector_assist_recommendations(
table_name: str, embedding_column: str, schema_name: str = "public"
) -> list[dict]Get the recommendations of the latest Vector Assist spec.
Uses the most recently defined spec for schema_name.table_name
and embedding_column. No new spec is defined.
| Parameters | |
|---|---|
| Name | Description |
table_name |
str
The table the spec was defined for. |
embedding_column |
str
The vector column the spec was defined for. |
schema_name |
str
The schema of the table. Default: "public". |
| Exceptions | |
|---|---|
| Type | Description |
ValueError |
If table_name, embedding_column or schema_name is empty. |
RuntimeError |
If the Vector Assist extension is not installed. |
| Returns | |
|---|---|
| Type | Description |
list[dict] |
Rows of vector_assist.get_recommendations, or an empty list (and a logged warning) if no spec has been defined. |
ainit_chat_history_table
ainit_chat_history_table(table_name: str, schema_name: str = "public") -> NoneCreate an AlloyDB table to save chat history messages.
| Parameters | |
|---|---|
| Name | Description |
table_name |
str
The table name to store chat history. |
schema_name |
str
The schema name to store chat history table. Default: "public". |
ainit_checkpoint_table
ainit_checkpoint_table(
table_name: str = "checkpoints", schema_name: str = "public"
) -> NoneCreate an AlloyDB table to save checkpoint messages.
| Parameter | |
|---|---|
| Name | Description |
schema_name |
str
The schema name to store checkpoint tables. Default: "public". |
ainit_document_table
ainit_document_table(
table_name: str,
schema_name: str = "public",
content_column: str = "page_content",
metadata_columns: typing.Optional[list[langchain_postgres.v2.engine.Column]] = None,
metadata_json_column: str = "langchain_metadata",
store_metadata: bool = True,
) -> NoneCreates a table for storing LangChain documents.
| Parameters | |
|---|---|
| Name | Description |
table_name |
str
The PgSQL database table name. |
schema_name |
str
The schema name. Default: "public". |
content_column |
str
Name of the column to store document content. Default: "page_content". |
metadata_columns |
Optional[list[Column]]
A list of SQLAlchemy Columns to create for custom metadata. Optional. |
metadata_json_column |
str
The column to store extra metadata in JSON format. Default: "langchain_metadata". Optional. |
store_metadata |
bool
Whether to store extra metadata in a metadata column if not described in 'metadata' field list (Default: True). |
| Exceptions | |
|---|---|
| Type | Description |
DuplicateTableErro |
|
ainitialize_embeddings
ainitialize_embeddings(
table_name: str,
model_id: str,
content_column: str,
embedding_column: str,
schema_name: str = "public",
overwrite: bool = False,
) -> NoneGenerate and manage embeddings for a table with AlloyDB AI.
Calls ai.initialize_embeddings, which registers the table for
automatic embedding management and then generates an embedding of
content_column into embedding_column for every row, in
batches, committing as it goes. Existing values in
embedding_column are replaced, so by default this method refuses
to run if the column already contains a non-NULL value (see
overwrite).
embedding_column must already exist as a vector(N) column,
where N is the model's output dimension (created for example with
ainit_vectorstore_table); it is not created. If the table
backs a vector store, use the same model as the vector store's
embedding service: queries are embedded by that service, so
embeddings from a different model make similarity search results
meaningless. Use a separate column for a different model.
The call runs on its own autocommit connection and cannot be part of
a caller's transaction. It requires the
google_ml_integration.enable_model_support and
google_ml_integration.enable_faster_embedding_generation instance
flags; the server's error is raised unchanged if they are off.
The registration is committed before any embedding is generated and
is not undone if the call fails later (for example because the model
endpoint rejects the request). It adds a hidden
google_ml_track_stale_embedding_<n> column, a trigger and an index
to the table. Once the table is registered, calling this method again
for the same table and embedding column fails with "already
initialized". ai.drop_embedding_config removes the registration
and these objects (the generated embeddings are kept);
ai.refresh_embeddings completes an interrupted run.
| Parameters | |
|---|---|
| Name | Description |
table_name |
str
The table to generate embeddings for. |
model_id |
str
The ID of the embedding model, as registered in |
content_column |
str
The column containing the text to embed. |
embedding_column |
str
The existing |
schema_name |
str
The schema of the table. Default: "public". |
overwrite |
bool
If False (the default), raise ValueError when |
| Exceptions | |
|---|---|
| Type | Description |
ValueError |
If an argument is empty, or if overwrite is False and embedding_column already contains embeddings. |
RuntimeError |
If ai.initialize_embeddings is not available (google_ml_integration missing or older than 1.5.6). |
sqlalchemy.exc.DBAPIError |
Other database errors (for example a missing table or column, a non-vector embedding column, or an error from the model endpoint) are re-raised unchanged. |
apply_vector_assist_spec
apply_vector_assist_spec(
table_name: str,
embedding_column: str,
schema_name: str = "public",
spec_id: typing.Optional[str] = None,
) -> typing.Optional[bool]Apply a Vector Assist spec.
Applying a spec executes every recommendation of the spec, which can
include database-wide statements. Review them with
get_vector_assist_recommendations first.
| Parameters | |
|---|---|
| Name | Description |
table_name |
str
The table the spec was defined for. |
embedding_column |
str
The vector column the spec was defined for. |
schema_name |
str
The schema of the table. Default: "public". |
spec_id |
Optional[str]
The spec to apply. If None, the most recently defined spec for the table and column is applied. |
| Exceptions | |
|---|---|
| Type | Description |
ValueError |
If an argument is empty, or if spec_id is None and no spec has been defined for the table and column. |
RuntimeError |
If the Vector Assist extension is not installed. |
| Returns | |
|---|---|
| Type | Description |
Optional[bool] |
The value returned by vector_assist.apply_spec. |
arun_auto_columnarization
arun_auto_columnarization() -> list[dict]Run the columnar engine's auto-columnarization once.
Calls
google_columnar_engine_recommend(mode => 'AUTO_COLUMNARIZATION'),
which analyzes the workload of the whole instance and populates the
columnar engine with the columns it recommends, for any table. This
is instance-wide and runs once; it does not create a recurring
schedule (that is the instance's own auto-columnarization setting).
| Exceptions | |
|---|---|
| Type | Description |
RuntimeError |
If the columnar engine is not available on the instance. |
| Returns | |
|---|---|
| Type | Description |
list[dict] |
The rows returned by google_columnar_engine_recommend, each with total_size_in_mb (INT8) and columns (TEXT, the recommended columns). |
define_vector_assist_spec
define_vector_assist_spec(
table_name: str,
embedding_column: str,
schema_name: str = "public",
embedding_model: typing.Optional[str] = None,
) -> list[dict]Define a Vector Assist spec for a table's vector column.
| Parameters | |
|---|---|
| Name | Description |
table_name |
str
The table containing the vector column. |
embedding_column |
str
The vector column. |
schema_name |
str
The schema of the table. Default: "public". |
embedding_model |
Optional[str]
The model ID that was used to generate the embeddings in the table. Vector Assist requires it when the table already contains embeddings. Defaults to None. |
| Exceptions | |
|---|---|
| Type | Description |
ValueError |
If table_name, embedding_column or schema_name is empty. |
RuntimeError |
If the Vector Assist extension is not installed. |
| Returns | |
|---|---|
| Type | Description |
list[dict] |
The recommendation rows returned by vector_assist.define_spec. |
enable_columnar_engine
enable_columnar_engine(
table_name: str,
columns: typing.Optional[list[str]] = None,
schema_name: str = "public",
) -> NoneAdd a table's columns to the AlloyDB columnar engine.
Calls google_columnar_engine_add. This is a one-time action on
the connected node; the columns are not kept across instance
restarts (use the google_columnar_engine.relations instance flag
for that). Logs a warning if the server returns 0. See
aenable_columnar_engine for details.
| Parameters | |
|---|---|
| Name | Description |
table_name |
str
The table to add to the columnar engine. |
columns |
Optional[list[str]]
The columns to add. If None, every column except pgvector-typed columns and the |
schema_name |
str
The schema of the table. Default: "public". |
| Exceptions | |
|---|---|
| Type | Description |
ValueError |
If an argument is empty or invalid, or if columns is None and the table has no eligible column. |
RuntimeError |
If the columnar engine is not available on the instance. |
forecast
forecast(
model_id: str,
*,
timestamp_column: str,
data_column: str,
horizon: int,
conf_level: float,
table_name: typing.Optional[str] = None,
schema_name: str = "public",
query: typing.Optional[str] = None
) -> list[dict]Synchronously get forecasting from AlloyDB AI.
Requires the google_ml_integration extension (google_ml.forecast)
in the database. All arguments after model_id are keyword-only.
Names and values are passed to the server exactly as given: they are
not stripped, and quoted names are case-sensitive.
| Exceptions | |
|---|---|
| Type | Description |
ValueError |
If neither or both of table_name and query are given, if model_id, timestamp_column, data_column, table_name, schema_name or query is empty, blank or not a string, if horizon is not between 1 and 128, or if conf_level is not strictly between 0 and 1. |
sqlalchemy.exc.DBAPIError |
Database errors (for example, a missing extension or table, an unregistered model, forecasting disabled on the instance, or an error from the model endpoint) are raised unchanged. |
from_connection_string
from_connection_string(
url: str | sqlalchemy.engine.url.URL, **kwargs: typing.Any
) -> langchain_google_alloydb_pg.engine.AlloyDBEngineCreate an AlloyDBEngine instance from arguments.
| Parameter | |
|---|---|
| Name | Description |
url |
str URL
The URL used to connect to a database. |
| Exceptions | |
|---|---|
| Type | Description |
ValueError |
If not all database url arguments are specified. |
| Returns | |
|---|---|
| Type | Description |
AlloyDBEngine |
A newly created AlloyDBEngine instance. |
from_engine_args
from_engine_args(
url: str | sqlalchemy.engine.url.URL, **kwargs: typing.Any
) -> langchain_google_alloydb_pg.engine.AlloyDBEngineCreate an AlloyDBEngine instance from arguments.
| Parameter | |
|---|---|
| Name | Description |
url |
str URL
The URL used to connect to a database. |
| Exceptions | |
|---|---|
| Type | Description |
ValueError |
If not all database url arguments are specified. |
| Returns | |
|---|---|
| Type | Description |
AlloyDBEngine |
A newly created AlloyDBEngine instance. |
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.alloydbconnector.enums.IPTypes
] = IPTypes.PUBLIC,
iam_account_email: typing.Optional[str] = None,
engine_args: typing.Optional[typing.Mapping[str, typing.Any]] = None,
) -> langchain_google_alloydb_pg.engine.AlloyDBEngineCreate 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. |
engine_args |
Optional[Mapping[str, Any]]
Additional arguments that are passed directly to |
| Returns | |
|---|---|
| Type | Description |
AlloyDBEngine |
A newly created AlloyDBEngine instance. |
get_vector_assist_recommendations
get_vector_assist_recommendations(
table_name: str, embedding_column: str, schema_name: str = "public"
) -> list[dict]Get the recommendations of the latest Vector Assist spec.
| Parameters | |
|---|---|
| Name | Description |
table_name |
str
The table the spec was defined for. |
embedding_column |
str
The vector column the spec was defined for. |
schema_name |
str
The schema of the table. Default: "public". |
| Exceptions | |
|---|---|
| Type | Description |
ValueError |
If table_name, embedding_column or schema_name is empty. |
RuntimeError |
If the Vector Assist extension is not installed. |
| Returns | |
|---|---|
| Type | Description |
list[dict] |
Rows of vector_assist.get_recommendations, or an empty list if no spec has been defined. |
init_chat_history_table
init_chat_history_table(table_name: str, schema_name: str = "public") -> NoneCreate an AlloyDB table to store chat history.
| Parameters | |
|---|---|
| Name | Description |
table_name |
str
Table name to store chat history. |
schema_name |
str
The schema name to store chat history table. Default: "public". |
init_checkpoint_table
init_checkpoint_table(
table_name: str = "checkpoints", schema_name: str = "public"
) -> NoneCreate AlloyDB tables to store checkpoints.
| Parameters | |
|---|---|
| Name | Description |
table_name |
str
The checkpoint table name. Default: "checkpoints". |
schema_name |
str
The schema name to store checkpoint tables. Default: "public". |
init_document_table
init_document_table(
table_name: str,
schema_name: str = "public",
content_column: str = "page_content",
metadata_columns: typing.Optional[list[langchain_postgres.v2.engine.Column]] = None,
metadata_json_column: str = "langchain_metadata",
store_metadata: bool = True,
) -> NoneCreates a table for storing LangChain documents.
| Parameters | |
|---|---|
| Name | Description |
table_name |
str
The PgSQL database table name. |
schema_name |
str
The schema name to store the PgSQL database table. Default: "public". |
content_column |
str
Name of the column to store document content. Default: "page_content". |
metadata_columns |
Optional[list[Column]]
A list of SQLAlchemy Columns to create for custom metadata. Optional. |
metadata_json_column |
str
The column to store extra metadata in JSON format. Default: "langchain_metadata". Optional. |
store_metadata |
bool
Whether to store extra metadata in a metadata column if not described in 'metadata' field list (Default: True). |
| Exceptions | |
|---|---|
| Type | Description |
DuplicateTableErro |
|
initialize_embeddings
initialize_embeddings(
table_name: str,
model_id: str,
content_column: str,
embedding_column: str,
schema_name: str = "public",
overwrite: bool = False,
) -> NoneGenerate and manage embeddings for a table with AlloyDB AI.
Calls ai.initialize_embeddings, which generates an embedding for
every row, replacing existing values in embedding_column. By
default this method refuses to run if the column already contains a
non-NULL value (see overwrite). embedding_column must already
exist as a vector(N) column. If the table backs a vector store,
use the same model as its embedding service. The call adds a hidden
google_ml_track_stale_embedding_<n> column, a trigger and an index
to the table (removed by ai.drop_embedding_config). See
ainitialize_embeddings for details.
| Parameters | |
|---|---|
| Name | Description |
table_name |
str
The table to generate embeddings for. |
model_id |
str
The ID of the embedding model, as registered in |
content_column |
str
The column containing the text to embed. |
embedding_column |
str
The existing |
schema_name |
str
The schema of the table. Default: "public". |
overwrite |
bool
If False (the default), raise ValueError when |
| Exceptions | |
|---|---|
| Type | Description |
ValueError |
If an argument is empty, or if overwrite is False and embedding_column already contains embeddings. |
RuntimeError |
If ai.initialize_embeddings is not available (google_ml_integration missing or older than 1.5.6). |
sqlalchemy.exc.DBAPIError |
Other database errors are re-raised unchanged. |
run_auto_columnarization
run_auto_columnarization() -> list[dict]Run the columnar engine's auto-columnarization once.
Instance-wide and one-time. See arun_auto_columnarization.
| Exceptions | |
|---|---|
| Type | Description |
RuntimeError |
If the columnar engine is not available on the instance. |
| Returns | |
|---|---|
| Type | Description |
list[dict] |
The rows returned by google_columnar_engine_recommend, each with total_size_in_mb and columns. |