Stay organized with collections
Save and categorize content based on your preferences.
The google_ml_integration extension includes embedding functions in two different namespaces; public and google_ml. This page describes how to generate text embeddings using functions from these namespaces.
The embedding() function in the public schema can be used with any Vertex AI embedding model without registering the endpoint. If you want to pass any custom information such as the task type, register the endpoint, and then use the google_ml.embedding() function in the google_ml schema. For more information about registering an endpoint, see Register a model.
How embeddings work
Imagine a database running on AlloyDB with the following characteristics:
The database contains a table, items. Each row in this table describes an
item that your business sells.
The items table contains a column, complaints. This TEXT column stores
buyer complaints logged about each item.
The database integrates with the Vertex AI
Model Garden, giving it access to the gemini-embedding-001 English
models.
Even though this database stores complaints about items, these complaints are
stored as plain text, making them difficult to query. For example,
to see which items have the most complaints from customers who received the
wrong color of merchandise, then you can perform ordinary SQL queries on the
table, that look for various keyword matches. However, this approach only matches
rows that contain those exact keywords.
For example, a basic SQL query such as SELECT * FROM item WHERE complaints LIKE
"%wrong color%" doesn't return a row whose complaints field contains only
The picture shows a blue one, but the one I received was red.
SQL queries using LLM-powered embeddings can help return semantically similar responses for such queries. By
applying embeddings, you can query the table in this example for items whose
complaints have semantic similarity to a given text prompt, such as It was the
wrong color.
To generate embeddings, select one of the following schemas.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-26 UTC."],[[["\u003cp\u003eAlloyDB can be used as a large language model (LLM) tool to generate vector embeddings of text using a Vertex AI-hosted LLM.\u003c/p\u003e\n"],["\u003cp\u003eTo use this functionality, the \u003ccode\u003egoogle_ml_integration\u003c/code\u003e extension (version 1.2 or later) must be installed on the AlloyDB database, and you need to integrate with Vertex AI to access the \u003ccode\u003etext-embedding-005\u003c/code\u003e model.\u003c/p\u003e\n"],["\u003cp\u003eDatabase users need specific permissions granted to execute the \u003ccode\u003eembedding\u003c/code\u003e function, which is used to translate text into a vector embedding.\u003c/p\u003e\n"],["\u003cp\u003eThe generated embeddings, which are arrays of \u003ccode\u003ereal\u003c/code\u003e values, can be stored in a database table column of type \u003ccode\u003ereal[]\u003c/code\u003e and can be used with \u003ccode\u003epgvector\u003c/code\u003e functions for similarity searches.\u003c/p\u003e\n"],["\u003cp\u003eAlways specify a stable embeddings model, including a version tag, when using the \u003ccode\u003eembedding()\u003c/code\u003e function to avoid inconsistent results due to potential model version updates.\u003c/p\u003e\n"]]],[],null,["# Generate text embeddings\n\nThe `google_ml_integration` extension includes embedding functions in two different namespaces; `public` and `google_ml`. This page describes how to generate text embeddings using functions from these namespaces.\n\nThe `embedding()` function in the `public` schema can be used with any Vertex AI embedding model without registering the endpoint. If you want to pass any custom information such as the task type, register the endpoint, and then use the `google_ml.embedding()` function in the `google_ml` schema. For more information about registering an endpoint, see [Register a model](/alloydb/docs/ai/register-model-endpoint).\n\nHow embeddings work\n-------------------\n\nImagine a database running on AlloyDB with the following characteristics:\n\n- The database contains a table, `items`. Each row in this table describes an\n item that your business sells.\n\n- The `items` table contains a column, `complaints`. This `TEXT` column stores\n buyer complaints logged about each item.\n\n- The database integrates with the Vertex AI\n Model Garden, giving it access to the `gemini-embedding-001` English\n models.\n\nEven though this database stores complaints about items, these complaints are\nstored as plain text, making them difficult to query. For example,\nto see which items have the most complaints from customers who received the\nwrong color of merchandise, then you can perform ordinary SQL queries on the\ntable, that look for various keyword matches. However, this approach only matches\nrows that contain those exact keywords.\n\nFor example, a basic SQL query such as `SELECT * FROM item WHERE complaints LIKE\n\"%wrong color%\"` doesn't return a row whose `complaints` field contains only\n`The picture shows a blue one, but the one I received was red`.\n\nSQL queries using LLM-powered embeddings can help return semantically similar responses for such queries. By\napplying embeddings, you can query the table in this example for items whose\ncomplaints have semantic similarity to a given text prompt, such as `It was the\nwrong color`.\n\nTo generate embeddings, select one of the following schemas. \ngoogle_ml schema public schema\n\nWhat's next\n-----------\n\n- [Run vector similarity searches](/alloydb/docs/ai/run-vector-similarity-search).\n- [Learn how to build a smart shopping assistant with AlloyDB, pgvector, and model endpoint management](https://codelabs.developers.google.com/smart-shop-agent-alloydb#0).\n- [Create indexes and query vectors](/alloydb/docs/ai/store-index-query-vectors).\n- Learn [an example embedding workflow](/alloydb/docs/ai/example-embeddings)."]]