truncate()

Deprecated.

This API is an ORM-style PyMilvus API and will be removed in PyMilvus 3.1. Use MilvusClient instead.

This operation truncates the current collection. This operation has the same effect as utility.truncate_collection().

Request Syntax

truncate(
    timeout: float | None
)

PARAMETERS:

  • timeout (float | None)

    The timeout duration for this operation. Setting this to None indicates that this operation timeouts when any response arrives or any error occurs.

RETURN TYPE:

NoneType

RETURNS:

None

EXCEPTIONS:

  • MilvusException

    This exception will be raised when any error occurs during this operation.

Example

from pymilvus import connections, Collection, CollectionSchema, FieldSchema, DataType

# Connect to localhost:19530
connections.connect()

schema = CollectionSchema([
    FieldSchema("id", DataType.INT64, is_primary=True),
    FieldSchema("vector", DataType.FLOAT_VECTOR, dim=5)
])

# Create a collection and insert two entities
collection = Collection(
    name="test_collection_truncate",
    schema=schema
)

collection.insert([
    [1, 2],
    [[1.0, 2.0], [3.0, 4.0]]
])
collection.flush()

collection.num_entities # 2

# Truncate the collection
collection.truncate()

collection.num_entities # 0

The following operations are related to truncate():

Try Managed Milvus for Free

Zilliz Cloud is hassle-free, powered by Milvus and 10x faster.

Get Started
Feedback

Was this page helpful?