OSS vector search locates objects across buckets by semantic content, multimedia properties, metadata, ETags, tags, and custom metadata -- without exact file names or paths.
Supported regions
| Region | Vector search | Audio search |
|---|---|---|
| China (Qingdao) | Supported | Supported |
| China (Beijing) | Supported | Supported |
| China (Zhangjiakou) | Supported | Supported |
| China (Hangzhou) | Supported | Supported |
| China (Shanghai) | Supported | Supported |
| China (Shenzhen) | Supported | Supported |
| China (Guangzhou) | Supported | Supported |
| China (Chengdu) | Supported | Supported |
| China (Hong Kong) | Supported | Not supported |
| Singapore | Supported | Not supported |
| Indonesia (Jakarta) | Supported | Not supported |
| Germany (Frankfurt) | Supported | Not supported |
Enable vector search
The bucket must be in a supported region. For SDK access, configure the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables.
OSS console
Log on to the OSS console.
Click Buckets, then click the name of the target bucket.
In the left-side navigation pane, choose Object Management > Data Indexing.
On the Data Indexing page, if this is your first time using data indexing, follow the instructions to grant permissions to the AliyunMetaQueryDefaultRole role. After granting permissions, click Enable Data Indexing.
In the retrieval method section, select AISearch and click Enable.
Building the metadata index takes time depending on the number of objects in the bucket. Refresh the page to check the status.
Alibaba Cloud SDK
Java
Java SDK 3.18.2 or later is required. For more information, see Vector search (Java SDK).
import com.aliyun.oss.*;
import com.aliyun.oss.common.auth.*;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.model.MetaQueryMode;
public class OpenMetaQuery {
public static void main(String[] args) throws com.aliyuncs.exceptions.ClientException {
// Specify the endpoint of the region. In this example, the endpoint of the China (Hangzhou) region is used. Specify your actual endpoint.
String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Specify the name of the bucket. Example: examplebucket.
String bucketName = "examplebucket";
// Obtain a credential from the environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
// Specify the region of the bucket. In this example, the China (Hangzhou) region is used. Set the region to cn-hangzhou.
String region = "cn-hangzhou";
// Create an OSSClient instance.
// When the OSSClient instance is no longer used, call the shutdown method to release resources.
ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
OSS ossClient = OSSClientBuilder.create()
.endpoint(endpoint)
.credentialsProvider(credentialsProvider)
.clientConfiguration(clientBuilderConfiguration)
.region(region)
.build();
try {
// Enable AISearch.
ossClient.openMetaQuery(bucketName, MetaQueryMode.SEMANTIC);
} catch (OSSException oe) {
System.out.println("Error Message:" + oe.getErrorMessage());
System.out.println("Error Code:" + oe.getErrorCode());
System.out.println("Request ID:" + oe.getRequestId());
System.out.println("Host ID:" + oe.getHostId());
} catch (ClientException ce) {
System.out.println("Error Message: " + ce.getMessage());
} finally {
// Shut down the OSSClient instance.
if(ossClient != null){
ossClient.shutdown();
}
}
}
}Python
For more information, see Vector search.
import argparse
import alibabacloud_oss_v2 as oss
# Create a command-line argument parser and add a description.
parser = argparse.ArgumentParser(description="open meta query sample")
# Add the required command-line argument --region to specify the region where the bucket is located.
parser.add_argument('--region', help='The region in which the bucket is located.', required=True)
# Add the required command-line argument --bucket to specify the name of the bucket to operate on.
parser.add_argument('--bucket', help='The name of the bucket.', required=True)
# Add the optional command-line argument --endpoint to specify the domain name used to access OSS.
parser.add_argument('--endpoint', help='The domain names that other services can use to access OSS')
def main():
# Parse command-line arguments.
args = parser.parse_args()
# Load authentication information from environment variables.
credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()
# Use the default configurations provided by the SDK.
cfg = oss.config.load_default()
# Set the credentials provider.
cfg.credentials_provider = credentials_provider
# Set the region based on the command-line arguments.
cfg.region = args.region
# If an endpoint is provided, update the endpoint in the configuration.
if args.endpoint is not None:
cfg.endpoint = args.endpoint
# Create an OSS client.
client = oss.Client(cfg)
# Build an OpenMetaQuery request to enable the vector search feature for the bucket.
result = client.open_meta_query(oss.OpenMetaQueryRequest(
bucket=args.bucket,
mode='semantic',# Set to "semantic" to select vector search.
))
# Print the status code and request ID of the result.
print(f'status code: {result.status_code},'
f' request id: {result.request_id},'
)
# Call the main function when running as the main program.
if __name__ == "__main__":
main()Go
For more information, see Vector search (Go SDK V2).
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"
)
var (
region string
bucketName string
)
// The init function is executed before the main function to initialize the program.
func init() {
// Use a command line parameter to specify the region.
flag.StringVar(®ion, "region", "", "The region in which the bucket is located.")
// Use a command line parameter to specify the bucket name.
flag.StringVar(&bucketName, "bucket", "", "The name of the bucket.")
}
func main() {
flag.Parse() // Parse the command line parameters.
// Check whether the bucket name is specified. If the bucket name is not specified, return the default parameters and exit the program.
if len(bucketName) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, bucket name required")
}
// Check whether the region is specified. If the region is not specified, return the default parameters and exit the program.
if len(region) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, region required")
}
// Create and configure a client and use environment variables to pass the credential provider.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
client := oss.NewClient(cfg) // Use the client configurations to create a new OSSClient instance.
// Create an OpenMetaQuery request to enable AISearch for a specific bucket.
request := &oss.OpenMetaQueryRequest{
Bucket: oss.Ptr(bucketName),
Mode: oss.Ptr("semantic"), // Set Mode to semantic, which specifies that AISearch is enabled.
}
result, err := client.OpenMetaQuery(context.TODO(), request)
if err != nil {
log.Fatalf("failed to open meta query %v", err)
}
log.Printf("open meta query result:%#v\n", result) // Display the results of the request.
}PHP
For more information, see Vector search (PHP SDK V2).
<?php
// Include the autoloader file to ensure that dependency libraries can be loaded correctly.
require_once __DIR__ . '/../vendor/autoload.php';
use AlibabaCloud\Oss\V2 as Oss;
// Define the description for command-line arguments.
$optsdesc = [
"region" => ['help' => 'The region in which the bucket is located.', 'required' => True], // The region where the bucket is located (required).
"endpoint" => ['help' => 'The domain names that other services can use to access OSS.', 'required' => False], // The endpoint (optional).
"bucket" => ['help' => 'The name of the bucket', 'required' => True], // The bucket name (required).
];
// Convert the argument descriptions to the long options format required by getopt.
// A colon ":" after each argument indicates that the argument requires a value.
$longopts = \array_map(function ($key) {
return "$key:";
}, array_keys($optsdesc));
// Parse command-line arguments.
$options = getopt("", $longopts);
// Verify that all required arguments are present.
foreach ($optsdesc as $key => $value) {
if ($value['required'] === True && empty($options[$key])) {
$help = $value['help']; // Get the help information for the argument.
echo "Error: the following arguments are required: --$key, $help" . PHP_EOL;
exit(1); // If a required argument is missing, exit the program.
}
}
// Extract values from the parsed arguments.
$region = $options["region"]; // The region where the bucket is located.
$bucket = $options["bucket"]; // The bucket name.
// Load credentials from environment variables.
// Use EnvironmentVariableCredentialsProvider to read the Access Key ID and Access Key Secret from environment variables.
$credentialsProvider = new Oss\Credentials\EnvironmentVariableCredentialsProvider();
// Use the default configuration of the SDK.
$cfg = Oss\Config::loadDefault();
$cfg->setCredentialsProvider($credentialsProvider); // Set the credentials provider.
$cfg->setRegion($region); // Set the region where the bucket is located.
if (isset($options["endpoint"])) {
$cfg->setEndpoint($options["endpoint"]); // If an endpoint is provided, set the endpoint.
}
// Create an OSS client instance.
$client = new Oss\Client($cfg);
// Enable the vector search feature.
$request = new Oss\Models\OpenMetaQueryRequest($bucket,'semantic');
$result = $client->openMetaQuery($request);
printf(
'status code:' . $result->statusCode . PHP_EOL .
'request id:' . $result->requestId
);ossutil
Enable vector search for the bucket named examplebucket:
ossutil api open-meta-query --bucket examplebucket --meta-query-mode semanticFor more information, see open-meta-query.
Search for objects
OSS console
The following example searches for files that contain "glowing buildings", are in JPG format, and have dimensions within 800 x 1200 pixels. The expected result is the "Night view by the river.jpg" image.

Log on to the OSS console.
Click Buckets, then click the name of the target bucket.
In the left-side navigation pane, choose Object Management > Data Indexing.
Set the Search Criteria. Keep default settings for other parameters.
In the Semantic Content section, enter a description of the image, for example,
glowing buildings.
For Multimedia Type, select Image.

Set Image Format to JPG/JPEG.
Set Image Width to less than 800 px.
Set Image Height to less than 1200 px.
Click Query Now. The search results match the expected output. The file is found based on the content description.

For the complete list of search criteria and output settings, see Search criteria reference.
Alibaba Cloud SDK
Java
Java SDK 3.18.2 or later is required. For more information, see Vector search (Java SDK).
import com.aliyun.oss.*;
import com.aliyun.oss.common.auth.CredentialsProviderFactory;
import com.aliyun.oss.common.auth.EnvironmentVariableCredentialsProvider;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.model.*;
import java.util.ArrayList;
import java.util.List;
public class DoMetaQuery {
public static void main(String[] args) throws Exception {
// Specify the endpoint of the region. In this example, the endpoint of the China (Hangzhou) region is used. Specify your actual endpoint.
String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Specify the name of the bucket. Example: examplebucket.
String bucketName = "examplebucket";
// Obtain a credential from the environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
// Specify the region of the bucket. In this example, the China (Hangzhou) region is used. Set the region to cn-hangzhou.
String region = "cn-hangzhou";
// Create an OSSClient instance.
// When the OSSClient instance is no longer used, call the shutdown method to release resources.
ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
OSS ossClient = OSSClientBuilder.create()
.endpoint(endpoint)
.credentialsProvider(credentialsProvider)
.clientConfiguration(clientBuilderConfiguration)
.region(region)
.build();
try {
int maxResults = 20;
List mediaTypes = new ArrayList();
mediaTypes.add("image");
String query = "Snow";
String simpleQuery = "{\"Operation\":\"gt\", \"Field\": \"Size\", \"Value\": \"30\"}";
String sort = "Size";
DoMetaQueryRequest doMetaQueryRequest = new DoMetaQueryRequest(bucketName, maxResults, query, sort, MetaQueryMode.SEMANTIC, mediaTypes, simpleQuery);
DoMetaQueryResult doMetaQueryResult = ossClient.doMetaQuery(doMetaQueryRequest);
} catch (OSSException oe) {
System.out.println("Error Message: " + oe.getErrorMessage());
System.out.println("Error Code: " + oe.getErrorCode());
System.out.println("Request ID: " + oe.getRequestId());
System.out.println("Host ID: " + oe.getHostId());
} catch (ClientException ce) {
System.out.println("Error Message: " + ce.getMessage());
} finally {
if(ossClient != null){
ossClient.shutdown();
}
}
}
}Python
For more information, see Vector search.
import argparse
import alibabacloud_oss_v2 as oss
# Create a command-line argument parser to handle command-line input.
parser = argparse.ArgumentParser(description="do meta query semantic sample")
# Add required command-line arguments.
parser.add_argument('--region', help='The region in which the bucket is located.', required=True) # The region where the bucket is located.
parser.add_argument('--bucket', help='The name of the bucket.', required=True) # The bucket name.
parser.add_argument('--endpoint', help='The domain names that other services can use to access OSS') # The OSS endpoint, optional.
def main():
# Parse command-line arguments.
args = parser.parse_args()
# Load access credentials from environment variables.
# Before running, you must set the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables.
credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()
# Load the default SDK configuration.
cfg = oss.config.load_default()
# Set the credentials provider.
cfg.credentials_provider = credentials_provider
# Set the region.
cfg.region = args.region
# If an endpoint is provided, update the endpoint in the configuration.
if args.endpoint is not None:
cfg.endpoint = args.endpoint
# Create an OSS client instance.
client = oss.Client(cfg)
# Initiate a metadata query request in vector search mode.
result = client.do_meta_query(oss.DoMetaQueryRequest(
bucket=args.bucket,
mode='semantic',
meta_query=oss.MetaQuery(
max_results=1000,
query='Overlook the snow-covered forest',
order='desc',
media_types=oss.MetaQueryMediaTypes(
media_type=['image']
),
simple_query='{"Operation":"gt", "Field": "Size", "Value": "30"}',
),
))
# Print the search results.
print(vars(result))
if __name__ == "__main__":
main()Go
For more information, see Vector search (Go SDK V2).
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"
)
var (
region string
bucketName string
)
func init() {
// Use a command line parameter to specify the region. By default, the parameter is an empty string.
flag.StringVar(®ion, "region", "", "The region in which the bucket is located.")
// Use a command line parameter to specify the bucket name. By default, the parameter is an empty string.
flag.StringVar(&bucketName, "bucket", "", "The name of the bucket.")
}
func main() {
flag.Parse() // Parse the command line parameters.
// Check whether the bucket name is specified. If the bucket name is not specified, return the default parameters and exit the program.
if len(bucketName) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, bucket name required")
}
// Check whether the region is specified. If the region is not specified, return the default parameters and exit the program.
if len(region) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, region required")
}
// Create and configure a client and use environment variables to pass the credential provider and the region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
client := oss.NewClient(cfg) // Use the client configurations to create a new OSSClient instance.
// Perform AISearch to query the objects that meet specific semantic conditions.
request := &oss.DoMetaQueryRequest{
Bucket: oss.Ptr(bucketName),
Mode: oss.Ptr("semantic"),
MetaQuery: &oss.MetaQuery{
MaxResults: oss.Ptr(int64(99)),
Query: oss.Ptr("Overlook the snow-covered forest"), // Specify sematic content.
MediaType: oss.Ptr("image"), // Specify the type of the media to be queried. In this example, the type of the media is set to image.
SimpleQuery: oss.Ptr(`{"Operation":"gt", "Field": "Size", "Value": "30"}`),
},
}
result, err := client.DoMetaQuery(context.TODO(), request)
if err != nil {
log.Fatalf("failed to do meta query %v", err)
}
log.Printf("do meta query result:%#v\n", result)
}PHP
For more information, see Vector search (PHP SDK V2).
<?php
// Include the autoloader file to ensure that dependency libraries can be loaded correctly.
require_once __DIR__ . '/../vendor/autoload.php';
use AlibabaCloud\Oss\V2 as Oss;
// Define the description for command-line arguments.
$optsdesc = [
"region" => ['help' => 'The region in which the bucket is located.', 'required' => True], // The region where the bucket is located (required).
"endpoint" => ['help' => 'The domain names that other services can use to access OSS.', 'required' => False], // The endpoint (optional).
"bucket" => ['help' => 'The name of the bucket', 'required' => True], // The bucket name (required).
];
// Convert the argument descriptions to the long options format required by getopt.
// A colon ":" after each argument indicates that the argument requires a value.
$longopts = \array_map(function ($key) {
return "$key:";
}, array_keys($optsdesc));
// Parse command-line arguments.
$options = getopt("", $longopts);
// Verify that all required arguments are present.
foreach ($optsdesc as $key => $value) {
if ($value['required'] === True && empty($options[$key])) {
$help = $value['help']; // Get the help information for the argument.
echo "Error: the following arguments are required: --$key, $help" . PHP_EOL;
exit(1); // If a required argument is missing, exit the program.
}
}
// Extract values from the parsed arguments.
$region = $options["region"]; // The region where the bucket is located.
$bucket = $options["bucket"]; // The bucket name.
// Load credentials from environment variables.
// Use EnvironmentVariableCredentialsProvider to read the Access Key ID and Access Key Secret from environment variables.
$credentialsProvider = new Oss\Credentials\EnvironmentVariableCredentialsProvider();
// Use the default configuration of the SDK.
$cfg = Oss\Config::loadDefault();
$cfg->setCredentialsProvider($credentialsProvider); // Set the credentials provider.
$cfg->setRegion($region); // Set the region where the bucket is located.
if (isset($options["endpoint"])) {
$cfg->setEndpoint($options["endpoint"]); // If an endpoint is provided, set the endpoint.
}
// Create an OSS client instance.
$client = new Oss\Client($cfg);
// Perform a vector search to query objects that meet the specified conditions.
$request = new Oss\Models\DoMetaQueryRequest($bucket, new Oss\Models\MetaQuery(
maxResults: 99,
query: "Overlook the snow-covered forest",
mediaTypes: new Oss\Models\MetaQueryMediaTypes('image'),
simpleQuery: '{"Operation":"gt", "Field": "Size", "Value": "30"}',
), 'semantic');
$result = $client->doMetaQuery($request);
printf(
'status code:' . $result->statusCode . PHP_EOL .
'request id:' . $result->requestId . PHP_EOL .
'result:' . var_export($result, true)
);ossutil
Search for objects that meet specified conditions in the bucket named examplebucket:
ossutil api do-meta-query --bucket examplebucket --meta-query "{\"Query\":\"Overlooking the snow covered forest\",\"MediaTypes\":{\"MediaType\":\"image\"},\"SimpleQuery\":\"{\\\"Operation\\\":\\\"gt\\\", \\\"Field\\\": \\\"Size\\\", \\\"Value\\\": \\\"1\\\"}\"}" --meta-query-mode semanticFor more information, see do-meta-query.
Search criteria reference
Set one or more search criteria as needed.
Result output settings
When semantic content search criteria are set, sorting and data aggregation are not available.
Object Sort Order: Sort results by last modified time, object name, or object size in ascending or descending order.
Data Aggregation: Perform calculations on results, including count distinct values, group by, maximum, minimum, average, and sum.
Disable vector search
Disabling vector search does not affect data already stored in OSS. Re-enabling the feature rescans existing files and rebuilds the index. The rebuild time depends on the number of files.
Billing stops in the hour after the feature is disabled. Bill generation may be delayed, so monitor your bill.
OSS console
Log on to the OSS console. On the Data Indexing page, click Disable and confirm the action as prompted.

Alibaba Cloud SDK
Java
Java SDK 3.18.2 or later is required. For more information, see Vector search (Java SDK).
import com.aliyun.oss.*;
import com.aliyun.oss.common.auth.*;
import com.aliyun.oss.common.comm.SignVersion;
public class CloseMetaQuery {
public static void main(String[] args) throws Exception {
// Specify the endpoint of the region. In this example, the endpoint of the China (Hangzhou) region is used. Specify your actual endpoint.
String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Specify the name of the bucket. Example: examplebucket.
String bucketName = "examplebucket";
// Obtain a credential from the environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
// Specify the region of the bucket. In this example, the China (Hangzhou) region is used. Set the region to cn-hangzhou.
String region = "cn-hangzhou";
// Create an OSSClient instance.
// When the OSSClient instance is no longer used, call the shutdown method to release resources.
ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
OSS ossClient = OSSClientBuilder.create()
.endpoint(endpoint)
.credentialsProvider(credentialsProvider)
.clientConfiguration(clientBuilderConfiguration)
.region(region)
.build();
try {
// Disable AISearch for the bucket.
ossClient.closeMetaQuery(bucketName);
} catch (OSSException oe) {
System.out.println("Error Message:" + oe.getErrorMessage());
System.out.println("Error Code:" + oe.getErrorCode());
System.out.println("Request ID:" + oe.getRequestId());
System.out.println("Host ID:" + oe.getHostId());
} catch (ClientException ce) {
System.out.println("Error Message: " + ce.getMessage());
} finally {
// Shut down the OSSClient instance.
if(ossClient != null){
ossClient.shutdown();
}
}
}
}Python
For more information, see Vector search.
import argparse
import alibabacloud_oss_v2 as oss
# Create a command-line argument parser to handle command-line arguments.
parser = argparse.ArgumentParser(description="close meta query 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 names that other services can use to access OSS')
def main():
# Parse command-line arguments.
args = parser.parse_args()
# Load credentials from environment variables.
credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()
# Use the default configuration of the SDK.
cfg = oss.config.load_default()
# Set the credentials provider to the credentials obtained from environment variables.
cfg.credentials_provider = credentials_provider
# Set the region in the configuration.
cfg.region = args.region
# If an endpoint is provided, set the endpoint in the configuration.
if args.endpoint is not None:
cfg.endpoint = args.endpoint
# Create an OSS client.
client = oss.Client(cfg)
# Call the close_meta_query method to disable the search feature for the bucket.
result = client.close_meta_query(oss.CloseMetaQueryRequest(
bucket=args.bucket,
))
# Print the status code and request ID of the response.
print(f'status code: {result.status_code}, request id: {result.request_id}')
# Execute the main function when this script is run directly.
if __name__ == "__main__":
main()Go
For more information, see Vector search (Go SDK V2).
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"
)
var (
region string
bucketName string
)
func init() {
// Use a command line parameter to specify the region.
flag.StringVar(®ion, "region", "", "The region in which the bucket is located.")
// Use a command line parameter to specify the bucket name.
flag.StringVar(&bucketName, "bucket", "", "The name of the bucket.")
}
func main() {
flag.Parse() // Parse the command line parameters.
// Check whether the bucket name is specified. If the bucket name is not specified, return the default parameters and exit the program.
if len(bucketName) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, bucket name required") // Record the error and exit the program.
}
// Check whether the region is specified. If the region is not specified, return the default parameters and exit the program.
if len(region) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, region required")
}
// Create and configure a client and use environment variables to pass the credential provider and the region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
client := oss.NewClient(cfg) // Create a new OSSClient instance.
// Create a CloseMetaQuery request to disable the metadata management feature for a specific bucket.
request := &oss.CloseMetaQueryRequest{
Bucket: oss.Ptr(bucketName), // Specify the name of the bucket.
}
result, err := client.CloseMetaQuery(context.TODO(), request) // Execute the request to disable the metadata management feature for the bucket.
if err != nil {
log.Fatalf("failed to close meta query %v", err)
}
log.Printf("close meta query result:%#v\n", result)
}PHP
For more information, see Vector search (PHP SDK V2).
<?php
// Include the autoloader file to ensure that dependency libraries can be loaded correctly.
require_once __DIR__ . '/../vendor/autoload.php';
use AlibabaCloud\Oss\V2 as Oss;
// Define the description for command-line arguments.
$optsdesc = [
"region" => ['help' => 'The region in which the bucket is located.', 'required' => True], // The region where the bucket is located (required).
"endpoint" => ['help' => 'The domain names that other services can use to access OSS.', 'required' => False], // The endpoint (optional).
"bucket" => ['help' => 'The name of the bucket', 'required' => True], // The bucket name (required).
];
// Convert the argument descriptions to the long options format required by getopt.
// A colon ":" after each argument indicates that the argument requires a value.
$longopts = \array_map(function ($key) {
return "$key:";
}, array_keys($optsdesc));
// Parse command-line arguments.
$options = getopt("", $longopts);
// Verify that all required arguments are present.
foreach ($optsdesc as $key => $value) {
if ($value['required'] === True && empty($options[$key])) {
$help = $value['help']; // Get the help information for the argument.
echo "Error: the following arguments are required: --$key, $help" . PHP_EOL;
exit(1); // If a required argument is missing, exit the program.
}
}
// Extract values from the parsed arguments.
$region = $options["region"]; // The region where the bucket is located.
$bucket = $options["bucket"]; // The bucket name.
// Load credentials from environment variables.
// Use EnvironmentVariableCredentialsProvider to read the Access Key ID and Access Key Secret from environment variables.
$credentialsProvider = new Oss\Credentials\EnvironmentVariableCredentialsProvider();
// Use the default configuration of the SDK.
$cfg = Oss\Config::loadDefault();
$cfg->setCredentialsProvider($credentialsProvider); // Set the credentials provider.
$cfg->setRegion($region); // Set the region where the bucket is located.
if (isset($options["endpoint"])) {
$cfg->setEndpoint($options["endpoint"]); // If an endpoint is provided, set the endpoint.
}
// Create an OSS client instance.
$client = new Oss\Client($cfg);
// Create a CloseMetaQueryRequest object to disable the search feature for the bucket.
$request = new \AlibabaCloud\Oss\V2\Models\CloseMetaQueryRequest(
bucket: $bucket
);
// Execute the operation to disable the search feature.
$result = $client->closeMetaQuery($request);
// Print the result of disabling the search feature.
printf(
'status code:' . $result->statusCode . PHP_EOL . // The HTTP status code. For example, 200 indicates success.
'request id:' . $result->requestId . PHP_EOL // The request ID, used for debugging or tracking requests.
);ossutil
Disable the metadata management feature for the bucket examplebucket:
ossutil api close-meta-query --bucket examplebucketFor more information, see close-meta-query.
Limits and performance
Bucket limits
| Limit | Value |
|---|---|
| Maximum files per bucket | 5 billion. Performance may degrade beyond this limit. To process more data, contact Technical Support for an evaluation. |
| Multipart upload objects | Only complete objects assembled through the CompleteMultipartUpload operation appear in search results. Parts from incomplete or aborted uploads do not. |
Internal bandwidth and QPS
OSS provides internal bandwidth and QPS for vector search at no cost to the bucket's Quality of Service (QoS) quota.
| Region | Internal bandwidth | Default QPS |
|---|---|---|
| China (Beijing), China (Hangzhou), China (Shanghai), China (Shenzhen) | 10 Gbps | 1,250 |
| Other regions | 1 Gbps | 1,250 |
Index generation time
During index building, API request fees are incurred for List, Head, and Get calls. Video, audio, and document files take longer to index than image files. Estimate the number of files before enabling.
Structured data and image files
| Files in bucket | Estimated time |
|---|---|
| 10 million | 2 to 3 hours |
| 100 million | 1 day |
| 1 billion | About 10 days |
Video, document, and audio files
| Files in bucket | Estimated time |
|---|---|
| 10 million | About 2 to 3 days |
| 100 million | About 7 to 9 days |
Incremental index updates
When the QPS for new, modified, or deleted files stays below the default value of 1,250, the latency between a file change and searchability is typically a few minutes to a few hours. If QPS exceeds 1,250, contact Technical Support for assistance.
Search response time
Search results are returned in seconds. The default timeout is 30 seconds.
Billing
Vector search fees consist of two parts:
Vector search feature fees
The vector search feature is currently in public preview and free of charge. This includes object metadata management fees. Billing will start after the public preview ends on August 25, 2025. After public preview, charges are based on OSS data indexing pricing. For more information, see Data indexing fees.
API request fees
API request fees are incurred during index building for existing files and index updates for incremental files. Charges are based on the number of API calls.
| Behavior | API |
|---|---|
| Build indexes for files in the bucket | HeadObject and GetObject |
| The bucket contains files with tags | GetObjectTag |
| The bucket contains files with custom metadata | GetObjectMeta |
| The bucket contains symbolic link files | GetSymlink |
| Scan files in the bucket | ListObjects |
For more information about OSS API request fees, see Request fees.
To stop incurring these charges, disable vector search.
FAQ
Why is a file not found immediately after upload?
After a file is uploaded, index generation takes some time. There is a delay before the file appears in search results. Wait a few moments, then search again.
API reference
| Operation | API |
|---|---|
| Enable data indexing or vector search | OpenMetaQuery |
| Search for objects | DoMetaQuery |
| Disable data indexing | CloseMetaQuery |