New MetaQuery features
When a bucket accumulates files from multiple services, devices, or scenarios, the legacy version of MetaQuery provides only a single, implicit metadata database. All files share the same AI processing configuration, making it difficult to isolate, manage, and retrieve data by service. The new MetaQuery introduces Datasets, which allow you to group files within the same bucket by service, device, or scenario. Each Dataset has its own metadata, an independent AI content awareness configuration (DatasetConfig), and a separate query entry point. This enables fine-grained metadata management and semantic search, achieving a "one bucket, multiple services" model where data is completely isolated.
The features described in this document, including multi-Dataset support and CRUD operations for Datasets and SmartClusters, are currently in an invitation-only preview and are only supported in the China (Hangzhou) and Singapore regions. Before you begin, ensure that your target bucket is in one of these regions, and contact technical support to request access to the new MetaQuery preview.
Use cases
Fine-grained search for mixed multi-device and multi-service data: Store videos from entrance, warehouse, and office cameras, or images from multiple applications, in a single bucket. Create a separate Dataset for each source to restrict queries to the target Dataset, preventing interference between services.
Cross-language content understanding and search: Configure different output languages for Insights, such as Chinese or English, for each Dataset. This ensures that AI-generated descriptions match the service's language, which simplifies cross-language search and display.
Custom event detection: For security or inspection services, configure custom event tags (for example, "person fell down") for a Dataset. When videos are ingested, they are automatically tagged, enabling you to later search directly for files that match these event tags.
Smart grouping (SmartCluster): Automatically cluster and group faces, images, or other objects within a Dataset to support applications such as photo albums and media asset libraries.
How it works
The new MetaQuery uses Datasets as the core unit for organizing metadata and AI processing. The overall workflow is as follows:
Enable and route: Enable MetaQuery for a bucket in
semanticmode. If you need multiple Datasets, configure aRouteRulewhen you enable the feature. This rule specifies which OSS object tag to use for routing files to different Datasets.Process by Dataset: MetaQuery routes files to the corresponding Dataset based on their tag and then processes them for AI content awareness according to that Dataset's
DatasetConfig(for example, image or video content descriptions, Insights language, and custom event tags). The results are written to the Dataset's metadata.Dataset-level query: After indexing is complete, use
SimpleQueryfor structured queries orSemanticQueryfor natural language semantic search within a specific Dataset. The query returns only files from that Dataset.Smart grouping (optional): Use a
SmartClusterto automatically cluster and group files within a Dataset.
File indexing is an asynchronous process. After you enable the feature or upload a file, you must wait for indexing to complete. Files may not be searchable until then. You can configure Message Service (MNS) notifications when you enable MetaQuery to receive a notification when indexing is finished.
New vs. legacy versions
Feature | Legacy version | New version |
Data organization | Each bucket has a single implicit metadata database. | A single bucket can have multiple Datasets. |
File routing | All files are routed to the implicit metadata database. | Routes files to a specific Dataset by using an OSS object tag. |
Processing configuration | A single, bucket-level configuration. | Each Dataset can have an independent |
Query API | Query the default metadata database by using | Query a specific Dataset by using |
Smart grouping | Does not support independent management. | Supports independent creation and management of a |
If you do not configure a RouteRule, all files are routed to the default system Dataset (typically named oss_{uid}_{bucket}). This usage is equivalent to the single-database model of the legacy version.
Limitations
The RouteRule takes effect only when mode=semantic and is set when you enable MetaQuery. To change the rule, you must first call CloseMetaQuery and then call OpenMetaQuery again. This action clears all indexed metadata.
Step 1: Enable MetaQuery
Enable MetaQuery for the target bucket in semantic mode. Before you run the code, configure your access credentials by using the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables. Replace examplebucket with the name of your bucket.
Java SDK
import com.aliyun.sdk.service.oss2.OSSClient;
import com.aliyun.sdk.service.oss2.credentials.EnvironmentVariableCredentialsProvider;
import com.aliyun.sdk.service.oss2.models.OpenMetaQueryRequest;
import com.aliyun.sdk.service.oss2.models.OpenMetaQueryResult;
public class OpenMetaQuerySample {
public static void main(String[] args) throws Exception {
try (OSSClient client = OSSClient.newBuilder()
.region("cn-hangzhou")
.credentialsProvider(new EnvironmentVariableCredentialsProvider())
.build()) {
OpenMetaQueryResult result = client.openMetaQuery(OpenMetaQueryRequest.newBuilder()
.bucket("examplebucket")
.mode("semantic")
.build());
System.out.println("open meta query status: " + result.statusCode());
}
}
}Go SDK
package main
import (
"context"
"log"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func main() {
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion("cn-hangzhou")
client := oss.NewClient(cfg)
_, err := client.OpenMetaQuery(context.TODO(), &oss.OpenMetaQueryRequest{
Bucket: oss.Ptr("examplebucket"),
Mode: oss.Ptr("semantic"),
})
if err != nil {
log.Fatalf("open meta query failed: %v", err)
}
log.Println("open meta query success")
}To route files to different Datasets, configure a RouteRule when you enable the feature. The following RouteRule reads the routing-dataset tag from a file and routes the file to a Dataset with the same name. If the Dataset does not exist, MetaQuery creates it automatically.
<RouteRule>
<Type>OSSTag</Type>
<OSSTagKey>routing-dataset</OSSTagKey>
<AutoCreateDataset>True</AutoCreateDataset>
</RouteRule>Step 2: Create and configure a Dataset
DatasetConfig is the unified configuration entry point for AI content awareness and smart grouping. The following example creates a Dataset named photos-en and configures it to generate image content descriptions (Insights) in English.
Java SDK
import com.aliyun.sdk.service.oss2.credentials.EnvironmentVariableCredentialsProvider;
import com.aliyun.sdk.service.oss2.dataprocess.OSSDataProcessClient;
import com.aliyun.sdk.service.oss2.dataprocess.models.CreateDatasetRequest;
public class CreateDatasetSample {
public static void main(String[] args) throws Exception {
// Use DatasetConfig (in JSON format) to specify the AI content awareness configuration.
// This example sets the output language for image content descriptions (Insights) to English.
String datasetConfig = "{\n" +
" \"Insights\": {\n" +
" \"Language\": \"en\",\n" +
" \"Image\": {\n" +
" \"Caption\": { \"Enable\": \"true\" }\n" +
" }\n" +
" }\n" +
"}";
try (OSSDataProcessClient client = OSSDataProcessClient.newBuilder()
.region("cn-hangzhou")
.credentialsProvider(new EnvironmentVariableCredentialsProvider())
.build()) {
client.createDataset(CreateDatasetRequest.newBuilder()
.bucket("examplebucket")
.datasetName("photos-en")
.datasetConfig(datasetConfig)
.build());
System.out.println("create dataset success");
}
}
}Go SDK
package main
import (
"context"
"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/dataprocess"
)
func main() {
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion("cn-hangzhou")
client := dataprocess.NewClient(cfg)
// Use DatasetConfig (in JSON format) to set the output language for this Dataset's
// image content descriptions (Insights) to English.
datasetConfig := `{
"Insights": {
"Language": "en",
"Image": {
"Caption": { "Enable": "true" }
}
}
}`
_, err := client.CreateDataset(context.TODO(), &dataprocess.CreateDatasetRequest{
Bucket: oss.Ptr("examplebucket"),
DatasetName: oss.Ptr("photos-en"),
DatasetConfig: oss.Ptr(datasetConfig),
})
if err != nil {
log.Fatalf("create dataset failed: %v", err)
}
log.Println("create dataset success")
}A DatasetConfig specified by using OpenMetaQuery can serve as the default processing configuration. Automatically created Datasets might use this default configuration at runtime, but this inherited value is not necessarily persisted in the Dataset record. To ensure that a configuration can be retrieved with GetDataset and maintained, explicitly provide the datasetConfig parameter when you call CreateDataset or UpdateDataset.
Step 3: Upload and route a file
After you configure a RouteRule, set the corresponding OSS object tag when you upload a file to route it to the target Dataset. The following example routes the photos/snow.jpg file to the photos-en Dataset.
Java SDK
import com.aliyun.sdk.service.oss2.OSSClient;
import com.aliyun.sdk.service.oss2.credentials.EnvironmentVariableCredentialsProvider;
import com.aliyun.sdk.service.oss2.models.PutObjectRequest;
import com.aliyun.sdk.service.oss2.transport.BinaryData;
import java.nio.file.Files;
import java.nio.file.Paths;
public class PutObjectSample {
public static void main(String[] args) throws Exception {
try (OSSClient client = OSSClient.newBuilder()
.region("cn-hangzhou")
.credentialsProvider(new EnvironmentVariableCredentialsProvider())
.build()) {
// Route the file to the photos-en Dataset by using an object tag.
client.putObject(PutObjectRequest.newBuilder()
.bucket("examplebucket")
.key("photos/snow.jpg")
.tagging("routing-dataset=photos-en")
.body(BinaryData.fromStream(Files.newInputStream(Paths.get("/local/path/snow.jpg"))))
.build());
System.out.println("put object success");
}
}
}Go SDK
package main
import (
"context"
"log"
"os"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
func main() {
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion("cn-hangzhou")
client := oss.NewClient(cfg)
file, err := os.Open("/local/path/snow.jpg")
if err != nil {
log.Fatalf("open file failed: %v", err)
}
defer file.Close()
// Route the file to the photos-en Dataset by using an object tag.
_, err = client.PutObject(context.TODO(), &oss.PutObjectRequest{
Bucket: oss.Ptr("examplebucket"),
Key: oss.Ptr("photos/snow.jpg"),
Tagging: oss.Ptr("routing-dataset=photos-en"),
Body: file,
})
if err != nil {
log.Fatalf("put object failed: %v", err)
}
log.Println("put object success")
}If you configured a RouteRule when enabling MetaQuery, an uploaded file that lacks the specified routing tag will not be assigned to any Dataset.
Step 4: Query within a Dataset
After indexing is complete, you can use Dataset-level query APIs to search within a specific Dataset. The following example uses SimpleQuery to perform a structured query. For natural language semantic search, you can use SemanticQuery instead.
Java SDK
import com.aliyun.sdk.service.oss2.credentials.EnvironmentVariableCredentialsProvider;
import com.aliyun.sdk.service.oss2.dataprocess.OSSDataProcessClient;
import com.aliyun.sdk.service.oss2.dataprocess.models.File;
import com.aliyun.sdk.service.oss2.dataprocess.models.Label;
import com.aliyun.sdk.service.oss2.dataprocess.models.SimpleQuery;
import com.aliyun.sdk.service.oss2.dataprocess.models.SimpleQueryRequest;
import com.aliyun.sdk.service.oss2.dataprocess.models.SimpleQueryResult;
import java.util.Arrays;
public class SimpleQueryLabelSample {
public static void main(String[] args) throws Exception {
try (OSSDataProcessClient client = OSSDataProcessClient.newBuilder()
.region("cn-hangzhou")
.credentialsProvider(new EnvironmentVariableCredentialsProvider())
.build()) {
SimpleQueryResult result = client.simpleQuery(SimpleQueryRequest.newBuilder()
.bucket("examplebucket")
.datasetName("security-events")
.query(SimpleQuery.newBuilder()
.field("Labels.LabelName")
.value("person fell down")
.operation("eq")
.build())
.withFields(Arrays.asList("Filename", "URI", "Labels"))
.maxResults(20)
.build());
for (File file : result.files()) {
StringBuilder names = new StringBuilder();
if (file.labels() != null) {
for (Label label : file.labels()) {
names.append(label.labelName()).append(" ");
}
}
System.out.println(file.filename() + " -> " + names);
}
}
}
}Go SDK
package main
import (
"context"
"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/dataprocess"
)
func main() {
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion("cn-hangzhou")
client := dataprocess.NewClient(cfg)
result, err := client.SimpleQuery(context.TODO(), &dataprocess.SimpleQueryRequest{
Bucket: oss.Ptr("examplebucket"),
DatasetName: oss.Ptr("security-events"),
Query: oss.Ptr(`{"Field":"Labels.LabelName","Value":"person fell down","Operation":"eq"}`),
WithFields: oss.Ptr(`["Filename","URI","Labels"]`),
MaxResults: oss.Ptr(int32(20)),
})
if err != nil {
log.Fatalf("simple query failed: %v", err)
}
for _, file := range result.Files {
log.Printf("%s %v", oss.ToString(file.Filename), file.Labels)
}
}API reference
The new version of MetaQuery retains the OpenMetaQuery, GetMetaQueryStatus, CloseMetaQuery, and DoMetaQuery APIs, and adds the following APIs.
Category | API | Description |
Dataset management | Creates a Dataset. | |
Dataset management | Queries the information and configuration of a Dataset. | |
Dataset management | Updates the configuration of a Dataset. | |
Dataset management | Deletes a Dataset. | |
Dataset management | Lists the Datasets in a bucket. | |
Dataset-level query | Performs a structured query within a specified Dataset. | |
Dataset-level query | Performs a semantic search within a specified Dataset. | |
SmartCluster management | Creates a SmartCluster. | |
SmartCluster management | Queries the details of a SmartCluster. | |
SmartCluster management | Updates the configuration of a SmartCluster. | |
SmartCluster management | Deletes a SmartCluster. | |
SmartCluster management | Lists the SmartClusters in a Dataset. | |
Metadata management | Deletes the metadata of a specified file from a Dataset. |