[[["易于理解","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-08-25。"],[[["\u003cp\u003eThis document guides users on tuning indexes for enhanced query performance and improved recall.\u003c/p\u003e\n"],["\u003cp\u003eUtilize the \u003ccode\u003eEXPLAIN ANALYZE\u003c/code\u003e command to gain insights into query performance, including time taken, rows scanned, and resource usage.\u003c/p\u003e\n"],["\u003cp\u003eVector index metrics, accessible via the \u003ccode\u003epg_stat_ann_indexes\u003c/code\u003e view, provide data to evaluate and improve index performance.\u003c/p\u003e\n"],["\u003cp\u003eMetrics like \u003ccode\u003eindexsize\u003c/code\u003e, \u003ccode\u003eindexscan\u003c/code\u003e, and \u003ccode\u003edistribution\u003c/code\u003e can help you understand the vector index performance.\u003c/p\u003e\n"]]],[],null,["# Tune vector query performance in AlloyDB for PostgreSQL\n\nThis page describes how to tune your indexes to achieve faster query performance\nand better recall in AlloyDB for PostgreSQL. \nScaNN IVF IVFFlat HNSW\n\nAnalyze your queries\n--------------------\n\nUse the `EXPLAIN ANALYZE` command to analyze your query insights as shown in the following example SQL query. \n\n EXPLAIN ANALYZE SELECT result-column\n FROM my-table\n ORDER BY EMBEDDING_COLUMN \u003c=\u003e embedding('text-embedding-005', 'What is a database?')::vector\n LIMIT 1;\n\nThe example response `QUERY PLAN` includes information such as the time taken, the number of rows scanned or returned, and the resources used. \n\n Limit (cost=0.42..15.27 rows=1 width=32) (actual time=0.106..0.132 rows=1 loops=1)\n -\u003e Index Scan using my-scann-index on my-table (cost=0.42..858027.93 rows=100000 width=32) (actual time=0.105..0.129 rows=1 loops=1)\n Order By: (embedding_column \u003c=\u003e embedding('text-embedding-005', 'What is a database?')::vector(768))\n Limit value: 1\n Planning Time: 0.354 ms\n Execution Time: 0.141 ms\n\nView vector index metrics\n-------------------------\n\nYou can use vector index metrics to review performance of your vector index,\nidentify areas for improvement, and tune your index based on the metrics, if\nneeded.\n\nTo view all vector index metrics, run the following SQL query, which uses the\n`pg_stat_ann_indexes` view: \n\n SELECT * FROM pg_stat_ann_indexes;\n\nYou see output similar to the following: \n\n -[ RECORD 1 ]----------+---------------------------------------------------------------------------\n relid | 271236\n indexrelid | 271242\n schemaname | public\n relname | t1\n indexrelname | t1_ix1\n indextype | scann\n indexconfig | {num_leaves=100,quantizer=SQ8}\n indexsize | 832 kB\n indexscan | 0\n insertcount | 250\n deletecount | 0\n updatecount | 0\n partitioncount | 100\n distribution | {\"average\": 3.54, \"maximum\": 37, \"minimum\": 0, \"outliers\": [37, 12, 11, 10, 10, 9, 9, 9, 9, 9]}\n distributionpercentile |{\"10\": { \"num_vectors\": 0, \"num_partitions\": 0 }, \"25\": { \"num_vectors\": 0, \"num_partitions\": 30 }, \"50\": { \"num_vectors\": 3, \"num_partitions\": 30 }, \"75\": { \"num_vectors\": 5, \"num_partitions\": 19 }, \"90\": { \"num_vectors\": 7, \"num_partitions\": 11 }, \"95\": { \"num_vectors\": 9, \"num_partitions\": 5 }, \"99\": { \"num_vectors\": 12, \"num_partitions\": 4 }, \"100\": { \"num_vectors\": 37, \"num_partitions\": 1 }}\n\nFor more information about the complete list of metrics, see [Vector index\nmetrics](/alloydb/docs/reference/vector-index-metrics).\n\nWhat's next\n-----------\n\n- [Maintain vector indexes](/alloydb/docs/ai/maintain-vector-indexes).\n- Learn about an [example embedding workflow](/alloydb/docs/ai/example-embeddings)."]]