Use AI Functions and Lance External Tables to Process Unstructured Data

Updated at:
Copy as MD

Lance external tables let MaxCompute access unstructured data on OSS without migration. Combined with AI Functions that call multimodal models, you can process and analyze this data through SQL. This topic uses e-commerce image tagging and summary generation as examples.

Prerequisites

  1. Activate MaxCompute and Create a MaxCompute project. Skip if already done.

  2. PAI-EAS (Elastic Algorithm Service) is activated. Skip if already done.

  3. OSS is activated. Skip if already done.

Step 1: Create an OSS bucket

  1. Log in to the OSS console.

    Create a bucket named lancetable-demo in OSS by following the OSS console quick start guide.

  2. Create a /lance_table/image/ directory in the bucket.

Step 2: Prepare Lance data

  1. Download image_demo.zip and extract it to a local path, such as D:\Downloads\image_demo.

  2. Update the configuration in upload_images_to_oss_lance_demo.py to match your local file paths, then run the script to create a Lance table in the OSS directory and upload the images to a Binary field named image.

  3. Verify that the image.lance directory was created in the OSS directory.

Step 3: Create and deploy a PAI-EAS model service

  1. Log on to the PAI console, select a region in the upper-left corner, and create a workspace.

  2. Go to the workspace details page, click Model Gallery on the left, select Qwen2.5-Omni-3B, and click Deploy.

  3. Select an instance type with an L20 GPU (48 GB VRAM) and click Deploy. Check the deployment status in Task Management. The status shows Running when deployment completes.

  4. In the left-side navigation pane, click Model Deployment to open EAS. Locate the deployed service, click View Call Information, and note the endpoint and token.

    -- The following information is required for creating the remote model in Step 3.
    Model name (subject to the actual EAS service name):quickstart_deploy_*****_apdf
    Endpoint (VPC address):http://*****.cn-beijing.pai-eas.aliyuncs.com (use only the part before
      aliyuncs.com)
    apikey(Token):****************************************==

Step 4: Create a Lance external table and query metadata

For the Lance external table creation syntax, see Lance external tables (beta).

CREATE EXTERNAL TABLE oss_lance_table (
    image_id BIGINT ,
    image_name STRING,
    image BINARY
)
STORED BY 'com.aliyun.odps.common.table.lance.LanceStorageHandler'
WITH serdeproperties (
    'odps.properties.rolearn'='acs:ram::<uid>:role/aliyunodpsdefaultrole'
)
LOCATION 'oss://oss-cn-<region>-internal.aliyuncs.com/lancetable-demo/lance_table/image/image.lance/'
;

SELECT * FROM oss_lance_table limit 1;
-- Sample output:
+------------+------------+-------+
| image_id   | image_name | image |
+------------+------------+-------+
| 1          | test-1.jpg | =FF=D******

Step 5: Create a VPC network connection

  1. Log in to the MaxCompute console and select a region in the upper-left corner.

  2. In the left-side navigation pane, choose Manage Configurations > Network Connection .

  3. Create a network connection between MaxCompute and the target VPC. The VPC ID can be any VPC, and the vSwitch can be in any zone.

Step 6: Register an Omni multimodal remote model

  • When defining a model with Binary input, declare input parameters as INPUT(data BINARY, promt STRING).

  • When using a String URL as input, use the default values without declaring input parameters.

For syntax parameter details, see Create a model.

SET odps.namespace.schema=true;
SET odps.session.networklink=<your vpc name>;

CREATE MODEL PAI_EAS_Qwen25_Omni_3B_binary WITH VERSION v1 
INPUT(data BINARY, promt STRING) 
OPTIONS(
    MODEL_SOURCE_TYPE = 'REMOTE',
    MODEL_TYPE = 'MLLM',
    TASKS = 'text-generation',
    PAI_EAS_MODEL_NAME = 'Qwen2.5-Omni-3B',
    PAI_EAS_SERVICE_NAME = 'quickstart_deploy_*****_apdf', -- Replace with the EAS service name
    ENDPOINT = 'http://*****.vpc.cn-beijing.pai-eas.aliyuncs.com', -- Replace with the PAI-EAS service endpoint
    APIKEY = '****************************************==', -- Replace with the PAI-EAS service token
    PAI_EAS_SYNC_MODE = 'true'
)
COMMENT "PAI EAS remote model";

Click to view remote model details

-- View the remote model.
SET odps.namespace.schema=true;
SET odps.session.networklink=<your vpc name>;
DESC model PAI_EAS_Qwen25_Omni_3B_binary;

-- Sample output:
+------------------------------------------------------------------------------------+
|                  Model Information                                                 |
+------------------------------------------------------------------------------------+
| Owner:                    ALIYUN$****_com                                          |
| Project:                  ****                                                     |
| Schema:                   default                                                  |
| Model Name:               pai_eas_qwen25_omni_3b_binary                            |
| Model Type:               MLLM                                                     |
| Source Type:              REMOTE                                                   |
| Default Version:          v1                                                       |
| CreateTime:               2026-04-30 14:50:39                                      |
| LastModifiedTime:         2026-04-30 14:50:39                                      |
| Model ID:                 ***                                                      |
| Comment:                  PAI EAS remote model                                     |
+------------------------------------------------------------------------------------+
|                Version Information                                                 |
+------------------------------------------------------------------------------------+
| Owner:                    ALIYUN$****_com                                          |
| Project:                  ****                                                     |
| Schema:                   default                                                  |
| Model Name:               pai_eas_qwen25_omni_3b_binary                            |
| Model Type:               MLLM                                                     |
| Source Type:              REMOTE                                                   |
| Version Name:             v1                                                       |
| Version ID:               ***                                                      |
| Path:                                                                              |
| CreateTime:               2026-04-30 14:50:39                                      |
| LastModifiedTime:         2026-04-30 14:50:39                                      |
| apikey:                   *****                                                    |
| endpoint:                 http://*******.vpc.cn-hangzhou.pai-eas.aliyuncs.com      |
| pai_eas_model_name:       Qwen2.5-Omni-3B                                          |
| pai_eas_service_name:     *******                                                  |
| pai_eas_sync_mode:        true                                                     |
| remote_service_type:      PAI-EAS                                                  |
+------------------------------------------------------------------------------------+
| Input           | Type       | Comment                                             |
+------------------------------------------------------------------------------------+
| data            | binary     |                                                     |
| promt           | string     |                                                     |
+------------------------------------------------------------------------------------+

Step 7: Process image data with AI_GENERATE

Use the MaxCompute AI_GENERATE function to classify image data and generate descriptive summaries.

SET odps.namespace.schema=true; 
SET odps.mcqa.disable=true; -- Disable Query Acceleration mode. AI Functions do not support Query Acceleration mode.
SET odps.session.networklink=<your vpc name>;

SELECT
  key,
  image_name,
  AI_GENERATE(
    PAI_EAS_Qwen25_Omni_3B_binary, v1, `image`,
    "从电商商品销售海报中识别并提取商品所属的类目。返回结果仅限于如下六个选项之一:美妆、服装、日用、食品、其他、电子产品,不包含其他文字或信息"
  ) AS item_catagory,
    AI_GENERATE(
    PAI_EAS_Qwen25_Omni_3B_binary, v1,`image`,
    "用20字描述图片内容,包括颜色、名称!"
  ) AS item_description
  FROM (
    SELECT image, image_name, image_id AS key
    FROM <project name>.<schema>.oss_lance_table
) Limit 10;

-- Sample output:
+------------+------------+---------------+------------------+
| key        | image_name | item_catagory | item_description |
+------------+------------+---------------+------------------+
| 1          | test-1.jpg | 服装        | 图片展示黑色高跟鞋,鞋面上有银色装饰,鞋跟细高,整体设计简约时尚。 |
| 2          | test-10.jpg | 服装        | 黑色丝绒裙襟,红色V领开扣上衣, amidst einen stilvollen Hintergrund with Nebel und kronleuchtern. |
| 3          | test-11.jpg | 美妆        | 图片展示了一排不同色号的Dior口红,背景为柔和粉红色,品牌标志明显。 |
| 4          | test-12.jpg | 美妆        | 透明圆形瓶装的白色乳霜,黑色盖子,红色几何图形装饰,底部有字幕。 |
| 5          | test-13.jpg | 其他        | 粉色和紫色的花朵精心编成的花束,搭配粉色背景和心形装饰,浪漫而不失优雅。 |
| 6          | test-14.jpg | 美妆        | La Mer海蓝之谜护肤品,绿色和淡紫色调,品牌标志。 |
| 7          | test-15.jpg | 美妆        | 图中黄色背景下的护肤套装,包含碧丽肤生物复合精华和纯净清洁产品。 |
| 8          | test-16.jpg | 日用        | 棕色圆形浴缸、黑色台面、窗户、 plants、红色红色,黄色按钮。 |
| 9          | test-17.jpg | 其他        | 图中金色的观音菩萨像,金色头冠,莲花台底座,身上有紫色、黄色、金色花纹。 |
| 10         | test-18.jpg | 照片显示的是化妆品。 | 洁白的透明纸包装,印有蓝色图案和文字,背景为蓝色渐变。 |
+------------+------------+---------------+------------------+