Ajustar a performance da consulta vetorial no AlloyDB para PostgreSQL
Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Nesta página, descrevemos como ajustar seus índices para alcançar um desempenho de consulta mais rápido e um recall melhor no AlloyDB para PostgreSQL.
Analisar suas consultas
Use o comando EXPLAIN ANALYZE para analisar os insights de consulta, conforme mostrado no exemplo de consulta SQL a seguir.
EXPLAINANALYZESELECTresult-columnFROMmy-tableORDERBYEMBEDDING_COLUMN<=>embedding('text-embedding-005','What is a database?')::vectorLIMIT1;
O exemplo de resposta QUERY PLAN inclui informações como o tempo gasto, o número de linhas verificadas ou retornadas e os recursos usados.
Limit (cost=0.42..15.27 rows=1 width=32) (actual time=0.106..0.132 rows=1 loops=1)
-> 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)
Order By: (embedding_column <=> embedding('text-embedding-005', 'What is a database?')::vector(768))
Limit value: 1
Planning Time: 0.354 ms
Execution Time: 0.141 ms
Conferir métricas de índice vetorial
Use as métricas de índice de vetor para analisar a performance dele, identificar áreas de melhoria e ajustar o índice com base nas métricas, se necessário.
Para conferir todas as métricas de índice de vetor, execute a seguinte consulta SQL, que usa a visualização pg_stat_ann_indexes:
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-08-25 UTC."],[[["\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)."]]