num_leaves_to_search:選用。指定要探測的葉節點數量,以進行 ANN 向量相似度搜尋。如果未指定葉節點數量,CloudSQL for MySQL 會為 num_leaves_to_search 選取計算值,該值會顯示在 information_schema.innodb_vector_indexes 中。一般來說,計算出的數字是良好的起點,可提供優質的搜尋結果和成效。建議您根據工作負載和效能/品質取捨,調整 num_leaves_to_search。
SELECT id, approx_distance(embedding_column_name
string_to_vector('[1,1,1]'),
'distance_measure=cosine') dist from t1
ORDER BY dist LIMIT 10;
SELECT id
FROM t1
ORDER BY
approx_distance(
embedding_column_name
string_to_vector('[1,1,1]'),
'distance_measure=dot_product,num_leaves_to_search=100) LIMIT 4;
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-09 (世界標準時間)。"],[],[],null,["# Cloud SQL functions\n\n\u003cbr /\u003e\n\nMySQL \\| PostgreSQL \\| SQL Server\n\n\u003cbr /\u003e\n\nThis pages describes Cloud SQL functions.\n\nVector conversion functions\n---------------------------\n\nThis following table lists the functions that you can use to manipulate vector\ninformation in a `SELECT` statement.\n\nSearch functions\n----------------\n\nThis section describes Cloud SQL search functions.\n\n### KNN functions\n\nThis following table lists the functions that you can use to calculate the\nKNN vector distance.\n\n### ANN function\n\nThis following table lists the function that you can use to calculate vector\ndistance.\n\nWhat's next\n-----------\n\n- Read the [overview about vector search on Cloud SQL](/sql/docs/mysql/vector-search).\n- Learn how to [enable and disable vector embeddings on your instance](/sql/docs/mysql/enable-vector-search).\n- Learn how to [generate vector embeddings](/sql/docs/mysql/generate-manage-vector-embeddings#generate_vector_embeddings_based_on_row_data).\n- Learn how to [create vector indexes](/sql/docs/mysql/create-manage-vector-indexes).\n- Learn how to [perform searches on vector embeddings](/sql/docs/mysql/search-filter-vector-embeddings)."]]