Stay organized with collections
Save and categorize content based on your preferences.
This 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.
Required database extension
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-04-12 UTC."],[[["AlloyDB can be used as a vector database by utilizing the `vector` extension, which includes `pgvector` functions and operators for storing embeddings."],["The `vector` extension, version `0.5.0.google-1` or later, is required and has Google-specific optimizations for AlloyDB to efficiently manage vector values."],["To store embeddings, add a `vector[]` column to your table with `ALTER TABLE`, specifying the number of dimensions supported by your model, and then populate it with generated embeddings."],["If using the Langchain framework with a dataset of 100k embeddings or more, consider using the `AlloyDBVectorStore` vector class from the alloydb langChain library."],["Once embeddings are stored, you can use either the `vector` extension or the `alloydb_scann` extension to create indexes, which will improve query performance."]]],[]]