Menyesuaikan performa kueri vektor di AlloyDB untuk PostgreSQL
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Halaman ini menjelaskan cara menyesuaikan indeks untuk mencapai performa kueri yang lebih cepat dan perolehan yang lebih baik di AlloyDB untuk PostgreSQL.
Menganalisis kueri Anda
Gunakan perintah EXPLAIN ANALYZE untuk menganalisis insight kueri Anda seperti yang ditunjukkan dalam contoh kueri SQL berikut.
EXPLAINANALYZESELECTresult-columnFROMmy-tableORDERBYEMBEDDING_COLUMN<=>embedding('text-embedding-005','What is a database?')::vectorLIMIT1;
Respons contoh QUERY PLAN mencakup informasi seperti waktu yang diperlukan, jumlah baris yang dipindai atau ditampilkan, dan resource yang digunakan.
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
Melihat metrik indeks vektor
Anda dapat menggunakan metrik indeks vektor untuk meninjau performa indeks vektor, mengidentifikasi area yang perlu ditingkatkan, dan menyesuaikan indeks berdasarkan metrik, jika diperlukan.
Untuk melihat semua metrik indeks vektor, jalankan kueri SQL berikut, yang menggunakan tampilan
pg_stat_ann_indexes:
SELECT*FROMpg_stat_ann_indexes;
Anda akan melihat output yang mirip dengan berikut ini:
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 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)."]]