Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Ekstensi google_ml_integration mencakup fungsi penyematan dalam dua namespace yang berbeda; public dan google_ml. Halaman ini menjelaskan cara membuat sematan teks menggunakan fungsi dari namespace ini.
Fungsi embedding() dalam skema public dapat digunakan dengan model embedding Vertex AI apa pun tanpa mendaftarkan endpoint. Jika Anda ingin meneruskan informasi kustom seperti jenis tugas, daftarkan endpoint, lalu gunakan fungsi google_ml.embedding() dalam skema google_ml. Untuk mengetahui informasi selengkapnya tentang cara mendaftarkan endpoint, lihat Mendaftarkan model.
Cara kerja penyematan
Bayangkan database yang berjalan di AlloyDB dengan karakteristik berikut:
Database berisi tabel, items. Setiap baris dalam tabel ini menjelaskan item yang dijual bisnis Anda.
Tabel items berisi kolom, complaints. Kolom TEXT ini menyimpan
keluhan pembeli yang dicatat tentang setiap item.
Database ini terintegrasi dengan Vertex AI Model Garden, sehingga memberikan akses ke model berbahasa Inggris gemini-embedding-001.
Meskipun database ini menyimpan keluhan tentang item, keluhan ini disimpan sebagai teks biasa, sehingga sulit untuk dikueri. Misalnya, untuk melihat item mana yang paling banyak dikeluhkan oleh pelanggan yang menerima warna barang yang salah, Anda dapat menjalankan kueri SQL biasa pada tabel, yang mencari berbagai kecocokan kata kunci. Namun, pendekatan ini hanya mencocokkan baris yang berisi kata kunci persis tersebut.
Misalnya, kueri SQL dasar seperti SELECT * FROM item WHERE complaints LIKE
"%wrong color%" tidak menampilkan baris yang kolom complaints-nya hanya berisi
The picture shows a blue one, but the one I received was red.
Kueri SQL yang menggunakan embedding yang didukung LLM dapat membantu menampilkan respons yang mirip secara semantik untuk kueri tersebut. Dengan
menerapkan embedding, Anda dapat membuat kueri tabel dalam contoh ini untuk item yang keluhannya memiliki kemiripan semantik dengan perintah teks tertentu, seperti It was the
wrong color.
Untuk membuat embedding, pilih salah satu skema berikut.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-09-03 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)."]]