milvus-logo
LFAI
< Docs
  • Python

insert()

This method inserts data into a specified collection.

Invocation

insert(data, partition_name=None, timeout=None, **kwargs)

Parameters

ParameterDescriptionTypeRequired
dataData to insertlist-like(list, tuple)True
partition_nameName of the partition to insert data into.StringFalse
timeoutAn optional duration of time in seconds to allow for the RPC. If it is set to None, the client keeps waiting until the server responds or error occurs.FloatFalse

Return

A MutationResult object.

Properties

PropertyDescriptionType
insert_countNumber of the inserted entities.Integer
primary_keysList of the primary keys of the inserted entities.list[String]

Raises

  • CollectionNotExistException: error if the collection does not exist.
  • ParamError: error if the parameters are invalid.
  • BaseException: error if the specified partition does not exist.

Example

import random
data = [
  [i for i in range(2000)],
  [i for i in range(10000, 12000)],
  [[random.random() for _ in range(2)] for _ in range(2000)],
]
from pymilvus import Collection
collection = Collection("book")      # Get an existing collection.
mr = collection.insert(data)
Feedback

Was this page helpful?