例如,SELECT * FROM item WHERE complaints LIKE
"%wrong color%" 等基本 SQL 查询不会返回 complaints 字段仅包含 The picture shows a blue one, but the one I received was red 的行。
使用 LLM 支持的嵌入的 SQL 查询可以帮助针对此类查询返回语义上相似的回答。通过应用嵌入,您可以在此示例的表中查询其投诉与给定文本提示(例如 It was the
wrong color)具有语义相似度的商品。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-25。"],[[["\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)."]]