使用 Partition Key公测版
本指南将指导您使用 Partition Key 来加快从 Collection 中检索数据的速度。
Partition Key
您可以将 Collection 的特定字段设置为 Partition Key。这样,Zilliz Cloud 将根据此字段中各自值的哈希值,将传入r Entity 分配到不同的 Partition 中。
您可以在 Collection Schema 中设置 Partition Key 的名称。
schema = MilvusClient.create_schema(
auto_id=False,
enable_dynamic_field=True,
# highlight-start
partition_key_field="id", # An existing scalar field
num_partitions=16 # Number of partitions. Defaults to 16.
# highlight-end
)
也可以在向 Schema 中添加字段时设置 Partition Key。
schema.add_field(
field_name="id",
datatype=DataType.VARCHAR,
max_length=512,
# highlight-next-line
is_partition_key=True
)
在使用上述 Schema 创建了一个 Collection、为向量字段建立索引并加载了 Collection 后,就可以使用包含 Partition Key的过滤条件进行搜索。这样,Zilliz Cloud 就会将搜索范围缩小到只包含与过滤条件中的 Partition Key 值相匹配的 Entity 所在 Partition,从而避免扫描不相关的 Partition,提高搜索性能。
您可以在过滤条件中包含一个或多个 Partition Key,如下所示:
# Filter based on a single partition key value
filter='partition_key == "x" && <other conditions>'
# Filter based on multiple partition key values
filter='partition_key in ["x", "y", "z"] && <other conditions>'
Partition-key Isolation
📘