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.Copy the service account key that you created to KEY_PATH. The key path should be a path on your host accessible, and owned, by the user that will run AlloyDB Omni.
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.
- Install the AlloyDB Omni RPM package.
Configure AlloyDB AI for AlloyDB Omni
After you install the AlloyDB Omni RPM package, complete the following steps to integrate AlloyDB AI:
Complete all of the steps listed in Set up Google Cloud to query remote models.
Move the service account key to AlloyDB Omni's data directory.
sudo mv KEY_PATH DATA_DIR/private-key.jsonReplace the following variables:
KEY_PATH: Path for your service account key file.DATA_DIR: Host directory path that your data is stored in.
Set the service account key's owner to
postgresand its permissions to600.sudo chown postgres:postgres DATA_DIR/private-key.json sudo chmod 600 DATA_DIR/private-key.jsonUpdate the AlloyDB Omni configuration by adding the following options to the
postgresql.conffile:sudo tee -a DATA_DIR/postgresql.conf << EOF omni_enable_ml_agent_process = 'on' omni_google_cloud_private_key_file_path = 'DATA_DIR/private-key.json' EOFRestart the AlloyDB Omni service.
sudo systemctl restart alloydbomni18
Connect using psql
To connect to the AlloyDB Omni database, run the following command:
sudo -u postgres /usr/lib/postgresql/18/bin/psql -U postgresVerify 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].