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.


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.
What is the maximum dimension of a vector in Milvus? Milvus can support vectors with up to 32,768 dimensions.
On this page