Insert vectors

You can insert vectors to a specified partition within a specific collection.

  1. Generate random vectors:
>>> import random
>>> vectors = [[random.random() for _ in range(8)] for _ in range(10)]
>>> entities = [vectors]
const entities = Array.from({ length: 10 }, () => ({
  [FIELD_NAME]: Array.from({ length: 8 }, () => Math.floor(Math.random() * 10)),
}));
  1. Insert the random vectors to the newly created collection. Milvus automatically assigns IDs to the inserted vectors, similar to AutoID in a relational database.

Milvus returns the value of MutationResult, which contains the corresponding primary_keys of the inserted vectors.

>>> mr = collection.insert(entities)
# Get the primary keys of the `MutationResult`
>>> mr.primary_keys
[425790736918318406, 425790736918318407, 425790736918318408, ...]
await milvusClient.dataManager.insert({{
  collection_name: COLLECTION_NAME,
  fields_data: entities,
});
  1. By specifying partition_name when calling insert(), you can insert vectors to a specified partition:
>>> collection.insert(data=entities, partition_name=partition_name)
await milvusClient.dataManager.insert({{
  collection_name: COLLECTION_NAME,
  partition_name: partition_name
  fields_data: entities,
});
  1. Milvus temporarily stores the inserted vectors in the memory. Call flush() to flush them to the disk.
>>> pymilvus.utility.get_connection().flush([collection_name])
await milvusClient.dataManager.flush({ collection_names: [COLLECTION_NAME] });
Is this page helpful?
Scored Successfully!