Ce document explique comment utiliser les embeddings stockés pour générer des index et interroger des embeddings. Pour en savoir plus sur le stockage des embeddings, consultez Stocker des embeddings vectoriels.
Vous pouvez créer des index ScaNN, IVF, IVFFlat et HNSW avec AlloyDB.
Avant de commencer
Avant de pouvoir commencer à créer des index, vous devez remplir les conditions préalables suivantes.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/04 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/04 (UTC)."],[[["\u003cp\u003eThis guide outlines how to generate and query indexes using stored embeddings within AlloyDB.\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 for efficient data retrieval.\u003c/p\u003e\n"],["\u003cp\u003ePrior to index creation, ensure that embedding vectors are stored in a table, the \u003ccode\u003evector\u003c/code\u003e extension (version 0.5.0 or later) is installed, and, for \u003ccode\u003eScaNN\u003c/code\u003e indexes, the \u003ccode\u003ealloydb_scann\u003c/code\u003e extension is installed.\u003c/p\u003e\n"],["\u003cp\u003eWhen upgrading to AlloyDB Omni, drop any indexes created with the \u003ccode\u003epostgres_ann\u003c/code\u003e extension and recreate them using \u003ccode\u003ealloydb_scann\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["# Create indexes and query vectors\n\nSelect a documentation version: Current (16.8.0)keyboard_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/current/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/current/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/current/docs/ai/example-embeddings)\n- [Tune vector query performance](/alloydb/omni/current/docs/ai/tune-indexes)\n- [Vector index metrics](/alloydb/omni/current/docs/reference/vector-index-metrics)"]]