• 关于 Milvus
  • 开始
  • 概念
  • 用户指南
  • 数据导入
  • 人工智能工具
  • 管理指南
  • 工具
  • 集成
  • 教程
  • 常见问题
  • API Reference

BIN_FLAT

BIN_FLAT索引是FLAT索引的一种变体,专门为二进制嵌入而定制。在向量相似性搜索要求在相对较小、百万级别的数据集上达到完美精确度的应用中,它表现出色。通过采用一种穷举搜索方法--将每个目标输入与数据集中的所有向量进行比较--BIN_FLAT 可以保证得到精确的结果。这种精确性使其成为评估其他可能提供不到 100%召回率的索引性能的理想基准,尽管其彻底的方法也使其成为处理大规模数据最慢的选择。

建立索引

要在 Milvus 中的向量场上建立BIN_FLAT 索引,请使用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_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:用于计算向量间距离的方法。二进制 Embeddings 的支持值包括HAMMING (默认)和JACCARD 。有关详情,请参阅 "度量类型"。

  • params:BIN_FLAT 索引不需要额外参数。

配置好索引参数后,可直接使用create_index() 方法或在create_collection 方法中传递索引参数来创建索引。详情请参阅创建 Collections

在索引上搜索

建立索引并插入实体后,就可以在索引上执行相似性搜索。

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 索引,在创建索引或搜索过程中都不需要额外的参数。

想要更快、更简单、更好用的 Milvus SaaS服务 ?

Zilliz Cloud是基于Milvus的全托管向量数据库,拥有更高性能,更易扩展,以及卓越性价比

免费试用 Zilliz Cloud
反馈

此页对您是否有帮助?