BIN_FLAT
BIN_FLAT索引是FLAT索引的變體,專門為二進位嵌入量身打造。在向量相似性搜尋需要在相對較小、百萬量級的資料集上達到完美精確度的應用程式中,BIN_FLAT 非常出色。BIN_FLAT 採用了徹底的搜尋方法 - 將每個目標輸入與資料集中的所有向量進行比較,以確保得到精確的結果。這種精確度使其成為評估其他可能提供低於 100% 回復率的索引效能的理想基準,不過其徹底的方法也使其成為大規模資料最慢的選擇。
建立索引
要在 Milvus 的向量場上建立BIN_FLAT 索引,請使用add_index() 方法,指定index_type 和metric_type 索引參數。
from pymilvus import MilvusClient
# Prepare index building params
index_params = MilvusClient.prepare_index_params()
index_params.add_index(
field_name="your_binary_vector_field_name", # Name of the vector field to be indexed
index_type="BIN_FLAT", # Type of the index to create
index_name="vector_index", # Name of the index to create
metric_type="HAMMING", # Metric type used to measure similarity
params={} # No additional parameters required for BIN_FLAT
)
在此設定中
index_type:要建立的索引類型。在本範例中,設定值為BIN_FLAT。metric_type:用來計算向量間距離的方法。二元嵌入的支援值包括HAMMING(預設值) 和JACCARD。詳情請參閱公制類型。params:BIN_FLAT 索引不需要額外的參數。
一旦配置好索引參數,就可以直接使用create_index() 方法或在create_collection 方法中傳入索引參數來建立索引。詳情請參閱建立集合。
在索引上搜尋
索引建立且實體插入後,您就可以在索引上執行相似性搜尋。
res = MilvusClient.search(
collection_name="your_collection_name", # Collection name
anns_field="binary_vector_field", # Binary vector field name
data=[query_binary_vector], # Query binary vector
limit=3, # TopK results to return
search_params={"params": {}} # No additional parameters required for BIN_FLAT
)
如需詳細資訊,請參閱二進位向量。
索引參數
對於 BIN_FLAT 索引,在索引建立或搜尋過程中都不需要額外的參數。