GPU_BRUTE_FORCE

GPU_BRUTE_FORCE索引專為GPU環境設計,適用於精確度要求極高的情況。它透過將每項查詢與資料集中的所有向量進行徹底比較,確保不會忽略任何潛在的匹配,從而保證召回率為 1。利用 GPU 加速,GPU_BRUTE_FORCE 適合要求向量相似性搜尋絕對精確度的應用程式。

建立索引

若要在 Milvus 的向量欄位上建立GPU_BRUTE_FORCE 索引,請使用add_index() 方法,指定index_typemetric_type 索引參數。

from pymilvus import MilvusClient

# Prepare index building params
index_params = MilvusClient.prepare_index_params()

index_params.add_index(
    field_name="your_vector_field_name", # Name of the vector field to be indexed
    index_type="GPU_BRUTE_FORCE", # Type of the index to create
    index_name="vector_index", # Name of the index to create
    metric_type="L2", # Metric type used to measure similarity
    params={} # No additional parameters required for GPU_BRUTE_FORCE
)

在此設定中

  • index_type:要建立的索引類型。在本範例中,設定值為GPU_BRUTE_FORCE

  • metric_type:用於計算向量間距離的方法。詳情請參閱公制類型

  • params:GPU_BRUTE_FORCE 索引不需要額外的參數。

一旦配置好索引參數,您就可以直接使用create_index() 方法或在create_collection 方法中傳入索引參數來建立索引。如需詳細資訊,請參閱建立集合

在索引上搜尋

索引建立且實體插入後,您就可以在索引上執行相似性搜尋。

res = MilvusClient.search(
    collection_name="your_collection_name", # Collection name
    anns_field="vector_field", # Vector field name
    data=[[0.1, 0.2, 0.3, 0.4, 0.5]],  # Query vector
    limit=3,  # TopK results to return
    search_params={"params": {}}  # No additional parameters required for GPU_BRUTE_FORCE
)

索引參數

對於GPU_BRUTE_FORCE 索引,在索引建立或搜尋過程中都不需要額外的參數。

免費嘗試托管的 Milvus

Zilliz Cloud 無縫接入,由 Milvus 提供動力,速度提升 10 倍。

開始使用
反饋

這個頁面有幫助嗎?