This document shows you how to use stored embeddings to generate indexes and query
embeddings. For more information about storing embedding, see
Store vector embeddings.
You can create ScaNN, IVF, IVFFlat, and HNSW indexes with AlloyDB.
Before you begin
Before you can start creating indexes, you must complete the following
prerequisites.
[[["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."],[],[],null,["# Create indexes and query vectors\n\nSelect a documentation version: 15.12.0keyboard_arrow_down\n\n- [Current (16.8.0)](/alloydb/omni/current/docs/ai/store-index-query-vectors)\n- [16.8.0](/alloydb/omni/16.8.0/docs/ai/store-index-query-vectors)\n- [16.3.0](/alloydb/omni/16.3.0/docs/ai/store-index-query-vectors)\n- [15.12.0](/alloydb/omni/15.12.0/docs/ai/store-index-query-vectors)\n- [15.7.1](/alloydb/omni/15.7.1/docs/ai/store-index-query-vectors)\n- [15.7.0](/alloydb/omni/15.7.0/docs/ai/store-index-query-vectors)\n\n\u003cbr /\u003e\n\nThis document shows you how to use stored embeddings to generate indexes and query\nembeddings. For more information about storing embedding, see\n[Store vector embeddings](/alloydb/omni/15.12.0/docs/ai/store-embeddings).\n\nYou can create `ScaNN`, `IVF`, `IVFFlat`, and `HNSW` indexes with AlloyDB.\n| **Caution:** The `postgres_ann` extension is renamed to `alloydb_scann`. Before you upgrade to AlloyDB Omni, you must drop any indexes created using the older `postgres_ann` version. Next, upgrade AlloyDB Omni, and then [create the indexes](#create-index) again using the `alloydb_scann` extension. This applies only to AlloyDB Omni.\n\nBefore you begin\n----------------\n\nBefore you can start creating indexes, you must complete the following\nprerequisites.\n\n- [Embedding vectors are added to a table](/alloydb/omni/15.12.0/docs/ai/store-embeddings) in your\n AlloyDB database.\n\n- The `vector` extension version `0.5.0` or later that is based on `pgvector`, extended by Google for\n AlloyDB is installed.\n\n CREATE EXTENSION IF NOT EXISTS vector;\n\n- To generate `ScaNN` indexes, install the `alloydb_scann` extension in addition\n to the `vector` extension.\n\n CREATE EXTENSION IF NOT EXISTS alloydb_scann;\n\n| **Note:** The `alloydb_scann` extension can be used with PostgreSQL 14 and 15 compatible databases.\n\nCreate an index\n---------------\n\nYou can create one of the following index types for tables in your database.\n**Note:** As the index names are shared across the database, create an index name unique to each table in your database. \nScaNN IVF IVFFlat HNSW\n\nWhat's next\n-----------\n\n- [An example embedding workflow](/alloydb/omni/15.12.0/docs/ai/example-embeddings)\n- [Tune vector query performance](/alloydb/omni/15.12.0/docs/ai/tune-indexes)\n- [Vector index metrics](/alloydb/omni/15.12.0/docs/reference/vector-index-metrics)"]]