Create indexes and query vectors

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.

  • Embedding vectors are added to a table in your AlloyDB database.

  • The pgvector extension, version 0.5.0 or later, extended by Google for AlloyDB is installed.

    CREATE EXTENSION IF NOT EXISTS vector;
    
  • To generate ScaNN indexes, install the alloydb_scann extension in addition to the pgvector extension.

    CREATE EXTENSION IF NOT EXISTS alloydb_scann;
    

Create an index

You can create one of the following index types for tables in your database.

What's next