milvus-io / pymilvus

Python SDK for Milvus.
Apache License 2.0
1.03k stars 326 forks source link

[Bug]: [milvus_client][Defer] Row count shows 0 for interface "get_collection_stats" and "get_partition_stats" when the collection/partition is not empty #1868

Open binbinlv opened 10 months ago

binbinlv commented 10 months ago

Is there an existing issue for this?

Describe the bug

Row count shows 0 for interface "get_collection_stats" when the collection is not empty

>>> milvus_client.get_collection_stats(collection_name)
{'row_count': 0}
>>>
>>>
>>>
>>> query_results = milvus_client.query(collection_name, ids=[2])
>>> query_results
[{'id': 2, 'vector': [0.9007387, 0.44944635, 0.18477614, 0.42930314, 0.40345728, 0.3957196, 0.6963897, 0.24356908], 'b': 200}]

Expected Behavior

Shows the correct row count

Steps/Code To Reproduce behavior

import time
import numpy as np
from pymilvus import (
    MilvusClient,
)

fmt = "\n=== {:30} ===\n"
dim = 8
collection_name = "hello_milvus"
milvus_client = MilvusClient()

has_collection = milvus_client.has_collection(collection_name, timeout=5)
if has_collection:
    milvus_client.drop_collection(collection_name)
milvus_client.create_collection(collection_name, dim, consistency_level="Strong", metric_type="L2")

print(fmt.format("    all collections    "))
print(milvus_client.list_collections())

print(fmt.format(f"schema of collection {collection_name}"))
print(milvus_client.describe_collection(collection_name))

rng = np.random.default_rng(seed=19530)
rows = [
        {"id": 1, "vector": rng.random((1, dim))[0], "a": 100},
        {"id": 2, "vector": rng.random((1, dim))[0], "b": 200},
        {"id": 3, "vector": rng.random((1, dim))[0], "c": 300},
        {"id": 4, "vector": rng.random((1, dim))[0], "d": 400},
        {"id": 5, "vector": rng.random((1, dim))[0], "e": 500},
        {"id": 6, "vector": rng.random((1, dim))[0], "f": 600},
]

print(fmt.format("Start inserting entities"))
insert_result = milvus_client.insert(collection_name, rows, progress_bar=True)
print(fmt.format("Inserting entities done"))
print(insert_result)
res = milvus_client.get_collection_stats(collection_name)
print(res)

Environment details

- Hardware/Softward conditions (OS, CPU, GPU, Memory):
- Method of installation (Docker, or from source):
- Milvus version (v0.3.1, or v0.4.0): master-20240115-fb4fbcf4
- pymilvus version: 2.4.0rc23
- Milvus configuration (Settings you made in `server_config.yaml`):

Anything else?

No response

binbinlv commented 10 months ago

/assign @czs007

binbinlv commented 9 months ago

This still exists in the latest version: pymilvus: 2.4.0rc30 milvus: master-20240205-a68b3213

>>> milvus_client.create_collection(collection_name, dim, consistency_level="Strong", metric_type="L2")
>>> res = milvus_client.get_collection_stats(collection_name)
>>> print(res)
{'row_count': 0}
tgvarner commented 23 hours ago

Any updates on this issue?