Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
A extensão google_ml_integration inclui funções de incorporação em dois namespaces diferentes: public e google_ml. Nesta página, descrevemos como gerar incorporações de texto usando funções desses namespaces.
A função embedding() no esquema public pode ser usada com qualquer modelo de incorporação da Vertex AI sem registrar o endpoint. Se quiser transmitir informações personalizadas, como o tipo de tarefa, registre o endpoint e use a função google_ml.embedding() no esquema google_ml. Para mais informações sobre como registrar um endpoint, consulte Registrar um modelo.
Como as incorporações funcionam
Imagine um banco de dados em execução no AlloyDB com as seguintes características:
O banco de dados contém uma tabela, items. Cada linha nesta tabela descreve um
item que sua empresa vende.
A tabela items contém uma coluna, complaints. Essa coluna TEXT armazena
reclamações do comprador registradas sobre cada item.
O banco de dados se integra ao Model Garden da Vertex AI, concedendo acesso aos modelos em inglês gemini-embedding-001.
Embora esse banco de dados armazene reclamações sobre itens, elas são
armazenadas como texto simples, dificultando a consulta. Por exemplo, se você quiser saber quais itens têm mais reclamações de clientes que receberam a cor errada do produto, realize consultas SQL comuns na tabela, procurando várias correspondências de palavras-chave. No entanto, essa abordagem corresponde apenas às linhas que contêm essas palavras-chave exatas.
Por exemplo, uma consulta SQL básica, como SELECT * FROM item WHERE complaints LIKE
"%wrong color%", não retorna uma linha em que o campo complaints contém apenas The picture shows a blue one, but the one I received was red.
Consultas SQL que usam embeddings com tecnologia LLM podem ajudar a retornar respostas semanticamente semelhantes para essas consultas. Ao aplicar embeddings, é possível consultar a tabela neste exemplo para itens em que as reclamações têm semelhança semântica com um determinado comando de texto, como It was the
wrong color.
Para gerar embeddings, selecione um dos seguintes esquemas.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-08-25 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)."]]