Skip to content

[Bug]: Insert method of MilvusClient doesnt support partitions #1987

Open

Description

@nightblure

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Insert method of MilvusClient doesnt have partition_name parameter but docs have. Lib code doesnt use kwargs and not use this parameter (2.3.6 version):

image image

docs:
image

Now this method insert all data only to collection

Expected Behavior

insert method use parameter partition_name

Steps/Code To Reproduce behavior

from pymilvus import (
    connections,
    utility,
    FieldSchema,
    CollectionSchema,
    DataType,
    Collection,
    Connections,
    db,
    MilvusClient, Partition
)


def is_collection_exists(collection: str, database: str) -> bool:
    return utility.has_collection(collection_name=collection, using=database)


def get_collection(collection: str, database: str):
    if not is_collection_exists(collection, database):
        raise Exception(f'Collection "{collection}" not exists')

    return Collection(name=collection, using=database)


def drop_collection(name: str = 'test_collection'):
    utility.drop_collection(name)


def is_database_exists(database: str):
    dbs = db.list_database()
    return database in dbs


def drop_database(name: str):
    clear_database(name)
    db.drop_database(name)


def use_database(database: str):
    db.using_database(database)


def create_database(database: str):
    db.create_database(database)


def connect_to_milvus(database: str = 'default'):
    connections.connect(database, host='localhost', port='19530', db_name=database)
    return connections


def disconnect_from_milvus(database: str):
    connections.disconnect(database)


def get_milvus_client(database: str):
    client = MilvusClient(uri='http://localhost:19530', db_name=database, token='root:Milvus')
    return client


def create_test_collection(collection_name: str, database: str):
    fields = [
        FieldSchema(name='id', dtype=DataType.INT64, is_primary=True, auto_id=True),
        FieldSchema(name='some_field', dtype=DataType.VARCHAR, max_length=1000),
        FieldSchema(name='some_field_2', dtype=DataType.INT64),
        FieldSchema(name='fake_vector_field', dtype=DataType.FLOAT_VECTOR, dim=1)
    ]
    schema = CollectionSchema(fields)
    collection = Collection(name=collection_name, schema=schema, using=database, consistency_level='Strong')

    collection.create_index(
        'fake_vector_field',
        dict(
            index_type="IVF_FLAT",
            metric_type="COSINE",
            params={"nlist": 4096},
        ),
        index_name='fake_vector_field_idx'
    )

    collection.create_index(
        'some_field_2',
        dict(index_type="STL_SORT"),
        index_name='some_field_2_idx'
    )

    collection.create_partition('Dairy_partition')
    collection.create_partition('SomeAA_partition')
    collection.create_partition('tHIrd_partition')


def fill_test_collection_with_mock_data(collection_name, database):
    data = []
    client = get_milvus_client(database)

    for i in range(100000):
        row = dict(
            some_field=fake.name(),
            some_field_2=randint(1, 14535345352),
            fake_vector_field=[0]
        )
        data.append(row)

    collection = get_collection(collection_name, database)
    res = client.insert(data, partition_name='Dairy_partition')
    res = client.insert(data[:5000], partition_name='SomeAA_partition')
    res = client.insert(data[:234], partition_name='tHIrd_partition')


def main():
    connect_to_milvus()

    if is_database_exists('test_database'):
        drop_database('test_database')

    create_database('test_database')

    connect_to_milvus('test_database')

    use_database('test_database')

    try:
        # create_collection_with_vectors('test_collection', 'test_database')
        # import_vectors_to_milvus('test_collection', 'test_database')

        create_test_collection('test_data_collection', 'test_database')
        fill_test_collection_with_mock_data('test_data_collection', 'test_database')
        get_just_data('test_data_collection', 'test_database')
    except Exception as e:
        logger.error(str(e))
    finally:
        disconnect_from_milvus('test_database')
        disconnect_from_milvus('default')


if __name__ == '__main__':
    main()

Environment details

- Hardware/Softward conditions (OS, CPU, GPU, Memory): MacBook Pro 2020 (M1), 16, 256, Sonoma 14.2.1
- Method of installation (Docker, or from source): from Docker
- Milvus version (v0.3.1, or v0.4.0): last with script standalone_embed.sh from Milvus site
- Milvus configuration (Settings you made in `server_config.yaml`): default with script standalone_embed.sh from Milvus site

Anything else?

No response

Activity

  1. czs007 commented on Mar 26, 2024

    @czs007
    Contributor

    @nightblure good catch.
    please upgrade to 2.3.7 or 2.4.0

  2. added and removed
    kind/bugSomething isn't working
    on Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions