Use the vector extension, version 0.5.0.google-1 or later, which includes
pgvector functions and operators, to store generated embeddings as vector values. This
is a version of pgvector that Google has extended with optimizations specific
to AlloyDB.
CREATEEXTENSIONIFNOTEXISTSvector;
Store generated embeddings
Ensure that you have already created a table in your AlloyDB database.
To store vector embeddings, do the following:
Create a vector[] column in your table to store your embeddings:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-25 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 to store embeddings as vector values.\u003c/p\u003e\n"],["\u003cp\u003eTo use this feature, ensure you install the \u003ccode\u003evector\u003c/code\u003e extension, version \u003ccode\u003e0.5.0.google-1\u003c/code\u003e or later, optimized for AlloyDB, by running \u003ccode\u003eCREATE EXTENSION IF NOT EXISTS vector;\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eYou can store embeddings in an existing AlloyDB table by adding a \u003ccode\u003evector[]\u003c/code\u003e column, specifying the number of dimensions supported by the model being used, and copying the vectors into this column from a CSV file or using \u003ccode\u003eAlloyDBVectorStore\u003c/code\u003e for LangChain integration.\u003c/p\u003e\n"],["\u003cp\u003eAfter storing vector data, consider creating indexes using the \u003ccode\u003evector\u003c/code\u003e or \u003ccode\u003ealloydb_scann\u003c/code\u003e extension for enhanced query performance.\u003c/p\u003e\n"],["\u003cp\u003eThe AlloyDB ScaNN index is currently in preview and subject to Pre-GA Offerings Terms, with features available "as is" and having potentially limited support.\u003c/p\u003e\n"]]],[],null,["# Store vector embeddings\n\nSelect a documentation version: 15.5.5keyboard_arrow_down\n\n- [15.5.5](/alloydb/omni/15.5.5/docs/store-embeddings)\n\n\u003cbr /\u003e\n\nThis page shows you how to use AlloyDB as a vector database with the `vector` extension that includes `pgvector` functions and operators. These functions and operators let you store embeddings as vector values.\n\n\u003cbr /\u003e\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 `textembedding-gecko`English models---for example, `textembedding-gecko@003` 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\n|\n| **Preview\n| --- AlloyDB ScaNN index**\n|\n|\n| This feature is subject to the \"Pre-GA Offerings Terms\" in the General Service Terms section\n| of the [Service Specific Terms](/terms/service-terms#1).\n|\n| Pre-GA features are available \"as is\" and might have limited support.\n|\n| For more information, see the\n| [launch stage descriptions](/products#product-launch-stages).\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/omni/15.5.5/docs/store-index-query-vectors)\n- [An example embedding workflow](/alloydb/omni/15.5.5/docs/example-embeddings)"]]