Get a list of collections

更新时间:
复制 MD 格式

Retrieve the names of all collections in a DashVector cluster.

Prerequisites

Before you begin, make sure that you have:

Request

GET https://{Endpoint}/v1/collections

Request parameters

ParameterLocationTypeRequiredDescription
{Endpoint}pathstrYesThe cluster endpoint. Find it on the cluster details page in the console.
dashvector-auth-tokenheaderstrYesThe API key for authentication.

Response parameters

ParameterTypeDescriptionExample
codeintStatus code. 0 indicates success. For details, see Status codes.0
messagestrStatus message.success
request_idstrUnique request identifier.89557fca-50ca-400d-9828-a6c9ba5a4228
outputarrayCollection 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"
VariableDescriptionWhere to find it
DASHVECTOR_API_KEYAPI keyManage API keys
DASHVECTOR_ENDPOINTCluster endpoint (without https://)Cluster details page in the console

curl

curl -H "dashvector-auth-token: ${DASHVECTOR_API_KEY}" \
  https://${DASHVECTOR_ENDPOINT}/v1/collections

Python

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