Vector index

Updated at:

A vector index stores and manages vector data in a vector bucket. Each index defines the dimension, distance metric, and metadata structure, which forms the foundation for vector retrieval.

Create vector index

  • A single vector bucket can contain a maximum of 100 vector indexes.

  • The request rate for the PutVectorIndex API operation is limited to 5 requests per second.

Note

OSS Vectors supports two types of vector indexes: Standard Mode and Fusion Mode. A Fusion-mode vector index lets you define multiple vector fields, scalar fields, and full-text fields within a single index. It must be created by using the separate PutVectorIndexFusion operation, which is currently supported only through ossutil, SDKs, and the API. The console does not support it yet. Fusion mode is currently in invitational preview.

Standard Mode

Console

  1. On the Vector Bucket page, click your vector bucket.

  2. On the Vector Indexes page, click Create Index Table.

  3. Configure the index parameters:

    • Index Table Name: Must be 1 to 63 characters long, contain only letters and digits, start with a letter, and be unique within the vector bucket.

    • Vector Data Type: The system default is float32 (floating-point).

    • Dimension: 1 to 4,096. All vectors added to this index must have the same dimension.

    • Distance Metric: Select a distance calculation method based on your use case.

      • Euclidean Distance: The straight-line distance between two points in space. This metric is suitable for measuring differences in numerical values.

      • Cosine Distance: Measures the difference in direction between two vectors. This metric is suitable for high-dimensional semantic similarity searches, such as with text or image embeddings.

    • Metadata Configuration: Configure non-filterable metadata fields to store additional information about vector data. This information is not used in search filters. The following limits apply:

      • Number of metadata fields: 1 to 100

      • Length of each metadata key: 1 to 63 bytes

  4. Click OK to create the index.

ossutil

Create an index named index for the examplebucket bucket. The index has 512 vector dimensions, uses the float32 data type, and the euclidean distance measure.

ossutil vectors-api put-vector-index --bucket examplebucket --index-name index --data-type float32 --dimension 512 --distance-metric euclidean

SDK

Python

import argparse
import alibabacloud_oss_v2 as oss
import alibabacloud_oss_v2.vectors as oss_vectors

parser = argparse.ArgumentParser(description="vector put vector index sample")
parser.add_argument('--region', help='The region in which the bucket is located.', required=True)
parser.add_argument('--bucket', help='The name of the bucket.', required=True)
parser.add_argument('--endpoint', help='The domain name that other services can use to access OSS')
parser.add_argument('--index_name', help='The name of the vector index.', required=True)
parser.add_argument('--account_id', help='The account ID.', required=True)

def main():
    args = parser.parse_args()

    # Load credentials from environment variables
    credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()

    # Using the SDK's default configuration
    cfg = oss.config.load_default()
    cfg.credentials_provider = credentials_provider
    cfg.region = args.region
    cfg.account_id = args.account_id
    cfg.use_internal_endpoint = True  # To access the service over the public network, set this parameter to False or remove this line.
    if args.endpoint is not None:
        cfg.endpoint = args.endpoint

    vector_client = oss_vectors.Client(cfg)

    result = vector_client.put_vector_index(oss_vectors.models.PutVectorIndexRequest(
        bucket=args.bucket,
        index_name=args.index_name,
        dimension=512,
        data_type='float32',
        distance_metric='euclidean',
        metadata={"nonFilterableMetadataKeys": ["key1", "key2"]}
    ))

    print(f'status code: {result.status_code},'
          f' request id: {result.request_id},'
    )

if __name__ == "__main__":
    main()

Go

package main

import (
	"context"
	"flag"
	"log"

	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/vectors"
)

var (
	region     string
	bucketName string
	accountId  string
	indexName  string
)

func init() {
	flag.StringVar(&region, "region", "", "The region in which the vector bucket is located.")
	flag.StringVar(&bucketName, "bucket", "", "The name of the vector bucket.")
	flag.StringVar(&accountId, "account-id", "", "The ID of the Alibaba Cloud account.")
	flag.StringVar(&indexName, "index", "", "The name of the vector index.")
}

func main() {
	flag.Parse()
	if len(bucketName) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, bucket name required")
	}

	if len(region) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, region required")
	}

	if len(accountId) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, accountId required")
	}

	if len(indexName) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, index required")
	}

	cfg := oss.LoadDefaultConfig().
		WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
		WithRegion(region).WithAccountId(accountId).
		// To access the service over the public internet, set this parameter to false or remove this line.
		WithUseInternalEndpoint(true)

	client := vectors.NewVectorsClient(cfg)

	request := &vectors.PutVectorIndexRequest{
		Bucket:         oss.Ptr(bucketName),
		DataType:       oss.Ptr("float32"),
		Dimension:      oss.Ptr(128),
		DistanceMetric: oss.Ptr("cosine"),
		IndexName:      oss.Ptr(indexName),
		Metadata: map[string]any{
			"nonFilterableMetadataKeys": []string{"foo", "bar"},
		},
	}
	result, err := client.PutVectorIndex(context.TODO(), request)
	if err != nil {
		log.Fatalf("failed to put vector index: %v", err)
	}
	log.Printf("put vector index result: %#v\n", result)
}

Java

import com.aliyun.sdk.service.oss2.credentials.CredentialsProvider;
import com.aliyun.sdk.service.oss2.credentials.EnvironmentVariableCredentialsProvider;
import com.aliyun.sdk.service.oss2.vectors.OSSVectorsClient;
import com.aliyun.sdk.service.oss2.vectors.models.PutVectorIndexRequest;
import com.aliyun.sdk.service.oss2.vectors.models.PutVectorIndexResult;

public class PutVectorIndexSample {
    public static void main(String[] args) throws Exception {
        CredentialsProvider provider = new EnvironmentVariableCredentialsProvider();
        try (OSSVectorsClient client = OSSVectorsClient.newBuilder()
                .region("cn-hangzhou")
                .accountId("1234567890")
                .credentialsProvider(provider)
                .build()) {
            PutVectorIndexRequest request = PutVectorIndexRequest.newBuilder()
                    .bucket("examplebucket")
                    .indexName("exampleindex")
                    .dataType("float32")
                    .dimension(3)
                    .distanceMetric("cosine")
                    .build();
            PutVectorIndexResult result = client.putVectorIndex(request);
            System.out.printf("status code: %d, request id: %s%n", result.statusCode(), result.requestId());
        }
    }
}

API

Call the PutVectorIndex operation to create a vector index.

Fusion Mode

Create a Fusion-mode vector index by using the separate PutVectorIndexFusion operation. Define the field structure of the index by using the schemaConfiguration parameter in the request body. You can create it by using ossutil, an SDK, or the API.

ossutil

Command format

ossutil vectors-api put-vector-index-fusion --bucket value --index-name value --vector-mode value --schema-configuration value --account-id value

Parameters

Parameter

Type

Description

--account-id

string

The ID of the Alibaba Cloud account. This option is required. If it is not specified, the command returns the AccountId is null error.

--bucket

string

The name of the vector bucket.

--index-name

string

The name of the vector index.

--vector-mode

string

The mode of the vector index. Set the value to fusion to create a Fusion-mode index.

--schema-configuration

string

The schema configuration of the vector index, in JSON format. If the option value contains the file:// prefix, the configuration is read from the specified file. For more information about the fields, see the PutVectorIndexFusion API documentation.

--schema-configuration

The --schema-configuration option supports JSON syntax. If the option value contains the file:// prefix, the configuration is read from the specified file. The JSON syntax is as follows:

{
    "fields": [
      {
        "name": "string",
        "type": "vector",
        "dataType": "float32",
        "dimension": int,
        "distanceMetric": "euclidean"
      },
      {
        "name": "string",
        "type": "long",
        "isArray": bool
      },
      {
        "name": "string",
        "type": "double",
        "isArray": bool
      },
      {
        "name": "string",
        "type": "ip"
      },
      {
        "name": "string",
        "type": "geoPoint"
      },
      {
        "name": "string",
        "type": "string",
        "isPartitionKey": bool
      },
      {
        "name": "string",
        "type": "string",
        "exactMatch": bool,
        "text": {
          "enabled": bool,
          "analyzer": "standard",
          "analyzerParameters": {
            "caseSensitive": bool,
            "delimitWord": bool
          }
        }
      },
      {
        "name": "string",
        "type": "string",
        "exactMatch": bool,
        "text": {
          "enabled": bool,
          "analyzer": "split",
          "analyzerParameters": {
            "caseSensitive": bool,
            "delimiter": "string"
          }
        }
      }
    ]
}
Note
  • This command requires ossutil 2.4.1 or later. For earlier versions, call the PutVectorIndexFusion operation by using the invoke-operation generic command.

  • For more information about the supported global command-line options, see Supported global command-line options.

Usage examples

Create a Fusion-mode vector index named my_index in the vector bucket named examplebucket.

Method 1: Read the schema configuration from a JSON file. The following example shows the content of the schema-configuration.json file:

{
  "fields": [
    {
      "name": "text_vector",
      "type": "vector",
      "dataType": "float32",
      "dimension": 4,
      "distanceMetric": "cosine"
    },
    {
      "name": "image_vector",
      "type": "vector",
      "dataType": "float32",
      "dimension": 4,
      "distanceMetric": "cosine"
    },
    {
      "name": "title",
      "type": "string",
      "exactMatch": false,
      "text": {
        "enabled": true,
        "analyzer": "standard",
        "analyzerParameters": {
          "caseSensitive": false,
          "delimitWord": false
        }
      }
    },
    {
      "name": "category",
      "type": "string",
      "isArray": true
    },
    {
      "name": "year",
      "type": "long"
    }
  ]
}
ossutil vectors-api put-vector-index-fusion --bucket examplebucket --index-name my_index --vector-mode fusion --schema-configuration file://schema-configuration.json --account-id 123456789012****

Method 2: Pass the JSON string directly on the command line.

ossutil vectors-api put-vector-index-fusion --bucket examplebucket --index-name my_index --vector-mode fusion --schema-configuration '{"fields":[{"name":"text_vector","type":"vector","dataType":"float32","dimension":4,"distanceMetric":"cosine"},{"name":"image_vector","type":"vector","dataType":"float32","dimension":4,"distanceMetric":"cosine"},{"name":"title","type":"string","exactMatch":false,"text":{"enabled":true,"analyzer":"standard","analyzerParameters":{"caseSensitive":false,"delimitWord":false}}},{"name":"category","type":"string","isArray":true},{"name":"year","type":"long"}]}' --account-id 123456789012****

SDK

Python

import argparse
import alibabacloud_oss_v2 as oss
import alibabacloud_oss_v2.vectors as oss_vectors

parser = argparse.ArgumentParser(description="put vector index fusion sample")
parser.add_argument('--region', help='The region in which the bucket is located.', required=True)
parser.add_argument('--bucket', help='The name of the bucket.', required=True)
parser.add_argument('--endpoint', help='The domain name that other services can use to access OSS')
parser.add_argument('--index_name', help='The name of the fusion vector index.', required=True)
parser.add_argument('--account_id', help='The account ID.', required=True)

def main():
    args = parser.parse_args()

    # Load credentials from environment variables
    credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()

    # Using the SDK's default configuration
    cfg = oss.config.load_default()
    cfg.credentials_provider = credentials_provider
    cfg.region = args.region
    cfg.account_id = args.account_id
    if args.endpoint is not None:
        cfg.endpoint = args.endpoint

    vector_client = oss_vectors.Client(cfg)

    # A fusion index is described by a schema listing every field, instead of
    # the single vector field that put_vector_index configures. This is the
    # typical e-commerce product schema: two vector fields for text and image
    # dual recall, scalar fields for filtering and sorting, and a tokenized
    # title for full text search.
    #
    # The schema is a plain dict, so any field type or property the service
    # supports travels through unchanged. A text field defaults to the
    # "standard" analyzer, English by word and Chinese by single character.
    # Write a boolean out explicitly when false is what you mean, an omitted
    # property and a property set to false are not the same thing to the
    # service. mode defaults to "fusion", so it is left out here.
    schema_configuration = {
        "fields": [
            {
                "name": "text_vector",
                "type": "vector",
                "dataType": "float32",
                "dimension": 768,
                "distanceMetric": "euclidean"
            },
            {
                "name": "image_vector",
                "type": "vector",
                "dataType": "float32",
                "dimension": 512,
                "distanceMetric": "euclidean"
            },
            {
                "name": "title",
                "type": "string",
                "exactMatch": True,
                "text": {
                    "enabled": True,
                    "analyzer": "standard"
                }
            },
            {
                "name": "brand",
                "type": "string"
            },
            {
                "name": "category",
                "type": "string",
                "isArray": True
            },
            {
                "name": "price",
                "type": "double"
            },
            {
                "name": "stock",
                "type": "long"
            },
            {
                "name": "on_sale",
                "type": "bool"
            }
        ]
    }

    result = vector_client.put_vector_index_fusion(oss_vectors.models.PutVectorIndexFusionRequest(
        bucket=args.bucket,
        index_name=args.index_name,
        schema_configuration=schema_configuration
    ))

    print(f'status code: {result.status_code},'
          f' request id: {result.request_id},'
    )

if __name__ == "__main__":
    main()

Go

package main

import (
	"context"
	"flag"
	"log"

	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/vectors"
)

var (
	region     string
	bucketName string
	accountId  string
	indexName  string
)

func init() {
	flag.StringVar(&region, "region", "", "The region in which the vector bucket is located.")
	flag.StringVar(&bucketName, "bucket", "", "The name of the vector bucket.")
	flag.StringVar(&accountId, "account-id", "", "The id of vector account.")
	flag.StringVar(&indexName, "index", "", "The name of vector index.")
}

func main() {
	flag.Parse()
	if len(bucketName) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, bucket name required")
	}
	if len(region) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, region required")
	}
	if len(accountId) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, accountId required")
	}
	if len(indexName) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, index required")
	}

	cfg := oss.LoadDefaultConfig().
		WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
		WithRegion(region).WithAccountId(accountId)

	client := vectors.NewVectorsClient(cfg)

	// Build the schema field list using FieldSchema structs
	request := &vectors.PutVectorIndexFusionRequest{
		Bucket:    oss.Ptr(bucketName),
		IndexName: oss.Ptr(indexName),
		Mode:      oss.Ptr("fusion"),
		SchemaConfiguration: &vectors.SchemaConfiguration{
			Fields: []map[string]any{
				vectors.FieldSchema{
					Name:           oss.Ptr("vector_1"),
					Type:           oss.Ptr("vector"),
					DataType:       oss.Ptr("float32"),
					Dimension:      oss.Ptr(1024),
					DistanceMetric: oss.Ptr("cosine"),
				}.ToMap(),
				vectors.FieldSchema{
					Name:           oss.Ptr("vector_2"),
					Type:           oss.Ptr("vector"),
					DataType:       oss.Ptr("float32"),
					Dimension:      oss.Ptr(512),
					DistanceMetric: oss.Ptr("cosine"),
				}.ToMap(),
				vectors.FieldSchema{
					Name:    oss.Ptr("timestamps"),
					Type:    oss.Ptr("long"),
					IsArray: oss.Ptr(true),
				}.ToMap(),
				vectors.FieldSchema{
					Name: oss.Ptr("price"),
					Type: oss.Ptr("double"),
				}.ToMap(),
				vectors.FieldSchema{
					Name: oss.Ptr("ip"),
					Type: oss.Ptr("ip"),
				}.ToMap(),
				vectors.FieldSchema{
					Name: oss.Ptr("location"),
					Type: oss.Ptr("geoPoint"),
				}.ToMap(),
				vectors.FieldSchema{
					Name: oss.Ptr("tag"),
					Type: oss.Ptr("string"),
				}.ToMap(),
				vectors.FieldSchema{
					Name:           oss.Ptr("user_id"),
					Type:           oss.Ptr("string"),
					IsPartitionKey: oss.Ptr(true),
				}.ToMap(),
				vectors.FieldSchema{
					Name:    oss.Ptr("tags"),
					Type:    oss.Ptr("string"),
					IsArray: oss.Ptr(true),
				}.ToMap(),
				vectors.FieldSchema{
					Name:       oss.Ptr("title_1"),
					Type:       oss.Ptr("string"),
					ExactMatch: oss.Ptr(true),
					Text: &vectors.TextSchema{
						Enabled:  oss.Ptr(true),
						Analyzer: oss.Ptr("standard"),
						AnalyzerParameters: &vectors.AnalyzerParameters{
							CaseSensitive: oss.Ptr(true),
							DelimitWord:   oss.Ptr(false),
						},
					},
				}.ToMap(),
				vectors.FieldSchema{
					Name:       oss.Ptr("title_2"),
					Type:       oss.Ptr("string"),
					ExactMatch: oss.Ptr(false),
					Text: &vectors.TextSchema{
						Enabled:  oss.Ptr(true),
						Analyzer: oss.Ptr("split"),
						AnalyzerParameters: &vectors.AnalyzerParameters{
							CaseSensitive: oss.Ptr(true),
							Delimiter:     oss.Ptr(" "),
						},
					},
				}.ToMap(),
			},
		},
	}

	result, err := client.PutVectorIndexFusion(context.TODO(), request)
	if err != nil {
		log.Fatalf("failed to put vector index fusion: %v", err)
	}
	log.Printf("put vector index fusion result: %#v\n", result)
}

Java

import com.aliyun.sdk.service.oss2.credentials.CredentialsProvider;
import com.aliyun.sdk.service.oss2.credentials.EnvironmentVariableCredentialsProvider;
import com.aliyun.sdk.service.oss2.vectors.OSSVectorsClient;
import com.aliyun.sdk.service.oss2.vectors.models.AnalyzerParameters;
import com.aliyun.sdk.service.oss2.vectors.models.AnalyzerType;
import com.aliyun.sdk.service.oss2.vectors.models.DistanceMetricType;
import com.aliyun.sdk.service.oss2.vectors.models.FieldSchema;
import com.aliyun.sdk.service.oss2.vectors.models.FieldType;
import com.aliyun.sdk.service.oss2.vectors.models.IndexModeType;
import com.aliyun.sdk.service.oss2.vectors.models.PutVectorIndexFusionRequest;
import com.aliyun.sdk.service.oss2.vectors.models.PutVectorIndexFusionResult;
import com.aliyun.sdk.service.oss2.vectors.models.SchemaConfiguration;
import com.aliyun.sdk.service.oss2.vectors.models.TextSchema;
import com.aliyun.sdk.service.oss2.vectors.models.VectorDataType;

import java.util.Arrays;
import java.util.List;

public class PutVectorIndexFusionSample {
    public static void main(String[] args) {
        CredentialsProvider provider = new EnvironmentVariableCredentialsProvider();

        try (OSSVectorsClient client = OSSVectorsClient.newBuilder()
                .region("cn-hangzhou")
                .accountId("1234567890")
                .credentialsProvider(provider)
                .build()) {

            String bucket = "examplebucket";
            String indexName = "exampleindex";

            // Define the vector field.
            FieldSchema vectorField = FieldSchema.newBuilder()
                    .name("vector_1")
                    .type(FieldType.VECTOR)
                    .dataType(VectorDataType.FLOAT32)
                    .dimension(1024)
                    .distanceMetric(DistanceMetricType.COSINE)
                    .build();

            // Define the partition key field. Only one string field can be the partition key.
            FieldSchema partitionKey = FieldSchema.newBuilder()
                    .name("user_id")
                    .type(FieldType.STRING)
                    .isPartitionKey(true)
                    .build();

            // Define a string field with full-text search enabled.
            FieldSchema title = FieldSchema.newBuilder()
                    .name("title")
                    .type(FieldType.STRING)
                    .exactMatch(true)
                    .text(TextSchema.newBuilder()
                            .enabled(true)
                            .analyzer(AnalyzerType.STANDARD)
                            .analyzerParameters(AnalyzerParameters.newBuilder()
                                    .caseSensitive(false)
                                    .delimitWord(false)
                                    .build())
                            .build())
                    .build();

            // Define an array field.
            FieldSchema timestamps = FieldSchema.newBuilder()
                    .name("timestamps")
                    .type(FieldType.LONG)
                    .isArray(true)
                    .build();

            List<FieldSchema> fields = Arrays.asList(vectorField, partitionKey, title, timestamps);

            // Build the request. The mode is FUSION by default.
            PutVectorIndexFusionRequest request = PutVectorIndexFusionRequest.newBuilder()
                    .bucket(bucket)
                    .indexName(indexName)
                    .mode(IndexModeType.FUSION)
                    .schemaConfiguration(SchemaConfiguration.newBuilder().fields(fields).build())
                    .build();

            PutVectorIndexFusionResult result = client.putVectorIndexFusion(request);

            System.out.printf("Status code:%d, request id:%s%n",
                    result.statusCode(), result.requestId());
        }
    }
}

API

Call the PutVectorIndexFusion operation to create a Fusion-mode vector index.

Get vector index

Standard Mode

Console

On the Vector Bucket page, click the vector bucket that you created. On the Vector Indexes page, you can view the vector index information.

ossutil

Retrieve the properties of the vector index named index in the vector bucket examplebucket.

ossutil vectors-api get-vector-index --bucket examplebucket --index-name index

SDK

Python

import argparse
import alibabacloud_oss_v2 as oss
import alibabacloud_oss_v2.vectors as oss_vectors

parser = argparse.ArgumentParser(description="vector get vector index sample")
parser.add_argument('--region', help='The region of the bucket.', required=True)
parser.add_argument('--bucket', help='The name of the bucket.', required=True)
parser.add_argument('--endpoint', help='The domain name for accessing OSS.')
parser.add_argument('--index_name', help='The name of the vector index.', required=True)
parser.add_argument('--account_id', help='The account ID.', required=True)

def main():
    args = parser.parse_args()

    # Load credentials from environment variables
    credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()

    # Use the SDK's default configuration
    cfg = oss.config.load_default()
    cfg.credentials_provider = credentials_provider
    cfg.region = args.region
    cfg.account_id = args.account_id
    cfg.use_internal_endpoint = True  # To access OSS over the public network, set this to False or remove this line.
    if args.endpoint is not None:
        cfg.endpoint = args.endpoint

    vector_client = oss_vectors.Client(cfg)

    result = vector_client.get_vector_index(oss_vectors.models.GetVectorIndexRequest(
        bucket=args.bucket,
        index_name=args.index_name,
    ))

    print(f'status code: {result.status_code},'
          f' request id: {result.request_id},'
          )

    if result.index:
        print(f'index name: {result.index}')

if __name__ == "__main__":
    main()

Go

package main

import (
	"context"
	"flag"
	"log"

	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/vectors"
)

var (
	region     string
	bucketName string
	indexName  string
	accountId  string
)

func init() {
	flag.StringVar(&region, "region", "", "The region where the bucket is located.")
	flag.StringVar(&bucketName, "bucket", "", "The name of the bucket.")
	flag.StringVar(&indexName, "index", "", "The name of the vector index.")
	flag.StringVar(&accountId, "account-id", "", "The ID of the Alibaba Cloud account.")
}

func main() {
	flag.Parse()
	if len(bucketName) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, bucket name required")
	}

	if len(region) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, region required")
	}

	if len(indexName) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, index required")
	}

	if len(accountId) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, accountId required")
	}

	cfg := oss.LoadDefaultConfig().
		WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
		WithRegion(region).WithAccountId(accountId).
		// To access the service over a public endpoint, set this to false or remove this line.
		WithUseInternalEndpoint(true)

	client := vectors.NewVectorsClient(cfg)

	request := &vectors.GetVectorIndexRequest{
		Bucket:    oss.Ptr(bucketName),
		IndexName: oss.Ptr(indexName),
	}
	result, err := client.GetVectorIndex(context.TODO(), request)
	if err != nil {
		log.Fatalf("failed to get vector index %v", err)
	}
	log.Printf("get vector index result:%#v\n", result)
}

Java

import com.aliyun.sdk.service.oss2.credentials.CredentialsProvider;
import com.aliyun.sdk.service.oss2.credentials.EnvironmentVariableCredentialsProvider;
import com.aliyun.sdk.service.oss2.vectors.OSSVectorsClient;
import com.aliyun.sdk.service.oss2.vectors.models.GetVectorIndexRequest;
import com.aliyun.sdk.service.oss2.vectors.models.GetVectorIndexResult;

public class GetVectorIndexSample {
    public static void main(String[] args) throws Exception {
        CredentialsProvider provider = new EnvironmentVariableCredentialsProvider();
        try (OSSVectorsClient client = OSSVectorsClient.newBuilder()
                .region("cn-hangzhou")
                .accountId("1234567890")
                .credentialsProvider(provider)
                .build()) {
            GetVectorIndexRequest request = GetVectorIndexRequest.newBuilder()
                    .bucket("examplebucket")
                    .indexName("exampleindex")
                    .build();
            GetVectorIndexResult result = client.getVectorIndex(request);
            System.out.printf("status code: %d, request id: %s%n", result.statusCode(), result.requestId());
        }
    }
}

API

Call the GetVectorIndex operation to retrieve information about a vector index.

Fusion Mode

A Fusion-mode vector index is retrieved by using the same GetVectorIndex operation. The response includes the mode parameter (standard or fusion), which identifies the type of the index. A Fusion-mode vector index returns its field structure in the schemaConfiguration parameter, instead of the vector data type, dimension, distance metric, and non-filterable metadata fields returned for a Standard-mode vector index. For more information about the parameters, see the GetVectorIndex API documentation.

List vector indexes

The ListVectorIndexes API operation returns a maximum of 500 indexes per request. You can use pagination to retrieve subsequent batches of the index list. The concurrency limit for this operation is 16.

Standard Mode

Console

On the Vector Bucket page, click your vector bucket. The Vector Indexes page opens and lists all vector indexes in the current vector bucket.

ossutil

List all vector indexes in the vector bucket named examplebucket.

ossutil vectors-api list-vector-indexes --bucket examplebucket

SDK

Python

import argparse
import alibabacloud_oss_v2 as oss
import alibabacloud_oss_v2.vectors as oss_vectors

parser = argparse.ArgumentParser(description="list vector indexes sample")

parser.add_argument('--region', help='The region where the bucket is located.', required=True)
parser.add_argument('--endpoint', help='The OSS access endpoint.')
parser.add_argument('--account_id', help='The account ID.', required=True)
parser.add_argument('--bucket', help='The name of the bucket.', required=True)

def main():

    args = parser.parse_args()

    # Load credential values from environment variables.
    credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()

    # Use the SDK's default configuration.
    cfg = oss.config.load_default()
    cfg.credentials_provider = credentials_provider
    cfg.region = args.region
    cfg.account_id = args.account_id
    cfg.use_internal_endpoint = True  # To connect over the public network, set this to False or remove this line.
    if args.endpoint is not None:
        cfg.endpoint = args.endpoint

    client = oss_vectors.Client(cfg)

    # Create the paginator for the ListVectorIndexes operation.
    paginator = client.list_vector_indexes_paginator()

    # Iterate through the pages of vector indexes.
    for page in paginator.iter_page(oss_vectors.models.ListVectorIndexesRequest(
        bucket=args.bucket
        )
    ):
        for o in page.indexes:
            print(f'Index: {o.get("indexName")}, {o.get("dataType")}, {o.get("dimension")}, {o.get("status")}')

if __name__ == "__main__":
    main()

Go

package main

import (
	"context"
	"flag"
	"log"

	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/vectors"
)

var (
	region     string
	bucketName string
	accountId  string
)

func init() {
	flag.StringVar(&region, "region", "", "The region in which the vector bucket is located.")
	flag.StringVar(&bucketName, "bucket", "", "The name of the vector bucket.")
	flag.StringVar(&accountId, "account-id", "", "The ID of your Alibaba Cloud account.")
}

func main() {
	flag.Parse()
	if len(region) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, region required")
	}

	if len(bucketName) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, bucket required")
	}

	if len(accountId) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, accountId required")
	}

	cfg := oss.LoadDefaultConfig().
		WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
		WithRegion(region).WithAccountId(accountId).
		// To access the service over the public internet, set this parameter to false or remove this line.
		WithUseInternalEndpoint(true)

	client := vectors.NewVectorsClient(cfg)

	request := &vectors.ListVectorIndexesRequest{
		Bucket: oss.Ptr(bucketName),
	}
	p := client.NewListVectorIndexesPaginator(request)

	var i int
	log.Println("Vector Indexes:")
	for p.HasNext() {
		i++

		page, err := p.NextPage(context.TODO())
		if err != nil {
			log.Fatalf("failed to get page %v, %v", i, err)
		}

		// Log the found indexes.
		for _, index := range page.Indexes {
			log.Printf("index:%v, %v, %v, %v\n", oss.ToString(index.IndexName), oss.ToTime(index.CreateTime), oss.ToString(index.DataType), oss.ToString(index.Status))
		}
	}
}

Java

import com.aliyun.sdk.service.oss2.credentials.CredentialsProvider;
import com.aliyun.sdk.service.oss2.credentials.EnvironmentVariableCredentialsProvider;
import com.aliyun.sdk.service.oss2.vectors.OSSVectorsClient;
import com.aliyun.sdk.service.oss2.vectors.models.ListVectorIndexesRequest;
import com.aliyun.sdk.service.oss2.vectors.models.ListVectorIndexesResult;

public class ListVectorIndexesSample {
    public static void main(String[] args) throws Exception {
        CredentialsProvider provider = new EnvironmentVariableCredentialsProvider();
        try (OSSVectorsClient client = OSSVectorsClient.newBuilder()
                .region("cn-hangzhou")
                .accountId("1234567890")
                .credentialsProvider(provider)
                .build()) {
            ListVectorIndexesRequest request = ListVectorIndexesRequest.newBuilder()
                    .bucket("examplebucket")
                    .build();
            ListVectorIndexesResult result = client.listVectorIndexes(request);
            System.out.printf("status code: %d, request id: %s%n", result.statusCode(), result.requestId());
        }
    }
}

API

Call the ListVectorIndexes operation to list all vector indexes in a vector bucket.

Fusion Mode

When you list vector indexes, the response returns the mode parameter (standard or fusion) for each index to identify its type. Standard-mode and Fusion-mode vector indexes in the same vector bucket may appear together in the list results. For a Fusion-mode vector index, the list operation returns only basic information, such as the index name, mode, status, and creation time. For more information about these parameters, see the ListVectorIndexes API documentation. To retrieve the complete schemaConfiguration field structure of a Fusion-mode vector index, call the GetVectorIndex operation.

Delete vector index

Deleting a vector index also deletes all vector data it contains. This operation is irreversible. Proceed with caution and back up any important data.

Console

On the Vector Bucket page, click the vector bucket that you created. On the Vector Indexes page, select the index to delete and confirm the deletion.

ossutil

Delete the vector index named index from the bucket named examplebucket.

ossutil vectors-api delete-vector-index --bucket examplebucket --index-name index

SDK

Python

import argparse
import alibabacloud_oss_v2 as oss
import alibabacloud_oss_v2.vectors as oss_vectors

parser = argparse.ArgumentParser(description="vector delete vector index sample")
parser.add_argument('--region', help='The region where the bucket is located.', required=True)
parser.add_argument('--bucket', help='The name of the bucket.', required=True)
parser.add_argument('--endpoint', help='The endpoint to access OSS.')
parser.add_argument('--index_name', help='The name of the vector index.', required=True)
parser.add_argument('--account_id', help='Your Alibaba Cloud account ID.', required=True)

def main():
    args = parser.parse_args()

    # Loading credentials values from the environment variables
    credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()

    # Using the SDK's default configuration
    cfg = oss.config.load_default()
    cfg.credentials_provider = credentials_provider
    cfg.region = args.region
    cfg.account_id = args.account_id
    cfg.use_internal_endpoint = True  # To access OSS over the public network, set this parameter to False or remove this line.
    if args.endpoint is not None:
        cfg.endpoint = args.endpoint

    vector_client = oss_vectors.Client(cfg)

    result = vector_client.delete_vector_index(oss_vectors.models.DeleteVectorIndexRequest(
        bucket=args.bucket,
        index_name=args.index_name,
    ))

    print(f'status code: {result.status_code},'
          f' request id: {result.request_id},'
    )

if __name__ == "__main__":
    main()

Go

package main

import (
	"context"
	"flag"
	"log"

	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/vectors"
)

var (
	region     string
	bucketName string
	indexName  string
	accountId  string
)

func init() {
	flag.StringVar(&region, "region", "", "The region in which the vector bucket is located.")
	flag.StringVar(&bucketName, "bucket", "", "The name of the vector bucket.")
	flag.StringVar(&indexName, "index", "", "The name of the vector index.")
	flag.StringVar(&accountId, "account-id", "", "The ID of the Alibaba Cloud account.")
}

func main() {
	flag.Parse()
	if len(bucketName) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, bucket name required")
	}

	if len(region) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, region required")
	}

	if len(indexName) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, index required")
	}

	if len(accountId) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, accountId required")
	}

	cfg := oss.LoadDefaultConfig().
		WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
		WithRegion(region).WithAccountId(accountId).
		// To access OSS over the Internet, set this to false or remove this line.
		WithUseInternalEndpoint(true)

	client := vectors.NewVectorsClient(cfg)

	request := &vectors.DeleteVectorIndexRequest{
		Bucket:    oss.Ptr(bucketName),
		IndexName: oss.Ptr(indexName),
	}
	result, err := client.DeleteVectorIndex(context.TODO(), request)
	if err != nil {
		log.Fatalf("failed to delete vector index %v", err)
	}

	log.Printf("delete vector index result:%#v\n", result)
}

Java

import com.aliyun.sdk.service.oss2.credentials.CredentialsProvider;
import com.aliyun.sdk.service.oss2.credentials.EnvironmentVariableCredentialsProvider;
import com.aliyun.sdk.service.oss2.vectors.OSSVectorsClient;
import com.aliyun.sdk.service.oss2.vectors.models.DeleteVectorIndexRequest;
import com.aliyun.sdk.service.oss2.vectors.models.DeleteVectorIndexResult;

public class DeleteVectorIndexSample {
    public static void main(String[] args) throws Exception {
        CredentialsProvider provider = new EnvironmentVariableCredentialsProvider();
        try (OSSVectorsClient client = OSSVectorsClient.newBuilder()
                .region("cn-hangzhou")
                .accountId("1234567890")
                .credentialsProvider(provider)
                .build()) {
            DeleteVectorIndexRequest request = DeleteVectorIndexRequest.newBuilder()
                    .bucket("examplebucket")
                    .indexName("exampleindex")
                    .build();
            DeleteVectorIndexResult result = client.deleteVectorIndex(request);
            System.out.printf("status code: %d, request id: %s%n", result.statusCode(), result.requestId());
        }
    }
}

API

Call the DeleteVectorIndex operation to delete a vector index.