List partitions
Updated at:
List all partitions in a DashVector collection using the Python SDK.
Partitions organize vectors within a collection into logical groups. Use list_partitions() to retrieve the names of all partitions in a collection. All partitions are returned in a single call.
Prerequisites
API reference
Collection.list_partitions() -> DashVectorResponseThis method takes no request parameters.
Example
Note
Replace the following placeholders with your actual values before you run the code.
| Placeholder | Description | Example |
|---|---|---|
<your-api-key> | API key for your cluster | LTAI5tXxx |
<your-cluster-endpoint> | Endpoint of your cluster | vrs-xxx.dashvector.region.aliyuncs.com |
This example uses a collection named quickstart. To create one, see the "Example" section of Create a collection.
import dashvector
client = dashvector.Client(
api_key='<your-api-key>',
endpoint='<your-cluster-endpoint>'
)
collection = client.get(name='quickstart')
# List all partitions in the collection
partitions = collection.list_partitions()
if partitions:
for pt in partitions:
print(pt)
else:
print(partitions) # Print the error detailsExpected output:
default
shoesAdditional operations
The returned partitions object also supports length checks and membership tests:
# Number of partitions
print(len(partitions))
# Check if a specific partition exists
print('quickstart' in partitions)Expected output:
2
TrueResponse parameters
list_partitions() returns a DashVectorResponse object with the following fields:
| Parameter | Type | Description | Example |
|---|---|---|---|
| code | int | Status code. See Status codes. | 0 |
| message | str | Response message. | success |
| request_id | str | Unique request ID. | 19215409-ea66-4db9-8764-26ce2eb5bb99 |
| output | list[str] | Names of all partitions in the collection. | ['shoes', 'default'] |
What's next
Is this page helpful?