What does num_entities indicate for a Milvus collection?

I had thought that num_entities would indicate the number of records (or whatever the correct term is) within a Milvus collection. However, I created 1 file – test_milvus.py to create a simple collection like so:

import numpy as np
from pymilvus import connections, Collection, CollectionSchema, FieldSchema, DataType

connections.connect(alias='default',host='localhost', port='19530')

# Define the schema
schema = CollectionSchema([FieldSchema("id", DataType.INT64, is_primary=True, max_length=100),
                           FieldSchema("vector", DataType.FLOAT_VECTOR, dim=2)])

# Create a collection
collection = Collection("test_collection", schema)

# Insert data
data = [{"id":i, "vector": np.array([i, i],dtype=np.float32)} for i in range(10)]
collection.insert(data)

# Flush data
collection.flush()

# Disconnect from the server
connections.disconnect(alias='default')

and another to get information on collections within a Milvus database = milvus_info.py – like so:

from pymilvus import Collection, connections, db, utility

def get_info (host: str = "localhost", port: str = "19530"):

    # Connect to Milvus (replace with your connection details)
    connections.connect(alias="default", host=host, port=port)  # Replace with your connection parameters

    # Print the list of databases and collections
    db_list = db.list_database()
    for db_name in db_list:
        print(f"Database: {db_name}")
        collection_list = utility.list_collections(using=db_name)
        if len(collection_list) == 0:
            print("  No collections")
        for collection_name in collection_list:
            print(f"  Collection: {collection_name}")
            temp_collection = Collection(name=collection_name)
            for info in temp_collection.describe():
                print(f"    {info}: {temp_collection.describe()[info]}")
            print(f"   Number of entities: {temp_collection.num_entities}")
          
    # Disconnect from Milvus
    connections.disconnect(alias='default')


if __name__ == "__main__":
    get_info()

The first time I ran test_milvus followed by milvus_info.py, I got this output:

  $ python test_milvus.py 
  $ python milvus_info.py 
    Database: default
      Collection: test_collection
        collection_name: test_collection
        auto_id: False
        num_shards: 1
        description: 
        fields: [{'field_id': 100, 'name': 'id', 'description': '', 'type': <DataType.INT64: 5>, 'params': {}, 'is_primary': True}, {'field_id': 101, 'name': 'vector', 'description': '', 'type': <DataType.FLOAT_VECTOR: 101>, 'params': {'dim': 2}}]
        aliases: []
        collection_id: 450687678279804785
        consistency_level: 2
        properties: {}
        num_partitions: 1
        enable_dynamic_field: False
       Number of entities: 10

which struck me as odd, because there were only 2 vectors in the db.

However, if I run `test_milvus.py’ again, the number of entities goes up to 20, even though no new vectors have been added:

$ python test_milvus.py 
$ python milvus_info.py 
Database: default
  Collection: test_collection
    collection_name: test_collection
    auto_id: False
    num_shards: 1
    description: 
    fields: [{'field_id': 100, 'name': 'id', 'description': '', 'type': <DataType.INT64: 5>, 'params': {}, 'is_primary': True}, {'field_id': 101, 'name': 'vector', 'description': '', 'type': <DataType.FLOAT_VECTOR: 101>, 'params': {'dim': 2}}]
    aliases: []
    collection_id: 450687678279804785
    consistency_level: 2
    properties: {}
    num_partitions: 1
    enable_dynamic_field: False
   Number of entities: 20

This happens even though I’ve only tried to add records that were already there. I would’ve expected num_entities to be 10, no matter how many time I run these files. The documentation says it returns the number of rows, but I can drive it arbitrarily high while still having only 10 rows. Is num_entities supposed to track all rows that ever existed???

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật