milvus-io / pymilvus

Python SDK for Milvus.
Apache License 2.0
986 stars 314 forks source link

[Bug]: num_partitions does not take effect #2150

Open zhuwenxing opened 2 months ago

zhuwenxing commented 2 months ago

Is there an existing issue for this?

Describe the bug

pymilvus version: 2.4.0rc39 milvus version: 2.4-20240621-e02a95e3-amd64

from pymilvus import MilvusClient, DataType, Collection, connections

# Setup Milvus client
client = MilvusClient(uri="http://10.104.18.39:19530")

# Create a collection schema with a partition key
schema = client.create_schema(
    auto_id=False,
    enable_dynamic_field=True,
    partition_key_field="color",  # Set the field used as the partition key
    num_partitions=10  # Specify the number of partitions
)

# Add fields to the schema
schema.add_field(field_name="id", datatype=DataType.INT64, is_primary=True)
schema.add_field(field_name="vector", datatype=DataType.FLOAT_VECTOR, dim=5)
schema.add_field(field_name="color", datatype=DataType.VARCHAR, max_length=512)

# Create the collection with the defined schema
client.create_collection(collection_name="hello_2", schema=schema)
connections.connect(host="10.104.18.39")

c = Collection(name="hello_2")
print(c.partitions)
print(c.describe())

result

[{"name":"_default_0","collection_name":"hello_2","description":""}, {"name":"_default_1","collection_name":"hello_2","description":""}, {"name":"_default_2","collection_name":"hello_2","description":""}, {"name":"_default_3","collection_name":"hello_2","description":""}, {"name":"_default_4","collection_name":"hello_2","description":""}, {"name":"_default_5","collection_name":"hello_2","description":""}, {"name":"_default_6","collection_name":"hello_2","description":""}, {"name":"_default_7","collection_name":"hello_2","description":""}, {"name":"_default_8","collection_name":"hello_2","description":""}, {"name":"_default_9","collection_name":"hello_2","description":""}, {"name":"_default_10","collection_name":"hello_2","description":""}, {"name":"_default_11","collection_name":"hello_2","description":""}, {"name":"_default_12","collection_name":"hello_2","description":""}, {"name":"_default_13","collection_name":"hello_2","description":""}, {"name":"_default_14","collection_name":"hello_2","description":""}, {"name":"_default_15","collection_name":"hello_2","description":""}]
{'collection_name': 'hello_2', 'auto_id': False, 'num_shards': 1, 'description': '', 'fields': [{'field_id': 100, 'name': 'id', 'description': '', 'type': 5, 'params': {}, 'element_type': 0, 'is_primary': True}, {'field_id': 101, 'name': 'vector', 'description': '', 'type': 101, 'params': {'dim': 5}, 'element_type': 0}, {'field_id': 102, 'name': 'color', 'description': '', 'type': 21, 'params': {'max_length': 512}, 'element_type': 0, 'is_partition_key': True}], 'aliases': [], 'collection_id': 450616824097041838, 'consistency_level': 2, 'properties': {}, 'num_partitions': 16, 'enable_dynamic_field': True}

Expected Behavior

No response

Steps/Code To Reproduce behavior

No response

Environment details

- Hardware/Softward conditions (OS, CPU, GPU, Memory):
- Method of installation (Docker, or from source):
- Milvus version (v0.3.1, or v0.4.0):
- Milvus configuration (Settings you made in `server_config.yaml`):

Anything else?

No response

zhuwenxing commented 2 months ago

same for 2.4.4rc11

zhuwenxing commented 2 months ago

/assign @czs007

PTAL

XuanYang-cn commented 2 months ago

@zhuwenxing Need to set it at create_collection, not in schema

try this

client.create_collection(xxx, num_partitions=64)