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."],[[["\u003cp\u003eThis guide outlines how to generate indexes and query embeddings using stored embeddings in AlloyDB, building upon the foundation of storing vector embeddings.\u003c/p\u003e\n"],["\u003cp\u003eAlloyDB supports the creation of \u003ccode\u003eScaNN\u003c/code\u003e, \u003ccode\u003eIVF\u003c/code\u003e, \u003ccode\u003eIVFFlat\u003c/code\u003e, and \u003ccode\u003eHNSW\u003c/code\u003e index types, and for \u003ccode\u003eScaNN\u003c/code\u003e indexes the \u003ccode\u003ealloydb_scann\u003c/code\u003e extension is necessary alongside the \u003ccode\u003evector\u003c/code\u003e extension.\u003c/p\u003e\n"],["\u003cp\u003eBefore creating indexes, you must ensure that vector embeddings are stored in an AlloyDB table, and the \u003ccode\u003evector\u003c/code\u003e extension (version 0.5.0 or later) is installed.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003epostgres_ann\u003c/code\u003e extension has been renamed to \u003ccode\u003ealloydb_scann\u003c/code\u003e, so any existing indexes using the prior extension must be dropped before upgrading, and re-created after the update.\u003c/p\u003e\n"],["\u003cp\u003eIndex names must be unique to each table in the database because they are shared across the database.\u003c/p\u003e\n"]]],[],null,["# Create indexes and query vectors\n\nSelect a documentation version: 15.7.1keyboard_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.7.1/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.7.1/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.7.1/docs/ai/example-embeddings)\n- [Tune vector query performance](/alloydb/omni/15.7.1/docs/ai/tune-indexes)\n- [Vector index metrics](/alloydb/omni/15.7.1/docs/reference/vector-index-metrics)"]]