Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Halaman ini menunjukkan cara menggunakan AlloyDB sebagai database vektor dengan ekstensi vector yang menyertakan fungsi dan operator pgvector. Fungsi dan operator ini memungkinkan Anda menyimpan penyematan sebagai nilai vektor.
Ekstensi database yang diperlukan
Gunakan ekstensi vector, versi 0.5.0.google-1 atau yang lebih baru, yang menyertakan
fungsi dan operator pgvector, untuk menyimpan penyematan yang dihasilkan sebagai nilai vector. Ini adalah versi pgvector yang telah diperluas oleh Google dengan pengoptimalan khusus untuk AlloyDB.
CREATEEXTENSIONIFNOTEXISTSvector;
Menyimpan embedding yang dibuat
Pastikan Anda telah membuat tabel di database AlloyDB.
Untuk menyimpan embedding vektor, lakukan hal berikut:
Buat kolom vector[] di tabel untuk menyimpan penyematan:
PATH_TO_VECTOR_CSV: jalur lengkap tempat Anda menyimpan file .csv.
Setelah menyimpan penyematan, Anda dapat menggunakan ekstensi vector atau ekstensi alloydb_scann untuk membuat indeks guna meningkatkan performa kueri.
[[["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 vector database by utilizing the \u003ccode\u003evector\u003c/code\u003e extension, which includes \u003ccode\u003epgvector\u003c/code\u003e functions and operators for storing embeddings.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003evector\u003c/code\u003e extension, version \u003ccode\u003e0.5.0.google-1\u003c/code\u003e or later, is required to store embeddings as \u003ccode\u003evector\u003c/code\u003e values, which includes optimizations specific to AlloyDB.\u003c/p\u003e\n"],["\u003cp\u003eTo store vector embeddings, you must add a \u003ccode\u003evector[]\u003c/code\u003e column to your existing AlloyDB database table, specifying the number of dimensions supported by the model.\u003c/p\u003e\n"],["\u003cp\u003eAfter creating the \u003ccode\u003evector[]\u003c/code\u003e column, you can copy vector data into it from a source such as a CSV file.\u003c/p\u003e\n"],["\u003cp\u003eYou can create indexes for faster query performance using the \u003ccode\u003evector\u003c/code\u003e or \u003ccode\u003ealloydb_scann\u003c/code\u003e extensions after the embeddings are stored.\u003c/p\u003e\n"]]],[],null,["# Store vector embeddings\n\nThis page shows you how to use AlloyDB as a vector database with\nthe `vector` extension that includes `pgvector` functions and operators. These\nfunctions and operators let you store embeddings as vector values.\n\nRequired database extension\n---------------------------\n\nUse the `vector` extension, version `0.5.0.google-1` or later, which includes\n`pgvector` functions and operators, to store generated embeddings as `vector` values. This\nis a version of `pgvector` that Google has extended with optimizations specific\nto AlloyDB. \n\n CREATE EXTENSION IF NOT EXISTS vector;\n\nStore generated embeddings\n--------------------------\n\nEnsure that you have already created a table in your AlloyDB database.\n| **Note:** If your application uses the LangChain framework and your dataset has `O(100k)` embeddings, we recommend that you use the `AlloyDBVectorStore` vector class included in the AlloyDB LangChain library to store your embeddings. For more information, see [Build LLM-powered applications using\n| LangChain](/alloydb/docs/ai/langchain#vector_store_procedure_guide).\n\nTo store vector embeddings, do the following:\n\n1. Create a `vector[]` column in your table to store your embeddings:\n\n ALTER TABLE \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-k\"\u003eTABLE\u003c/span\u003e\u003c/var\u003e ADD COLUMN \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eEMBEDDING_COLUMN\u003c/span\u003e\u003c/var\u003e vector(\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eDIMENSIONS\u003c/span\u003e\u003c/var\u003e);\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eTABLE\u003c/var\u003e: the table name\n\n - \u003cvar translate=\"no\"\u003eEMBEDDING_COLUMN\u003c/var\u003e: the name of the new embedding column\n\n - \u003cvar translate=\"no\"\u003eDIMENSIONS\u003c/var\u003e: the number of dimensions that the model\n supports.\n\n For example, if you are using one of the `text-embedding` English models---for example, `text-embedding-005` with Vertex AI, specify `768`.\n2. Copy the vectors to the vector column. The following example assumes your embeddings are available in a CSV file:\n\n COPY \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-k\"\u003eTABLE\u003c/span\u003e\u003c/var\u003e (\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eEMBEDDING_COLUMN\u003c/span\u003e\u003c/var\u003e) FROM '\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003ePATH_TO_VECTOR_CSV\u003c/span\u003e\u003c/var\u003e (FORMAT CSV);\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003ePATH_TO_VECTOR_CSV\u003c/var\u003e: the full path of where you have stored your `.csv` file.\n\nAfter you store the embeddings, you can use the `vector` extension or the `alloydb_scann`\nextension to create indexes for faster query performance.\n\nWhat's next\n-----------\n\n- [Create indexes and query vectors](/alloydb/docs/ai/store-index-query-vectors)\n- [An example embedding workflow](/alloydb/docs/ai/example-embeddings)"]]