Stay organized with collections
Save and categorize content based on your preferences.
This page describes how to use stored embeddings to generate indexes and query
embeddings using ScaNN, IVF, IVFFlat, and HNSW indexes with AlloyDB for PostgreSQL.
For more information about storing embedding, see
Store vector embeddings.
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-26 UTC."],[[["\u003cp\u003eThis page guides you on creating and querying indexes using stored embeddings with \u003ccode\u003eScaNN\u003c/code\u003e, \u003ccode\u003eIVF\u003c/code\u003e, \u003ccode\u003eIVFFlat\u003c/code\u003e, and \u003ccode\u003eHNSW\u003c/code\u003e indexes in AlloyDB for PostgreSQL.\u003c/p\u003e\n"],["\u003cp\u003ePrerequisites include having embedding vectors in an AlloyDB table and installing the \u003ccode\u003evector\u003c/code\u003e extension version \u003ccode\u003e0.5.0\u003c/code\u003e or later.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ealloydb_scann\u003c/code\u003e extension, compatible with PostgreSQL 14 and 15, must also be installed to create \u003ccode\u003eScaNN\u003c/code\u003e indexes.\u003c/p\u003e\n"],["\u003cp\u003eYou can create various index types, such as \u003ccode\u003eScaNN\u003c/code\u003e, \u003ccode\u003eIVF\u003c/code\u003e, \u003ccode\u003eIVFFlat\u003c/code\u003e, and \u003ccode\u003eHNSW\u003c/code\u003e, but remember that index names are shared across the database.\u003c/p\u003e\n"]]],[],null,["# Create indexes\n\nThis page describes how to use stored embeddings to generate indexes and query\nembeddings using `ScaNN`, `IVF`, `IVFFlat`, and `HNSW` indexes with AlloyDB for PostgreSQL.\nFor more information about storing embedding, see\n[Store vector embeddings](/alloydb/docs/ai/store-embeddings).\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/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- [Run vector similarity searches](/alloydb/docs/ai/run-vector-similarity-search)\n- [Tune vector query performance](/alloydb/docs/ai/tune-indexes)\n- [Vector index metrics](/alloydb/docs/reference/vector-index-metrics)\n- [Learn how to build a smart shopping assistant with AlloyDB, pgvector, and model endpoint management](https://codelabs.developers.google.com/smart-shop-agent-alloydb#0)."]]