Get partition statistics
Retrieve statistics for a partition in a collection, such as the total document count. Use this to monitor data distribution across partitions or verify document insertion.
Prerequisites
Before you begin, ensure that you have:
An API key
The DashVector SDK for Python (latest version)
API signature
Collection.stats_partition(name: str) -> DashVectorResponseRequest parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| name | str | Yes | The name of the partition to query |
Response
A DashVectorResponse object is returned with the following fields:
| Field | Type | Description | Example |
|---|---|---|---|
| code | int | Status code. For more information, see Status codes. | 0 |
| message | str | Status message | success |
| request_id | str | Unique request identifier | 19215409-ea66-4db9-8764-26ce2eb5bb99 |
| output | PartitionStats | Partition statistics, including total_doc_count |
Example
This example retrieves the document count for a partition named shoes in the quickstart collection.
This example requires a collection named quickstart and a partition named shoes. To set these up, see the examples in Create a collection and Create a partition.
Replace <your-api-key> and <your-cluster-endpoint> with your actual API key and cluster endpoint.
import dashvector
# 1. Initialize the client
client = dashvector.Client(
api_key='<your-api-key>',
endpoint='<your-cluster-endpoint>'
)
# 2. Get the collection
collection = client.get(name='quickstart')
# 3. Query partition statistics
ret = collection.stats_partition('shoes')
print(ret)Sample response:
{
"code": 0,
"message": "",
"requests_id": "330a2bcb-e4a7-4fc6-a711-2fe5f8a24e8c",
"output": {
"total_doc_count": 0
}
}A total_doc_count of 0 indicates that the partition exists but contains no documents. After you insert documents into this partition, total_doc_count returns the total number of stored documents.