Retrieve the names of all collections in a DashVector cluster.
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 the DashVector SDK. For more information, see Install DashVector SDK
Request
GET https://{Endpoint}/v1/collectionsRequest parameters
| Parameter | Location | Type | Required | Description |
|---|---|---|---|---|
| {Endpoint} | path | str | Yes | The cluster endpoint. Find it on the cluster details page in the console. |
| dashvector-auth-token | header | str | Yes | The API key for authentication. |
Response parameters
| Parameter | Type | Description | Example |
|---|---|---|---|
| code | int | Status code. 0 indicates success. For details, see Status codes. | 0 |
| message | str | Status message. | success |
| request_id | str | Unique request identifier. | 89557fca-50ca-400d-9828-a6c9ba5a4228 |
| output | array | Collection names in the cluster. | ["my_collection1", "my_collection2"] |
Examples
Set the following environment variables before running the examples:
export DASHVECTOR_API_KEY="your_api_key"
export DASHVECTOR_ENDPOINT="your_cluster_endpoint"| Variable | Description | Where to find it |
|---|---|---|
DASHVECTOR_API_KEY | API key | Manage API keys |
DASHVECTOR_ENDPOINT | Cluster endpoint (without https://) | Cluster details page in the console |
curl
curl -H "dashvector-auth-token: ${DASHVECTOR_API_KEY}" \
https://${DASHVECTOR_ENDPOINT}/v1/collectionsPython
import os
import requests
api_key = os.environ["DASHVECTOR_API_KEY"]
endpoint = os.environ["DASHVECTOR_ENDPOINT"]
response = requests.get(
f"https://{endpoint}/v1/collections",
headers={"dashvector-auth-token": api_key},
)
print(response.json())Java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class ListCollections {
public static void main(String[] args) throws Exception {
String apiKey = System.getenv("DASHVECTOR_API_KEY");
String endpoint = System.getenv("DASHVECTOR_ENDPOINT");
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://" + endpoint + "/v1/collections"))
.header("dashvector-auth-token", apiKey)
.GET()
.build();
HttpResponse<String> response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}Go
package main
import (
"fmt"
"io"
"net/http"
"os"
)
func main() {
apiKey := os.Getenv("DASHVECTOR_API_KEY")
endpoint := os.Getenv("DASHVECTOR_ENDPOINT")
req, _ := http.NewRequest("GET", "https://"+endpoint+"/v1/collections", nil)
req.Header.Set("dashvector-auth-token", apiKey)
resp, err := http.DefaultClient.Do(req)
if err != nil {
fmt.Println("Error:", err)
return
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}Sample response
{
"request_id": "89557fca-50ca-400d-9828-a6c9ba5a4228",
"code": 0,
"message": "",
"output": [
"quickstart"
]
}What's next
Create a collection -- Create a new collection in the cluster.
Describe a collection -- Get details about a specific collection.
Delete a collection -- Remove a collection from the cluster.
该文章对您有帮助吗?