Asynchronous vectorization
Use a Lindorm stream engine extract, transform, and load (ETL) task to call the AI engine automatically when you insert or update text in a wide table. The task generates embedding vectors and writes them back to the table, so your application does not need to call the model API directly.
Prerequisites
LindormTable is activated and runs version
2.9.2.1or later. For more information about theVECTORdata type, see Vector type.The stream engine is activated and runs version
3.4.2or later. The instance must supportbailian_embeddingand writing results back to aVECTORcolumn.You have the AI engine endpoint and API key that the stream engine can use to call
text-embedding-v4.Contact Lindorm technical support to confirm the required AI embedding model and quota. For the contact details, see Limits.
Limits
Supported input — Only text embeddings are supported. Image embeddings are not supported.
Model and quota — Before you use the automatic embedding feature, contact Lindorm technical support on DingTalk (ID: s0s3eg3) to confirm the required AI embedding model and quota. Otherwise, the task may fail or fall behind because of throttling.
Throughput — Vectorization is asynchronous relative to writes in the wide table. Within the stream engine operator,
bailian_embeddingcalls the model synchronously, one record at a time. Throughput depends on the model response time, the quota, and the operator parallelism that theparallelismparameter sets.
Example
This example shows the complete process: create a wide table with a vector column, and then use a stream engine ETL task to detect text changes, generate vectors, and write them back to the table.
Step 1: Create a wide table
Connect to LindormTable SQL and run the following statements to create the table in the default database. For the syntax, see Use a MySQL client to connect to and use LindormTable.
USE `default`;
CREATE TABLE product_embedding_demo (
id VARCHAR,
title VARCHAR,
embedding VECTOR(768),
PRIMARY KEY (id)
);Step 2: Create an ETL task
Connect to stream engine SQL. To obtain the connection endpoint, see Connect to the streaming engine using the MySQL command line.
Replace <AI_ENGINE_HOST>:<PORT> and <AI_API_KEY> with the AI engine endpoint and API key, and then run the following statement:
CREATE ETL product_title_embedding
WITH (
`source.parallelism` = '4',
`parallelism` = '8',
`ai.engine.endpoint` = 'https://<AI_ENGINE_HOST>:<PORT>',
`ai.engine.apikey` = '<AI_API_KEY>',
`ai.bailian.embedding` = 'text-embedding-v4',
`incremental.startup.mode` = 'latest-offset',
`changelogMode` = 'true',
`changelog.watch-columns` = 'title',
`source.ignore-delete` = 'true',
`source.ignore-update-before` = 'true'
)
AS
INSERT INTO `lindorm_table`.`default`.product_embedding_demo (id, embedding)
SELECT id, bailian_embedding(title, 768)
FROM `lindorm_table`.`default`.product_embedding_demo
WHERE title IS NOT NULL AND CHAR_LENGTH(TRIM(title)) > 0;The WHERE clause skips empty or whitespace-only text, so no vector is generated for those rows. The following table describes the parameters in the WITH clause and the function in the SELECT clause:
Parameter | Description |
| The read parallelism of the source wide table. As a general guideline, set it higher than the number of nodes in the source LindormTable cluster. |
| The compute parallelism of the task. |
| The base URL of the AI engine, including the scheme, host, and port. |
| The API key of the AI engine. |
| The embedding model name. This example uses |
| Valid values: |
| Required for this example. The default value is |
| Required for this example. The default value is |
| Required for this example. The default value is |
| Required for this example. The default value is |
| The function called in the |
Step 3: Write text and query the result
In stream engine SQL, run SHOW ETLS; and verify that the task is RUNNING.
Return to LindormTable SQL to write text to the wide table and query the result:
UPSERT INTO product_embedding_demo (id, title)
VALUES ('p001', 'Lightweight waterproof outdoor backpack');
SELECT id, title, embedding
FROM product_embedding_demo
WHERE id = 'p001';Vectorization is asynchronous, so there is a delay before the vector column is written back. After the writeback completes, the embedding column in the query result contains the generated vector. When you upsert a new title value for an existing primary key, the task generates a new vector. To monitor the task latency, see Stream Engine Monitoring and Alerting.
Step 4: Delete the ETL task
(Optional) To stop vectorization, delete the ETL task in stream engine SQL. Vectors that have already been written remain in the table and are not cleared. For the detailed syntax, see ETL management.
DROP ETL IF EXISTS product_title_embedding;