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 dimension
    >>> 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)
Edit
© 2019 - 2020 Milvus. All rights reserved.