AlloyDB AI is a suite of features included with AlloyDB Omni that let you build enterprise generative AI applications. For more information about the AI/ML functionality of AlloyDB, see Build generative AI applications.
AlloyDB Omni with AlloyDB AI lets you query remote ML models using the google_ml_integration extension to work with online predictions and text embeddings generated from ML models. AlloyDB Omni with AlloyDB AI can also process vector embeddings from other content such as an image, for example, if you use the google_ml.predict_row interface and do the translation yourself in the query.
Set up Google Cloud to query remote models
If you want to query Vertex AI models, then you must configure an AlloyDB Omni service account with Vertex AI before installing AlloyDB Omni.
To set up a service account to query remote models, follow these steps:
Create a service account with Google Cloud. You grant this service account permissions to access Vertex AI in a later step.
Create a service account key and save it in JSON format to the
private-key.jsonfile, and download it.Store the key in a permanent location on your file system. It resides at this location for the lifetime of your AlloyDB Omni server.
Note its location on your file system; you need it for subsequent steps.
Enable the Vertex AI API in your Google Cloud project.
gcloud services enable aiplatform.googleapis.com
Add Vertex AI Identity and Access Management (IAM) permissions to the appropriate project and service account.
gcloud projects add-iam-policy-binding PROJECT_ID \ --member="serviceAccount:SERVICE_ACCOUNT_ID" \ --role="roles/aiplatform.user"Replace the following:
PROJECT_ID: ID of your Google Cloud project.SERVICE_ACCOUNT_ID: ID of the service account that you created in the step one. This includes the full@PROJECT_ID.iam.gserviceaccount.comsuffix. For example,my-service@my-project.iam.gserviceaccount.com.
Create a secret using the service account key path
To create a Secret resource based on the service account key downloaded in the preceding steps, complete the following steps:
Convert the contents of the
private-key.jsonfile to a base64 format.cat private-key.json | base64 -w 0The following is a sample response:
ewogICJ0eXBlIjogInNlcnZpY2VfYWNjb3VudCIsCiAgInByb2plY3RfaWQiOiAibXktcHJvamVjdC1pZ...[TRUNCATED]...CiAifQo=Create a
Secretresource and save it to a file, for example,secret.yaml:--- Secret: metadata: name: SECRET_NAME spec: type: Opaque data: private-key.json: BASE64_ENCODED_PRIVATE_KEYReplace the following variables:
SECRET_NAME: the name of the secret—for example,ai-secret-dbclustera.BASE64_ENCODED_PRIVATE_KEY: the base64-encoded contents of your service account key file generated in the earlier step.
Apply the
Secretresource using either of the following methods:alloydbctlalloydbctl apply -d "DEPLOYMENT_SPEC_PATH" -r "SECRET_SPECIFICATION"Replace the following variables:
DEPLOYMENT_SPEC_PATH: the path to your deployment specification directory.SECRET_SPECIFICATION: the path to theSecretresource YAML file that you created.
Ansible
Create a playbook for your database cluster specifications and save it as an
update.yamlfile.name: Update resource spec: - hosts: localhost vars: update_action: "update_resource_spec" ansible_user: ANSIBLE_USER ansible_ssh_private_key_file: ANSIBLE_SSH_PRIVATE_KEY_FILE roles: - role: google.alloydbomni_orchestrator.updateReplace the following variables:
ANSIBLE_USER: OS user that Ansible uses to log into your AlloyDB Omni nodes.ANSIBLE_SSH_PRIVATE_KEY_FILE: private key Ansible uses to connect to your AlloyDB Omni nodes using SSH.
Run your playbook.
ansible-playbook UPDATE_PLAYBOOK -i "DEPLOYMENT_SPEC_PATH" \ -e resource_spec="SECRET_SPECIFICATION"Replace the following variables:
UPDATE_PLAYBOOK: path to theupdate.yamlplaybook that you created for your database cluster.DEPLOYMENT_SPEC_PATH: path to the deployment specification you created in Install AlloyDB Omni components.SECRET_SPECIFICATION: the path to theSecretresource YAML file that you created.
Configure AlloyDB AI for AlloyDB Omni
After you provision your cluster, complete the following steps to integrate AlloyDB AI:
Complete all of the steps listed in Set up Google Cloud to query remote models.
Create a
Secretresource using steps in Create a secret using the service account key path.Update your
DBClusterresource specification to enable AlloyDB AI.Under the
googleMLExtensionfield, setenabledtotrueto let you query remote models. If you want to query Agent Platform models, you must also setvertexAIKeyRefto the name of theSecretyou created.--- DBCluster: metadata: name: DB_CLUSTER_NAME spec: primarySpec: features: googleMLExtension: enabled: true config: vertexAIKeyRef: secret.metadata.SECRET_NAME vertexAIRegion: VERTEX_AI_REGIONReplace the following:
DB_CLUSTER_NAME: the name of this database cluster.VERTEX_AI_REGION(Optional): the Agent Platform regional endpoint that you want to send your request to—for example,us-west4. The default value isus-central1.
Apply the updated
DBClusterresource specification using either of the following methods. The orchestrator automatically restarts the database to apply the extension settings.alloydbctlalloydbctl apply -d "DEPLOYMENT_SPEC_PATH" -r "DBCLUSTER_SPECIFICATION"Replace the following variables:
DEPLOYMENT_SPEC_PATH: the path to your deployment specification directory.DBCLUSTER_SPECIFICATION: the path to theDBClusterresource specification file that you modified.
Ansible
Create a playbook for your database cluster specifications and save it as an
update.yamlfile.name: Update resource spec: - hosts: localhost vars: update_action: "update_resource_spec" ansible_user: ANSIBLE_USER ansible_ssh_private_key_file: ANSIBLE_SSH_PRIVATE_KEY_FILE roles: - role: google.alloydbomni_orchestrator.updateReplace the following variables:
ANSIBLE_USER: the OS user that Ansible uses to log into your AlloyDB Omni nodes.ANSIBLE_SSH_PRIVATE_KEY_FILE: the private key Ansible uses to connect to your AlloyDB Omni nodes using SSH.
Run your playbook.
ansible-playbook UPDATE_PLAYBOOK -i "DEPLOYMENT_SPEC_PATH" \ -e resource_spec="DBCLUSTER_SPECIFICATION"Replace the following variables:
UPDATE_PLAYBOOK: the path to theupdate.yamlplaybook that you created for your database cluster.DEPLOYMENT_SPEC_PATH: the path to the deployment specification you created in Install AlloyDB Omni components.DBCLUSTER_SPECIFICATION: the path to your cluster specifications.
Connect to your database
Connect to your database cluster. For instructions on how to connect to the orchestrator using psql, see Run and connect to AlloyDB Omni.
Verify AlloyDB Omni with AlloyDB AI installation
To verify your installation is successful and uses model prediction, enter the following:
CREATE EXTENSION IF NOT EXISTS google_ml_integration CASCADE;
SELECT array_dims(embedding('text-embedding-005', 'AlloyDB AI')::real[]);
The output looks similar to the following:
array_dims
------------
[1:768]
(1 row)
In the previous query, the embedding() call generates embeddings for the input text AlloyDB AI.
array_dims returns the dimensions of the array returned by embedding().
Since the text-embedding-005 model returns an output with 768 dimensions, the output is [768].