Register now open for the virtual Milvus Community Conf2020!Join us on Oct.17th, 2020.

Insert and Delete Vectors

You can perform vector operations on collections or partitions. This article talks about the following topics:

Insert vectors to a collection

  1. Randomly generate 20 256-dimensional vectors:

    >>> import random
    # Generate 20 vectors of 256 dimensions.
    >>> vectors = [[random.random() for _ in range(256)] for _ in range(20)]
    
  2. Insert a list of vectors. If you do not specify vector IDs, Milvus automatically assigns IDs to the vectors.

    # Insert vectors.
    >>> milvus.insert(collection_name='test01', records=vectors)
    

    You can also specify the vector IDs:

    >>> vector_ids = [id for id in range(20)]
    >>> milvus.insert(collection_name='test01', records=vectors, ids=vector_ids)
    

Insert vectors to a partition

>>> milvus.insert('test01', vectors, partition_tag="tag01")

Delete vectors by ID

Suppose your collection contains the following vector IDs:

>>> ids = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]

You can delete the vectors with the following command:

>>> milvus.delete_entity_by_id(collection_name='test01', id_array=ids)
After calling delete, you can call flush again to ensure that the newly inserted data is visible and the deleted data is no longer recoverable.

FAQ

Is there a length limit on the self-defined entity IDs? Entity IDs must be non-negative 64-bit integers.
Can I insert vectors with existing IDs? Yes, you can. If you insert vectors with an existing ID, you would end up having duplicate IDs.
Does Milvus support inserting while searching? Yes.
Is there a volume limit on the vectors inserted each time? Vectors inserted each time must not exceed 256 MB.
Edit
© 2019 - 2020 Milvus. All rights reserved.