OSS Vector Search & AI Content Awareness
Leverage multimodal AI models to extract semantic descriptions and concise summaries from images, videos, audio, and documents stored in OSS Buckets. Build searchable vector indexes to enable advanced retrieval capabilities such as text-to-image and text-to-video search.
Prerequisites
- 1. Aliyun CLI (>= 3.3.1)
Pre-check: Aliyun CLI >= 3.3.1 required
This skill uses Aliyun CLI for all OSS operations except opening MetaQuery.
If Aliyun CLI is already installed, ossutil does not need to be installed separately.
Run the following command to verify the version: aliyun version
If not installed or the version is below 3.3.1, refer to references/cli-installation-guide.md for installation instructions, then run:
aliyun configure set --auto-plugin-install true
This configuration enables automatic plugin installation.
- 2. Update the aliyun ossutil plugin
Troubleshooting: --user-agent unknown flag error
If you encounter Error: unknown flag: --user-agent when running a command, the ossutil plugin version is too old. Run the following command to update to the latest version:
> aliyun ossutil update
>
After the update, re-run the original command.
# Python SDK dependencies
pip install oss2==2.19.1 alibabacloud-credentials==1.0.8
Notes:
- - Required: Aliyun CLI, Python dependencies oss2 and alibabacloud-credentials
- Not required: ossutil
- The only operation that requires Python: opening MetaQuery (AI Content Awareness + semantic search)
Security Rules:
- - NEVER read, echo, or print AK/SK values (e.g.,
echo $ALIBABA_CLOUD_ACCESS_KEY_ID is FORBIDDEN) - NEVER ask the user to input AK/SK directly in the conversation or command line
Architecture
User Request -> OSS Bucket -> AI Content Awareness Engine -> Semantic Feature Extraction -> Vector Index -> Semantic Search
|
Images/Videos/Audio/Docs -> Detailed Description (~100 chars) + Concise Summary (<=20 chars)
Core Components: INLINECODE4
Usage Restrictions
Supported Regions
| Region Category | Region List |
|---|
| East China | cn-hangzhou, cn-shanghai |
| North China |
cn-qingdao, cn-beijing, cn-zhangjiakou |
| South China | cn-shenzhen, cn-guangzhou |
| Southwest China | cn-chengdu |
| Other | cn-hongkong, ap-southeast-1 (Singapore), us-east-1 (Virginia) |
Note: If the user's Bucket is in a region not listed above, vector-mode MetaQuery and content awareness cannot be enabled, and an EC Code 0037-00000001 error will be returned. Guide the user to create a new Bucket in a supported region.
File Types
- - Supported: Images, videos, audio, documents
- Multipart uploads: Only objects that have been assembled via
CompleteMultipartUpload are shown
Performance Reference
OSS Internal Bandwidth and QPS
| Region | Internal Bandwidth | Default QPS |
|---|
| cn-beijing, cn-hangzhou, cn-shanghai, cn-shenzhen | 10Gbps | 1250 |
| Other regions |
1Gbps | 1250 |
This bandwidth and QPS is provided exclusively for vector search and does not consume the Bucket's QoS quota.
Existing File Index Build Time
| File Type | 10 Million Files | 100 Million Files | 1 Billion Files |
|---|
| Structured data & images | 2-3 hours | 1 day | ~10 days |
| Videos, documents, audio |
2-3 days | 7-9 days | - |
Incremental Updates and Search Latency
- - Incremental updates: When QPS < 1250, latency is typically minutes to hours
- Search response: Sub-second, default timeout 30 seconds
Dangerous Operation Confirmation
Before executing any of the following dangerous operations,
you MUST confirm with the user first and obtain explicit consent before proceeding:
- - Delete Bucket:
aliyun ossutil rm oss://<bucket-name> -b --user-agent AlibabaCloud-Agent-Skills -- Deletes the entire Bucket, irreversible - Delete Object:
aliyun ossutil rm oss://<bucket-name>/<object-key> --user-agent AlibabaCloud-Agent-Skills -- Deletes a specific file - Batch Delete Objects:
aliyun ossutil rm oss://<bucket-name>/ --recursive --user-agent AlibabaCloud-Agent-Skills -- Recursively deletes all files in the Bucket - Close MetaQuery:
aliyun ossutil api close-meta-query --bucket <bucket-name> --user-agent AlibabaCloud-Agent-Skills -- Closes the metadata index; all indexed data will be cleared - Open MetaQuery:
python scripts/open_metaquery.py --region <your-region> --bucket <your-bucket-name> --endpoint <your-endpoint> -- Opens the metadata index; existing data will start being indexed. If the bucket has more than 1000 objects, confirm with the user first. - Create Bucket:
aliyun ossutil api put-bucket --bucket <bucket> --region <region-id> --user-agent AlibabaCloud-Agent-Skills -- Creates a Bucket
When confirming, explain the following to the user:
- 1. The specific operation to be performed
- The scope of impact (which files/resources will be deleted or closed)
- Whether the operation is reversible (most delete operations are irreversible)
RAM Permissions
See
references/ram-policies.md
Critical Rules (Must Follow)
Rule 1: Opening MetaQuery MUST use the Python script
PROHIBITED:
aliyun ossutil api open-meta-query oss://my-bucket --mode semantic
REQUIRED:
python scripts/open_metaquery.py --region cn-hangzhou --bucket my-bucket
Reason: Only the Python script or SDK can correctly configure
WorkflowParameters to enable AI Content Awareness (ImageInsightEnable and VideoInsightEnable). Without this, semantic search quality will be severely degraded.
Rule 2: Must ask the user when Bucket name conflicts
When creating a Bucket and encountering a
BucketAlreadyExists error:
- 1. Immediately stop all subsequent operations
- Inform the user: "The Bucket name is already taken"
- Ask the user to choose:
- Option 1: Use the existing bucket (requires explicit user confirmation)
- Option 2: Choose a new bucket name (user provides the new name)
- 4. Wait for the user's response before continuing
PROHIBITED:
- - Automatically modifying the bucket name (e.g., appending
-2, -new, etc.) - Using an existing bucket without asking the user
Rule 3: Use Aliyun CLI by default for all operations except opening MetaQuery
The following operations should use Aliyun CLI by default:
- - Create Bucket
- Query Bucket info
- Query Bucket statistics
- Upload files
- Query MetaQuery status
- Execute semantic search
- Close MetaQuery
- Delete Object / Bucket
Goal: Use the aliyun command uniformly, minimizing dependency on ossutil.
Rule 4: If Aliyun CLI is installed, ossutil is not needed
This skill does not require ossutil to be installed by default.
As long as Aliyun CLI >= 3.3.1 is installed and the following has been executed:
aliyun configure set --auto-plugin-install true
It can be used as the default execution tool.
Core Workflows
Task 1: Create Bucket and Upload Files
Always confirm with the user before creating a bucket. Proceed only after the user agrees.
CODEBLOCK7
Task 2: Enable Vector Search & AI Content Awareness (Python script or SDK only)
WARNING: You MUST use python scripts/open_metaquery.py to open MetaQuery. Using aliyun ossutil api open-meta-query is STRICTLY PROHIBITED (it cannot configure WorkflowParameters, which prevents enabling AI Content Awareness features ImageInsightEnable and VideoInsightEnable, severely degrading semantic search quality).
Using the Python Script (Mandatory)
Before executing the Python script, complete the following environment setup:
1. Install Python dependencies:
CODEBLOCK8
2. Configure credentials:
The Python script uses the alibabacloud-credentials default credential chain to automatically discover credentials (supporting environment variables, ~/.aliyun/config.json, ECS instance roles, etc.). No explicit AK/SK handling is needed in the code. Ensure credentials are configured via the aliyun configure command.
3. Verify RAM permissions:
Users must have the minimum RAM permissions required for MetaQuery. See references/ram-policies.md.
If the user encounters an AccessDenied error, check that RAM permissions are correctly configured.
Enablement Process:
- 1. Prepare the Bucket:
a. If the user requests creating a new Bucket:
- Run
aliyun ossutil api put-bucket --bucket examplebucket --user-agent AlibabaCloud-Agent-Skills with the user-specified bucket name
- If creation fails with a
BucketAlreadyExists error:
-
Immediately stop the operation
- Inform the user: "The Bucket name
<bucket-name> is already taken (it may have been created by you or another user)"
-
You MUST ask the user: "Would you like to: 1) Use this existing bucket? or 2) Choose a new bucket name?"
-
Wait for the user's explicit response before continuing. Do not modify the bucket name or use the existing bucket without permission.
b. If the user provides an existing bucket:
- First verify the bucket exists using
aliyun ossutil api get-bucket-info --bucket <bucket-name> --user-agent AlibabaCloud-Agent-Skills
- If it does not exist, ask the user whether to create it
- 2. Verify Bucket object count: After the user provides a bucket, check the object count. If it exceeds 1000, warn the user that enabling MetaQuery will incur costs.
Use the following command to get the bucket's object count:
aliyun ossutil api get-bucket-stat --bucket <your-bucket-name> --output-format json --user-agent AlibabaCloud-Agent-Skills
The
ObjectCount field in the response indicates the number of objects.
- If the object count exceeds 1000, warn the user that enabling MetaQuery will incur costs and confirm whether to proceed.
- If the object count is 0, ask the user which files to upload. Upload command:
CODEBLOCK10
- 3. Run the Python script: After the above steps are complete, attempt to open MetaQuery using the Python script.
Python script example:
CODEBLOCK11
Troubleshooting MetaQuery Enablement Issues
Use the
get-meta-query-status command to check MetaQuery status:
aliyun ossutil api get-meta-query-status --bucket <your-bucket-name> --output-format json --user-agent AlibabaCloud-Agent-Skills
Based on the returned status:
- - Status is
Deleted: MetaQuery is being closed. The user should retry later. - Status is
Running or Ready: MetaQuery has already been created. Check the following two conditions:
- Whether
MetaQueryMode is
semantic
- Whether
WorkflowParameters contains the following configuration:
<WorkflowParameters>
<WorkflowParameter><Name>ImageInsightEnable</Name><Value>True</Value></WorkflowParameter>
<WorkflowParameter><Name>VideoInsightEnable</Name><Value>True</Value></WorkflowParameter>
</WorkflowParameters>
If
MetaQueryMode=semantic and both
VideoInsightEnable and
ImageInsightEnable are
True, the user has successfully enabled MetaQuery in vector mode with content awareness (which greatly improves semantic search quality). No further action is needed.
If these conditions are not met, recommend the user switch to a different bucket and start over.
Task 3: Execute Semantic Search
Prerequisites for MetaQuery Search
Before using MetaQuery for search, confirm the following:
- 1. Verify MetaQuery is enabled:
aliyun ossutil api get-meta-query-status --bucket <your-bucket-name> --output-format json --user-agent AlibabaCloud-Agent-Skills
2. **If MetaQuery is not enabled**: Complete the enablement process first. Refer to Task 2 to enable it using the Python script.
3. **Check index scan status**: The `Phase` field from `get-meta-query-status` indicates the current scan phase:
- `FullScanning`: Full scan in progress. **Search is not available yet**. Wait for the full scan to complete.
- `IncrementalScanning`: Incremental scan in progress. The index has been largely built and search can be performed normally.
4. **Verify MetaQuery state is `Running`**: MetaQuery is only available when `State` is `Running`. If the state is `Ready` or any non-`Running` state, you may need to wait or re-enable it.
**1. Prepare the meta-query.xml file:**
Create a `meta-query.xml` file to define query conditions. For detailed format, field descriptions, and complete examples, see [references/metaquery.md](references/metaquery.md).
Example of semantic vector search for video files containing "person" (MediaTypes can only be one of: video, image, audio, document):
xml
video
person
Example of scalar search where file size > 30B and file modification time > 2025-06-03T09:20:47.999Z:
xml
{"SubQueries":[{"Field":"Size","Value":"30","Operation":"gt"},{"Field":"FileModifiedTime","Value":"2025-06-03T09:20:47.999Z","Operation":"gt"}],"Operation":"and"}
**2. Execute the search command:**
This example uses semantic vector search. The `meta-query.xml` file defines the query conditions, and search results return the most similar files.
bash
aliyun ossutil api do-meta-query --bucket
--meta-query file://meta-query.xml --meta-query-mode semantic --user-agent AlibabaCloud-Agent-Skills
For scalar search, use `--meta-query-mode basic`
> For detailed command parameters, see the DoMetaQuery section in [references/related-apis.md](references/related-apis.md).
**3. Optimizing search result display:**
After search completes, when displaying results to the user, use the `x-oss-process` parameter to generate preview images or cover frames for image and video files, making it easier for the user to visually review search results. If the user's current channel supports multimedia files, send them directly to the user.
**Video files -- Get video cover snapshot:**
bash
aliyun ossutil presign oss:/// --query-param x-oss-process=video/snapshot,t0,fpng,w0,h0 --user-agent AlibabaCloud-Agent-Skills
Parameters: `t_0`: Capture frame at 0ms as cover; `f_png`: Output format PNG; `w_0,h_0`: Width/height 0 means original resolution.
**Image files -- Get image preview link:**
bash
aliyun ossutil presign oss:/// --user-agent AlibabaCloud-Agent-Skills
> **Note**: The `aliyun ossutil presign` command generates a signed temporary access URL that can be opened directly in a browser for preview during its validity period. For image files, you can also add image processing parameters via `x-oss-process` (e.g., resize, crop):
>
bash
aliyun ossutil presign oss:/// --query-param x-oss-process=image/resize,w_200 --user-agent AlibabaCloud-Agent-Skills
> This generates a thumbnail preview to reduce loading time.
### Troubleshooting MetaQuery Search Issues
#### User asks "Why wasn't a specific file found?"
When a user reports that a specific uploaded file is missing from search results, troubleshoot based on the MetaQuery configuration:
**a. Content awareness is NOT enabled:**
If the user's MetaQuery does not have content awareness enabled (i.e., `VideoInsightEnable` or `ImageInsightEnable` is not `True` in `WorkflowParameters`), possible reasons include:
- The file's metadata index has not been fully built yet. Wait for the index scan to complete (check the `Phase` field via `aliyun ossutil api get-meta-query-status --bucket <bucket-name> --output-format json --user-agent AlibabaCloud-Agent-Skills`).
- Without content awareness, search is based only on basic file metadata (filename, size, type, etc.) and cannot perform semantic understanding of file contents, resulting in limited search effectiveness.
- **Recommendation**: Suggest the user enable content awareness to improve search quality. Since existing MetaQuery configurations cannot be directly modified, recommend the user switch to a new bucket and re-enable MetaQuery with content awareness following the Task 2 process.
**b. Content awareness IS enabled:**
If the user's MetaQuery has content awareness enabled but a specific file still cannot be found, possible reasons include:
- **File is still being processed**: Content awareness requires deep analysis of files (e.g., image recognition, video understanding), which takes longer, especially for video files. Check the `Phase` field via `aliyun ossutil api get-meta-query-status --bucket <bucket-name> --output-format json --user-agent AlibabaCloud-Agent-Skills`:
- `FullScanning`: The overall index is still in full scan mode. Wait patiently.
- `IncrementalScanning`: Newly uploaded files are being processed incrementally. Usually wait a few minutes.
- **Unsupported file format**: Some file formats may not be supported by content awareness. In this case, search can only use basic metadata.
- **Search keywords don't match**: The user's search keywords may not semantically match the file content. Suggest the user try adjusting their search keywords to use descriptions closer to the actual file content.
### Task 4: Query Data Index Status (aliyun ossutil)
bash
aliyun ossutil api get-meta-query-status --bucket --output-format json --user-agent AlibabaCloud-Agent-Skills
> For detailed descriptions of returned fields (State, Phase, MetaQueryMode, etc.), see the GetMetaQueryStatus section in [references/related-apis.md](references/related-apis.md).
## Verification
See [references/verification-method.md](references/verification-method.md)
## Resource Cleanup
bash
Close the data index. (Dangerous operation -- confirm with the user first)
aliyun ossutil api close-meta-query --bucket --user-agent AlibabaCloud-Agent-Skills
```
Warning: After closing the data index, all indexed data will be cleared. (Dangerous operation -- confirm with the user first)
Alternative Python Scripts for OSS Operations
When aliyun ossutil is unavailable, you can use Python scripts as alternatives. See the Python SDK Scripts section in references/related-apis.md.
OSS 向量搜索与AI内容感知
利用多模态AI模型,从存储在OSS Bucket中的图片、视频、音频和文档中提取语义描述和简洁摘要。构建可搜索的向量索引,实现文本搜图、文本搜视频等高级检索能力。
前提条件
- 1. 阿里云CLI(>= 3.3.1)
预检查:需要阿里云CLI >= 3.3.1
除开启MetaQuery外,本技能使用阿里云CLI执行所有OSS操作。
如果已安装阿里云CLI,则无需单独安装ossutil。
运行以下命令验证版本:aliyun version
如果未安装或版本低于3.3.1,请参考references/cli-installation-guide.md的安装说明,然后运行:
aliyun configure set --auto-plugin-install true
此配置将启用自动插件安装。
- 2. 更新阿里云ossutil插件
故障排除:--user-agent未知标志错误
如果在运行命令时遇到Error: unknown flag: --user-agent,说明ossutil插件版本过旧。运行以下命令更新到最新版本:
bash
aliyun ossutil update
更新后,重新运行原始命令。
bash
Python SDK依赖
pip install oss2==2.19.1 alibabacloud-credentials==1.0.8
说明:
- - 必需:阿里云CLI、Python依赖oss2和alibabacloud-credentials
- 非必需:ossutil
- 唯一需要Python的操作:开启MetaQuery(AI内容感知+语义搜索)
安全规则:
- - 严禁读取、回显或打印AK/SK值(例如,echo $ALIBABACLOUDACCESSKEYID是禁止的)
- 严禁要求用户在对话或命令行中直接输入AK/SK
架构
用户请求 -> OSS Bucket -> AI内容感知引擎 -> 语义特征提取 -> 向量索引 -> 语义搜索
|
图片/视频/音频/文档 -> 详细描述(约100字符)+ 简洁摘要(<=20字符)
核心组件:OSS Bucket + 数据索引 + 向量搜索 + AI内容感知
使用限制
支持的地域
| 地域分类 | 地域列表 |
|---|
| 华东 | cn-hangzhou, cn-shanghai |
| 华北 |
cn-qingdao, cn-beijing, cn-zhangjiakou |
| 华南 | cn-shenzhen, cn-guangzhou |
| 西南 | cn-chengdu |
| 其他 | cn-hongkong, ap-southeast-1(新加坡), us-east-1(弗吉尼亚) |
注意:如果用户的Bucket位于上述未列出的地域,则无法启用向量模式的MetaQuery和内容感知,并会返回EC Code 0037-00000001错误。请指导用户在支持的地域创建新的Bucket。
文件类型
- - 支持:图片、视频、音频、文档
- 分片上传:仅显示已通过CompleteMultipartUpload组装完成的对象
性能参考
OSS内网带宽和QPS
| 地域 | 内网带宽 | 默认QPS |
|---|
| cn-beijing, cn-hangzhou, cn-shanghai, cn-shenzhen | 10Gbps | 1250 |
| 其他地域 |
1Gbps | 1250 |
此带宽和QPS专供向量搜索使用,不消耗Bucket的QoS配额。
存量文件索引构建时间
| 文件类型 | 1000万文件 | 1亿文件 | 10亿文件 |
|---|
| 结构化数据与图片 | 2-3小时 | 1天 | 约10天 |
| 视频、文档、音频 |
2-3天 | 7-9天 | - |
增量更新与搜索延迟
- - 增量更新:当QPS < 1250时,延迟通常为分钟到小时级别
- 搜索响应:亚秒级,默认超时30秒
危险操作确认
在执行以下任何危险操作之前,
您必须首先与用户确认并获得明确同意后方可继续:
- - 删除Bucket:aliyun ossutil rm oss:// -b --user-agent AlibabaCloud-Agent-Skills -- 删除整个Bucket,不可逆
- 删除对象:aliyun ossutil rm oss:/// --user-agent AlibabaCloud-Agent-Skills -- 删除特定文件
- 批量删除对象:aliyun ossutil rm oss:/// --recursive --user-agent AlibabaCloud-Agent-Skills -- 递归删除Bucket中的所有文件
- 关闭MetaQuery:aliyun ossutil api close-meta-query --bucket --user-agent AlibabaCloud-Agent-Skills -- 关闭元数据索引;所有已索引的数据将被清除
- 开启MetaQuery:python scripts/open_metaquery.py --region --bucket --endpoint -- 开启元数据索引;现有数据将开始被索引。如果Bucket中的对象超过1000个,请先与用户确认。
- 创建Bucket:aliyun ossutil api put-bucket --bucket --region --user-agent AlibabaCloud-Agent-Skills -- 创建一个Bucket
确认时,请向用户说明以下内容:
- 1. 将要执行的具体操作
- 影响范围(哪些文件/资源将被删除或关闭)
- 操作是否可逆(大多数删除操作不可逆)
RAM权限
请参见
references/ram-policies.md
关键规则(必须遵守)
规则1:开启MetaQuery必须使用Python脚本
禁止:
bash
aliyun ossutil api open-meta-query oss://my-bucket --mode semantic
必须:
bash
python scripts/open_metaquery.py --region cn-hangzhou --bucket my-bucket
原因: 只有Python脚本或SDK才能正确配置WorkflowParameters以启用AI内容感知(ImageInsightEnable和VideoInsightEnable)。否则,语义搜索质量将严重下降。
规则2:Bucket名称冲突时必须询问用户
创建Bucket时遇到BucketAlreadyExists错误:
- 1. 立即停止所有后续操作
- 告知用户:该Bucket名称已被占用
- 请用户选择:
- 选项1:使用现有Bucket(需要用户明确确认)
- 选项2:选择新的Bucket名称(用户提供新名称)
- 4. 等待用户响应后再继续
禁止:
- - 自动修改Bucket名称(例如,添加-2、-new等后缀)
- 未经用户询问直接使用现有Bucket
规则3:除开启MetaQuery外,默认使用阿里云CLI执行所有操作
以下操作应默认使用阿里云CLI:
- - 创建Bucket
- 查询Bucket信息
- 查询Bucket统计信息
- 上传文件
- 查询MetaQuery状态
- 执行语义搜索
- 关闭MetaQuery
- 删除对象/Bucket
目标:统一使用aliyun命令,尽量减少对ossutil的依赖。
规则4:如果已安装阿里云CLI,则不需要ossutil
本技能默认不需要安装ossutil。
只要安装了阿里云CLI >= 3.3.1,并且已执行以下命令:
bash
aliyun configure set --auto-plugin-install true
即可将其作为默认执行工具。
核心工作流
任务1:创建Bucket并上传文件
在创建Bucket之前,务必与用户确认。只有在用户同意后才能继续。
bash
1.1 创建Bucket
aliyun ossutil api put-bucket --bucket examplebucket --region
--user-agent AlibabaCloud-Agent-Skills
1.2 下载文件
aliyun ossutil cp oss://example-bucket/testmedias/ /tmp/testmedias_download/ -r --region cn-hangzhou --user-agent AlibabaCloud-Agent-Skills
1.3 上传文件
aliyun ossutil cp /tmp/testmediasdownload/ oss://example-bucket/test_medias/ -r --region cn-hangzhou --user-agent AlibabaCloud-Agent-Skills
任务2:启用向量搜索与AI内容感知(仅限Python脚本或SDK)
警告:您必须使用python scripts/open_metaquery.py来开启MetaQuery。严禁使用aliyun ossutil api open-meta-query(它无法配置Workflow