google_ml_integration 확장 프로그램에는 public 및 google_ml의 두 가지 네임스페이스에 삽입 함수가 포함되어 있습니다. 이 페이지에서는 이러한 네임스페이스의 함수를 사용하여 텍스트 임베딩을 생성하는 방법을 설명합니다.
public 스키마의 embedding() 함수는 엔드포인트를 등록하지 않고도 모든 Vertex AI 임베딩 모델과 함께 사용할 수 있습니다. 작업 유형과 같은 맞춤 정보를 전달하려면 엔드포인트를 등록한 다음 google_ml 스키마에서 google_ml.embedding() 함수를 사용하세요. 엔드포인트 등록에 관한 자세한 내용은 모델 등록을 참고하세요.
삽입 작동 방식
다음과 같은 특성을 가진 AlloyDB에서 실행되는 데이터베이스를 가정해 보세요.
데이터베이스에는 items 테이블이 포함되어 있습니다. 이 테이블의 각 행은 비즈니스에서 판매하는 상품을 설명합니다.
items 테이블에는 complaints 열이 포함되어 있습니다. 이 TEXT 열에는 각 항목에 대해 로깅된 구매자 불만사항이 저장됩니다.
데이터베이스는 Vertex AI Model Garden과 통합되어 gemini-embedding-001 영어 모델에 대한 액세스 권한을 부여합니다.
이 데이터베이스에 항목에 대한 불만사항이 저장되어 있지만 이러한 불만사항은 일반 텍스트로 저장되므로 쿼리하기가 어렵습니다. 예를 들어 잘못된 색상의 상품을 받은 고객이 불만사항을 가장 많이 제기한 상품이 무엇인지 확인하려면 테이블에서 일반 SQL 쿼리를 수행하여 다양한 키워드 검색 유형을 찾으면 됩니다. 하지만 이 방법은 정확한 키워드가 포함된 행만 일치시킵니다.
예를 들어 SELECT * FROM item WHERE complaints LIKE
"%wrong color%"와 같은 기본 SQL 쿼리는 The picture shows a blue one, but the one I received was red만 포함된 complaints 필드가 있는 행을 반환하지 않습니다.
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"]],["최종 업데이트: 2025-09-04(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)."]]