Get a collection
Retrieve an existing collection by name to perform operations such as inserting documents, searching for documents, and managing partitions.
Prerequisites
Before you begin, make sure that you have:
A DashVector cluster. For more information, see Create a cluster
An API key. For more information, see Manage API keys
The latest version of DashVector SDK for Java. For more information, see Install DashVector SDK
API definition
// DashVectorClient
public DashVectorCollection get(String name);Request parameters
| Parameter | Type | Required | Default value | Description |
|---|---|---|---|---|
| name | String | Yes | - | The name of an existing collection. |
Example
Replace <your-api-key> and <your-cluster-endpoint> with your actual values before running this code. We recommend storing credentials in environment variables to avoid hardcoding sensitive information. This example uses a collection named quickstart. To create one, see the example in Create a collection.
import com.aliyun.dashvector.DashVectorClient;
import com.aliyun.dashvector.DashVectorCollection;
import com.aliyun.dashvector.common.DashVectorException;
public class Main {
public static void main(String[] args) throws DashVectorException {
// Initialize the client with your API key and cluster endpoint
DashVectorClient client = new DashVectorClient("<your-api-key>", "<your-cluster-endpoint>");
// Retrieve the collection by name
DashVectorCollection collection = client.get("quickstart");
// Verify the operation succeeded
assert collection.isSuccess();
}
}Response parameters
The get method returns a DashVectorCollection object with the following methods:
| Method | Type | Description | Example |
|---|---|---|---|
| getCode() | int | Status code. For more information, see Status codes. | 0 |
| getMessage() | String | Response message | success |
| getRequestId() | String | Unique request ID | 19215409-ea66-4db9-8764-26ce2eb5bb99 |
| getName() | String | Collection name | complex |
| getCollectionMeta() | CollectionMeta | Collection metadata. For more information, see CollectionMeta. | See the following example |
| isSuccess() | Boolean | Whether the operation succeeded | true |
CollectionMeta example
{
"name": "quickstart",
"dimension": 4,
"dataType": "INT",
"metric": "dotproduct",
"status": "SERVING",
"fieldsSchema": {
"name": "STRING",
"weight": "FLOAT",
"age": "INT"
},
"partitionStatus": {
"default": "SERVING"
}
}What's next
Insert documents into the collection
Search for documents in the collection
Manage partitions within the collection