Select a documentation version: <button class="button button-with-icon cloud-select-dropdown__button button-primary" aria-haspopup="true">15.7.1</button>

- [Current (18.4.0)](https://docs.cloud.google.com/alloydb/omni/kubernetes/current/docs/ai/store-embeddings.md.txt)
- [18.4.0](https://docs.cloud.google.com/alloydb/omni/kubernetes/18.4.0/docs/ai/store-embeddings.md.txt)
- [18.3.0](https://docs.cloud.google.com/alloydb/omni/kubernetes/18.3.0/docs/ai/store-embeddings.md.txt)
- [18.1.0](https://docs.cloud.google.com/alloydb/omni/kubernetes/18.1.0/docs/ai/store-embeddings.md.txt)
- [17.10.0](https://docs.cloud.google.com/alloydb/omni/kubernetes/17.10.0/docs/ai/store-embeddings.md.txt)
- [17.9.0](https://docs.cloud.google.com/alloydb/omni/kubernetes/17.9.0/docs/ai/store-embeddings.md.txt)
- [17.7.0](https://docs.cloud.google.com/alloydb/omni/kubernetes/17.7.0/docs/ai/store-embeddings.md.txt)
- [17.5.0](https://docs.cloud.google.com/alloydb/omni/kubernetes/17.5.0/docs/ai/store-embeddings.md.txt)
- [16.14.0](https://docs.cloud.google.com/alloydb/omni/kubernetes/16.14.0/docs/ai/store-embeddings.md.txt)
- [16.13.0](https://docs.cloud.google.com/alloydb/omni/kubernetes/16.13.0/docs/ai/store-embeddings.md.txt)
- [16.11.0](https://docs.cloud.google.com/alloydb/omni/kubernetes/16.11.0/docs/ai/store-embeddings.md.txt)
- [16.9.0](https://docs.cloud.google.com/alloydb/omni/kubernetes/16.9.0/docs/ai/store-embeddings.md.txt)
- [16.8.0](https://docs.cloud.google.com/alloydb/omni/kubernetes/16.8.0/docs/ai/store-embeddings.md.txt)
- [16.3.0](https://docs.cloud.google.com/alloydb/omni/kubernetes/16.3.0/docs/ai/store-embeddings.md.txt)
- [15.18.0](https://docs.cloud.google.com/alloydb/omni/kubernetes/15.18.0/docs/ai/store-embeddings.md.txt)
- [15.17.0](https://docs.cloud.google.com/alloydb/omni/kubernetes/15.17.0/docs/ai/store-embeddings.md.txt)
- [15.15.0](https://docs.cloud.google.com/alloydb/omni/kubernetes/15.15.0/docs/ai/store-embeddings.md.txt)
- [15.13.0](https://docs.cloud.google.com/alloydb/omni/kubernetes/15.13.0/docs/ai/store-embeddings.md.txt)
- [15.12.0](https://docs.cloud.google.com/alloydb/omni/kubernetes/15.12.0/docs/ai/store-embeddings.md.txt)
- [15.7.1](https://docs.cloud.google.com/alloydb/omni/kubernetes/15.7.1/docs/ai/store-embeddings.md.txt)
- [15.7.0](https://docs.cloud.google.com/alloydb/omni/kubernetes/15.7.0/docs/ai/store-embeddings.md.txt)

<br />

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.

<br />

## 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.

```sql
CREATE EXTENSION IF NOT EXISTS vector;
```

## Store generated embeddings

Ensure that you have already created a table in your AlloyDB database.

> [!NOTE]
> **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 LangChain](https://docs.cloud.google.com/alloydb/docs/ai/langchain.md.txt#vector_store_procedure_guide).

To store vector embeddings, follow these steps:

1. Create a `vector[]` column in your table to store your embeddings:

   ```sql
   ALTER TABLE TABLE ADD COLUMN EMBEDDING_COLUMN vector(DIMENSIONS);
   ```

   Replace the following:
   - `TABLE`: the table name.

   - `EMBEDDING_COLUMN`: the name of the new embedding column.

   - `DIMENSIONS`: the number of dimensions that the model
     supports.

     For example, if you are using one of the `text-embedding`English models---for example, `text-embedding-005` with Vertex AI, specify `768`.
2. Copy the vectors to the vector column. The following example assumes that your
   embeddings are available in a CSV file:

   ```sql
   COPY TABLE (EMBEDDING_COLUMN) FROM 'PATH_TO_VECTOR_CSV (FORMAT CSV);
   ```

   Replace the following:
   - `PATH_TO_VECTOR_CSV`: the full path of where you stored your CSV file.

After you store the embeddings, you can use the `vector` extension or the `alloydb_scann`
extension to create indexes for faster query performance.

## What's next

- [Create indexes and query vectors](https://docs.cloud.google.com/alloydb/omni/kubernetes/15.7.1/docs/ai/store-index-query-vectors.md.txt).
- Learn [an example embedding workflow](https://docs.cloud.google.com/alloydb/omni/kubernetes/15.7.1/docs/ai/example-embeddings.md.txt).