flush()
This operation seals all segments in the collection. Any insertions after this operation will generate a new segment.
Request Syntax
flush(
timeout: float | None
)
can i call `flush()` after every data insertion?
When new data is inserted, it is written into a growing segment. Once the size of a growing segment reaches its upper limit, Milvus automatically seals the segment.
Continuously calling this operation results in many sealed segments of small sizes, which can gradually degrade search performance.
It is recommended that you wait for Milvus to seal all segments before conducting any searches.
PARAMETERS:
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.
Examples
from pymilvus import Collection, CollectionSchema, FieldSchema, DataType
schema = CollectionSchema([
FieldSchema("id", DataType.INT64, is_primary=True),
FieldSchema("vector", DataType.FLOAT_VECTOR, dim=5)
])
# Create a collection
collection = Collection(
name="test_collection",
schema=schema
)
# Insert some data
collection.insert(
data=[
[0,1,2,3,4], # id
[ # vector
[0.1,0.2,-0.3,-0.4,0.5],
[0.3,-0.1,-0.2,-0.6,0.7],
[-0.6,-0.3,0.2,0.8,0.7],
[0.6,0.2,-0.3,-0.8,0.5],
[0.3,0.1,-0.2,-0.6,-0.7],
],
]
)
# Flush the data
collection.flush()
# Check the number of flushed entities in the collection
collection.num_entities # 5