[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-03。"],[],[],null,["Select a documentation version: 15.12.0keyboard_arrow_down\n\n- [Current (16.8.0)](/alloydb/omni/current/docs/ai/maintain-vector-indexes)\n- [16.8.0](/alloydb/omni/16.8.0/docs/ai/maintain-vector-indexes)\n- [16.3.0](/alloydb/omni/16.3.0/docs/ai/maintain-vector-indexes)\n- [15.12.0](/alloydb/omni/15.12.0/docs/ai/maintain-vector-indexes)\n- [15.7.1](/alloydb/omni/15.7.1/docs/ai/maintain-vector-indexes)\n- [15.7.0](/alloydb/omni/15.7.0/docs/ai/maintain-vector-indexes)\n\n\u003cbr /\u003e\n\nThis page describes options for maintaining your vector indexes. Maintaining indexes helps to ensure that the indexes adapt to data changes that might impact the accuracy of your search results. Use the strategies on this page to avoid degradation in query performance as your dataset grows.\n\n\u003cbr /\u003e\n\nView vector index metrics\n\nIf your table is prone to frequent updates or insertions, then we recommend\nperiodically [reindexing the existing ScaNN index](#manually-rebuild-index)\nin order to improve the recall accuracy for your index. You can monitor\nindex metrics to view changes in vector distributions or vector mutations since\nthe index was built, and then reindex accordingly.\n\nFor more information about metrics, see [Vector index metrics](/alloydb/omni/15.12.0/docs/reference/vector-index-metrics).\n\nMaintain indexes automatically\n| **Preview**\n|\n|\n| This feature is subject to the \"Pre-GA Offerings Terms\" in the General Service Terms section\n| of the [Service Specific Terms](/terms/service-terms#1).\n|\n| Pre-GA features are available \"as is\" and might have limited support.\n|\n| For more information, see the\n| [launch stage descriptions](/products#product-launch-stages).\n\nYou can use the `scann.enable_index_maintenance` Grand Unified Configuration (GUC) database flag along with the\nindex-level `auto_maintenance` parameter while creating a ScaNN index. Using these settings together lets\nAlloyDB incrementally manage the index and split large outlier partitions as your dataset grows. By\nsplitting partitions, AlloyDB tries to provide better Queries per Second (QPS) and\nsearch results.\n\nAuto-maintenance index updates persist until AlloyDB updates the index again.\n\nTo enable AlloyDB to maintain an index automatically, add the `alloydb_scann` extension into the `shared_preload_libraries` parameter, enable the `scann.enable_index_maintenance` database flag, and then load the `alloydb_scann` extension by restarting the database:\n\n1. Load the `alloydb_scann` extension to the `shared_preload_libraries` list:\n\n sudo sed -r -i \"s|(shared_preload_libraries\\s*=\\s*)'(.*)'.*$|\\1'\\2,alloydb_scann'|\" \u003cvar translate=\"no\"\u003eDATA_DIR\u003c/var\u003e/postgresql.conf\n\n2. Verify that the parameter's configuration is set properly:\n\n grep -iE 'shared_preload_libraries' \u003cvar translate=\"no\"\u003eDATA_DIR\u003c/var\u003e/postgresql.conf\n\n3. Enable the `scann.enable_index_maintenance` flag by setting the flag in the in the `postgresql.conf` file:\n\n scann.enable_index_maintenance = ON\n\n4. Restart AlloyDB Omni for the parameter change to take effect:\n\n Docker \n\n docker container restart \u003cvar translate=\"no\"\u003eCONTAINER_NAME\u003c/var\u003e\n\n Replace \u003cvar translate=\"no\"\u003eCONTAINER_NAME\u003c/var\u003e with the name that you assigned to the AlloyDB Omni container when you started it.\n\n Podman \n\n podman container restart \u003cvar translate=\"no\"\u003eCONTAINER_NAME\u003c/var\u003e\n\n Replace \u003cvar translate=\"no\"\u003eCONTAINER_NAME\u003c/var\u003e with the name that you assigned to the AlloyDB Omni container when you started it.\n\nAfter you enable the `scann.enable_index_maintenance` flag, you can enable auto maintenance for indexes, or you can enable the `scann_index_maintenance` function to manually invoke maintenance.\n\nEnable auto-maintenance during index creation\n\nTo create a ScaNN index with auto maintenance enabled, run the following example command: \n\n CREATE INDEX \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eINDEX_NAME\u003c/span\u003e\u003c/var\u003e ON \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-k\"\u003eTABLE\u003c/span\u003e\u003c/var\u003e\n USING scann (\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eEMBEDDING_COLUMN\u003c/span\u003e\u003c/var\u003e \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eDISTANCE_FUNCTION\u003c/span\u003e\u003c/var\u003e)\n WITH (num_leaves=\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eNUM_LEAVES_VALUE\u003c/span\u003e\u003c/var\u003e, auto_maintenance=on);\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eINDEX_NAME\u003c/var\u003e: the name of the index you want to\n create---for example, `my-scann-index`. The index names are shared\n across your database. Ensure that each index name is unique to each\n table in your database.\n\n- \u003cvar translate=\"no\"\u003eTABLE\u003c/var\u003e: the table to add the index to.\n\n- \u003cvar translate=\"no\"\u003eEMBEDDING_COLUMN\u003c/var\u003e: a column that stores `vector`\n data.\n\n- \u003cvar translate=\"no\"\u003eDISTANCE_FUNCTION\u003c/var\u003e: the distance function to use\n with this index. Choose one of the following:\n\n - **L2 distance:** `l2`\n\n - **Dot product:** `dot_product`\n\n - **Cosine distance:** `cosine`\n\n- \u003cvar translate=\"no\"\u003eNUM_LEAVES_VALUE\u003c/var\u003e: the number of partitions to apply to\n this index. Set to any value between 1 to 1048576. For more information\n about how to decide this value, see [Tune a `ScaNN` index](/alloydb/omni/15.12.0/docs/ai/tune-indexes).\n\nManage leaves to search for split partitions automatically\n\nIf you have enabled automatic maintenance of indexes, then AlloyDB\nautomatically splits partitions when the `num_leaves` threshold is reached. As\nthe number of partitions grows due to these splits, you should adjust the number\nof leaves to search to maintain optimal performance.\n\nTo manage the number of leaves to search automatically, use\n`pct_leaves_to_search`. This parameter lets you specify a percentage of number\nof partitions to search. If you expect your dataset to grow significantly, then\nstart by setting the `pct_leaves_to_search` value to 1. The parameter is\ndisabled by default.\n\nSet this value to the percentage of current number of partitions. For example,\nto search 1% of current number of partitions, set this value to `1`. \n\nYou\ncan set this parameter to any value between `0` to `100`.\nThe default value is `0`, which disables this parameter and uses the\n`scann.num_leaves_to_search` to calculate the number of leaves to search.\n\nTo set the `pct_leaves_to_search` flag on your database, run the following command: \n\n ALTER DATABASE \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eDATABASE_NAME\u003c/span\u003e\u003c/var\u003e SET scann.pct_leaves_to_search = \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003ePERCENTAGE_LEAVES_TO_SEARCH\u003c/span\u003e\u003c/var\u003e;\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eDATABASE_NAME\u003c/var\u003e: the name of the database.\n- \u003cvar translate=\"no\"\u003ePERCENTAGE_LEAVES_TO_SEARCH\u003c/var\u003e: the percentage of `num_leaves` to search.\n\nManually invoke maintenance\n\nIf you want to invoke maintenance on a particular index on-demand, then run the following command: \n\n SELECT scann_index_maintenance('\u003cvar translate=\"no\"\u003eINDEX_NAME\u003c/var\u003e');\n\nManually rebuild your index\n\nYou can manually rebuild your index if you want to\nrebuild it with the configurations you specified when it was created.\n\nTo manually rebuild your index, run the following command: \n\n REINDEX INDEX CONCURRENTLY \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eINDEX_NAME\u003c/span\u003e\u003c/var\u003e;\n\nReplace \u003cvar translate=\"no\"\u003eINDEX_NAME\u003c/var\u003e with the name of the index you want to\nrebuild---for example, `my-scann-index`. The index names are shared\nacross your database. Ensure that each index name is unique to each\ntable in your database.\n\nFor more information about reindexing in PostgreSQL, see\n[REINDEX](https://www.postgresql.org/docs/15/sql-reindex.html).\n\nWhat's next\n\n- View [vector index metrics](/alloydb/omni/15.12.0/docs/reference/vector-index-metrics).\n\n- [Optimize vector query performance for ScaNN](/alloydb/omni/15.12.0/docs/ai/scann-vector-query-perf-overview)."]]