milvus-io / pymilvus

Python SDK for Milvus.
Apache License 2.0
1k stars 322 forks source link

[QUESTION]: Why is collection.num_entities 0 after insertion? #1623

Open pablopalafox opened 1 year ago

pablopalafox commented 1 year ago

Is there an existing issue for this?

What is your question?

Hey folks!

I'm getting started with milvus and tried running this example

Aside from the fact that I had to move the release_collection(collection) call up above the dropping index call,

    # drop collection index
    drop_index(collection)

    # release memory
    release_collection(collection) # Gave error if not placed above drop_index

    # drop collection
    drop_collection(_COLLECTION_NAME)

what I saw is that the number of entities is 0.

Create connection...

List connections:
[('default', <pymilvus.client.grpc_handler.GrpcHandler object at 0x7fb34b3b71c0>)]

Drop collection: demo

collection created: demo

list collections:
['demo', 'books']

The number of entity:
0

Created index:
{'index_type': 'IVF_FLAT', 'params': {'nlist': 1024}, 'metric_type': 'L2'}

Search result for 0th vector: 
Top 0: id: 7, distance: 0.7198156714439392, entity: {}
Top 1: id: 6, distance: 0.8187153339385986, entity: {}
Top 2: id: 4, distance: 0.8676149845123291, entity: {}

Search result for 1th vector: 
Top 0: id: 1, distance: 0.0, entity: {}
Top 1: id: 9, distance: 0.9325504899024963, entity: {}
Top 2: id: 8, distance: 0.9705616235733032, entity: {}

Search result for 2th vector: 
Top 0: id: 2, distance: 0.0, entity: {}
Top 1: id: 6, distance: 0.48646578192710876, entity: {}
Top 2: id: 4, distance: 0.5971701145172119, entity: {}

Drop index sucessfully

Drop collection: demo

Could you guys give me a brief overview as why this is zero? I would have expected it to be some greater-than-zero number, in particular, the number of entries in the database. Thanks in advance!!

Anything else?

No response

Vickcle commented 1 year ago

In fact,I met this issue too. I guess when we first do insert,the index didn't completely created, it cost time more then we expect. Although we can do search quick soon but with the attu tool i see the num of collection is 0 too. A little time passed ,it changed to my inserted num.

XuanYang-cn commented 1 year ago

@pablopalafox num_entities are estimated values, for real-time correct num_rows, you can use count(*): https://milvus.io/docs/query.md#Count-entities

image