Embedding models convert data, such as text, images, and videos, into vectors within a mathematical space. By calculating the distance or angle between these vectors, you can quantify data similarity. This capability is applicable to tasks such as exact search, recommendation systems, automatic classification, and anomaly detection.
Scenarios
Recommendation: Recommend relevant items based on input data. For example, you can recommend related products based on a user's purchase history and browsing records.
Clustering: Classify input data based on relevance. For example, you can categorize large volumes of news articles into topics such as technology, sports, and entertainment.
Search: Rank search results based on their relevance to the input data. For example, a text embedding model can return relevant web pages based on user search queries, and a multimodal embedding model can enable image search using text.
Anomaly detection: For example, in the finance domain, you can extract feature vectors from transaction records and mark transactions that significantly deviate from normal patterns as potential fraudulent activities.
Supported models
General text embedding
Vector dimension is the number of elements in a vector. For example, a 1,024-dimensional vector contains 1,024 numerical values. A higher dimension allows the vector to represent richer information, capturing the characteristics of the text in greater detail.
Model | Vector dimensions | Maximum rows | Maximum tokens per row | Supported languages | Unit price (Million input tokens) | Free quota (Note) |
text-embedding-v4 Qwen3-Embedding series Only available in the China (Beijing) region | 2,048, 1,536, 1,024 (default), 768, 512, 256, 128, 64 | 10 | 8,192 | Over 100 major languages, including Chinese, English, Spanish, French, Portuguese, Indonesian, Japanese, Korean, German, and Russian | $0.072 | 1 million tokens Validity: 180 days after Model Studio is activated |
text-embedding-v3 Only available in the Singapore region | 1,024 (default), 768, 512, 256, 128, or 64 | Over 50 major languages, including Chinese, English, Spanish, French, Portuguese, Indonesian, Japanese, Korean, German, and Russian | $0.07 | 500,000 tokens Validity: 180 days after Model Studio is activated |
Multimodal embedding
The model generates vectors based on user input, which can be text, images, or videos. This model is suitable for tasks such as video classification, image classification, and image-text retrieval. Only available in the China (Beijing) region
Model | Data type | Vector dimension | Unit price | Free quota (Note) | Rate limit |
multimodal-embedding-v1 Only available in the China (Beijing) region | float(32) | 1,024 | Free trial | No limit on weighted entries | RPM: 120 |
Model selection suggestions
Preferred models
For multimodal vector analysis involving images and videos, use multimodal-embedding-v1.
For vector analysis of plain text or code snippets, we recommend text-embedding-v4. Its performance is aligned with the open-source Qwen3-Embedding model, and its inference performance has been optimized. This model is suitable for most scenarios:
More language support: Covers over 100 major languages.
Code embedding: Adds the capability to vectorize code snippets as input. This lets you build vector index services for code snippets in frameworks such as LlamaIndex.
Flexible vector dimension selection: Provides eight dimension options: 2048, 1536, 1024, 768, 512, 256, 128, and 64. A higher dimension provides greater semantic expression accuracy, but also increases the computational and storage costs for downstream tasks.
Custom instruction: You can add task descriptions to the input content. For example, in a text retrieval scenario, you can add the `instruct` parameter to the request: "Given a web search query, retrieve relevant passages that answer the query". We recommend that you customize prompts for specific tasks and write them in English if possible. In practical applications, this method can improve performance by 1% to 5%.
Diverse output options: Supports dense and sparse vectors. Compared to the open-source Qwen3-Embedding version, this model also supports sparse vectors for different application scenarios:
Dense vectors: More effectively captures the semantic features of text. Suitable for conventional retrieval and semantic matching scenarios.
Sparse vectors: Reduces computational complexity and storage costs. Suitable for scenarios with limited storage resources or those that require efficient semantic matching.
For string input, the model treats the entire string as a single line and has an input length limit of 8,192 tokens. If your string content exceeds this limit, you can use the following methods to adjust the input format:
String list input: Split the input content into multiple parts to generate a string list. The following conditions must be met:
The number of elements in the list does not exceed 10.
The length of each element must be within 8,192 tokens.
Plain text file upload: Consolidate the input string content into a plain text file and upload it. The following conditions must be met:
The total number of lines in the file does not exceed 10.
The length of each line is within 8,192 tokens.
Get started
You must have obtained an API key and set the API key as an environment variable. If you use the OpenAI SDK or DashScope SDK to make calls, you must also install the SDK.
Get started with general text embedding
String input
OpenAI compatible
import os
from openai import OpenAI
client = OpenAI(
api_key=os.getenv("DASHSCOPE_API_KEY"), # If you have not configured environment variables, replace this with your API key
# If you use a model in the China (Beijing) region, you need to replace the base_url with: https://dashscope.aliyuncs.com/compatible-mode/v1
base_url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1" # base_url for Model Studio service
)
completion = client.embeddings.create(
# If you use a model in the China (Beijing) region, you need to replace the model with: text-embedding-v4
model="text-embedding-v3",
input='The quality of the clothes is excellent, very beautiful. It was worth the long wait. I like it and will come back to buy here again.',
dimensions=1024,# Specify the vector dimension
encoding_format="float"
)
print(completion.model_dump_json())
import OpenAI from "openai";
import process from 'process';
// Initialize the OpenAI client
const openai = new OpenAI({
apiKey: process.env.DASHSCOPE_API_KEY, // Read from environment variable
// If you use a model in the China (Beijing) region, you need to replace the baseURL with: https://dashscope.aliyuncs.com/compatible-mode/v1
baseURL: 'https://dashscope-intl.aliyuncs.com/compatible-mode/v1'
});
async function getEmbedding() {
try {
const completion = await openai.embeddings.create({
// If you use a model in the China (Beijing) region, you need to replace the model with: text-embedding-v4
model: "text-embedding-v3",
input: 'The quality of the clothes is excellent, very beautiful. It was worth the long wait. I like it and will come back to buy here again.',
dimensions: 1024, // Specify the vector dimension
encoding_format: "float"
});
console.log(JSON.stringify(completion, null, 2));
} catch (error) {
console.error('Error:', error);
}
}
getEmbedding();
# ======= Important Note =======
# If you use a model in the China (Beijing) region, you need to replace the base_url with: https://dashscope.aliyuncs.com/compatible-mode/v1/embeddings
# If you use a model in the China (Beijing) region, you need to replace the model with: text_embedding_v4
# === Please delete this comment when executing ====
curl --location 'https://dashscope-intl.aliyuncs.com/compatible-mode/v1/embeddings' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "text-embedding-v3",
"input": "The quality of the clothes is excellent, very beautiful. It was worth the long wait. I like it and will come back to buy here again.",
"dimension": "1024",
"encoding_format": "float"
}'
DashScope
import dashscope
from http import HTTPStatus
# If you use a model in the China (Beijing) region, you need to replace the base_url with: https://dashscope.aliyuncs.com/api/v1
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
resp = dashscope.TextEmbedding.call(
# If you use a model in the China (Beijing) region, you need to replace the model with: text_embedding_v4
model=dashscope.TextEmbedding.Models.text_embedding_v3,
input='The quality of the clothes is excellent, very beautiful. It was worth the long wait. I like it and will come back to buy here again.',
dimension=1024,# Specify the vector dimension
output_type="dense&sparse"
)
print(resp) if resp.status_code == HTTPStatus.OK else print(resp)
import java.util.Arrays;
import java.util.concurrent.Semaphore;
import com.alibaba.dashscope.common.ResultCallback;
import com.alibaba.dashscope.embeddings.TextEmbedding;
import com.alibaba.dashscope.embeddings.TextEmbeddingParam;
import com.alibaba.dashscope.embeddings.TextEmbeddingResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.Constants;
public final class Main {
static {
Constants.baseHttpApiUrl="https://dashscope-intl.aliyuncs.com/api/v1";
// The China (Beijing) region needs to be replaced with: https://dashscope.aliyuncs.com/api/v1
}
public static void basicCall() throws ApiException, NoApiKeyException{
TextEmbeddingParam param = TextEmbeddingParam
.builder()
// The China (Beijing) region needs to be replaced with: TEXT_EMBEDDING_V4
.model(TextEmbedding.Models.TEXT_EMBEDDING_V3)
.texts(Arrays.asList("The wind is swift, the sky is high, the apes shriek mournfully", "The islet is clear, the sand is white, the birds fly back", "The boundless forest sheds its leaves shower by shower", "The endless river rolls its waves hour after hour")).build();
TextEmbedding textEmbedding = new TextEmbedding();
TextEmbeddingResult result = textEmbedding.call(param);
System.out.println(result);
}
public static void callWithCallback() throws ApiException, NoApiKeyException, InterruptedException{
TextEmbeddingParam param = TextEmbeddingParam
.builder()
.model(TextEmbedding.Models.TEXT_EMBEDDING_V3)
.texts(Arrays.asList("The wind is swift, the sky is high, the apes shriek mournfully", "The islet is clear, the sand is white, the birds fly back", "The boundless forest sheds its leaves shower by shower", "The endless river rolls its waves hour after hour")).build();
TextEmbedding textEmbedding = new TextEmbedding();
Semaphore sem = new Semaphore(0);
textEmbedding.call(param, new ResultCallback<TextEmbeddingResult>() {
@Override
public void onEvent(TextEmbeddingResult message) {
System.out.println(message);
}
@Override
public void onComplete(){
sem.release();
}
@Override
public void onError(Exception err){
System.out.println(err.getMessage());
err.printStackTrace();
sem.release();
}
});
sem.acquire();
}
public static void main(String[] args){
try{
callWithCallback();
}catch(ApiException|NoApiKeyException|InterruptedException e){
e.printStackTrace();
System.out.println(e);
}
try {
basicCall();
} catch (ApiException | NoApiKeyException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}
# ======= Important Note =======
# If you use a model in the China (Beijing) region, you need to replace the base_url with: https://dashscope.aliyuncs.com/api/v1/services/embeddings/text-embedding/text-embedding
# If you use a model in the China (Beijing) region, you need to replace the model with: text_embedding_v4
# === Please delete this comment when executing ====
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/services/embeddings/text-embedding/text-embedding' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "text-embedding-v3",
"input": {
"texts": [
"The quality of the clothes is excellent, very beautiful. It was worth the long wait. I like it and will come back to buy here again."
]
},
"parameters": {
"dimension": 1024
}
}'
String list input
OpenAI compatible
import os
from openai import OpenAI
client = OpenAI(
api_key=os.getenv("DASHSCOPE_API_KEY"), # If you have not configured environment variables, replace this with your API key
# If you use a model in the China (Beijing) region, you need to replace the base_url with: https://dashscope.aliyuncs.com/compatible-mode/v1
base_url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1" # base_url for Model Studio service
)
completion = client.embeddings.create(
# If you use a model in the China (Beijing) region, you need to replace the model with: text-embedding-v4
model="text-embedding-v3",
input=['The wind is swift, the sky is high, the apes shriek mournfully', 'The islet is clear, the sand is white, the birds fly back', 'The boundless forest sheds its leaves shower by shower', 'The endless river rolls its waves hour after hour'],
encoding_format="float"
)
print(completion.model_dump_json())
import OpenAI from "openai";
import process from 'process';
// Initialize the OpenAI client
const openai = new OpenAI({
apiKey: process.env.DASHSCOPE_API_KEY, // Read from environment variable
// If you use a model in the China (Beijing) region, you need to replace the baseURL with: https://dashscope.aliyuncs.com/compatible-mode/v1
baseURL: 'https://dashscope-intl.aliyuncs.com/compatible-mode/v1'
});
async function getMultipleEmbeddings() {
try {
const completion = await openai.embeddings.create({
// If you use a model in the China (Beijing) region, you need to replace the model with: text-embedding-v4
model: "text-embedding-v3",
input: [
'The wind is swift, the sky is high, the apes shriek mournfully',
'The islet is clear, the sand is white, the birds fly back',
'The boundless forest sheds its leaves shower by shower',
'The endless river rolls its waves hour after hour'
],
encoding_format: "float"
});
console.log(JSON.stringify(completion, null, 2));
} catch (error) {
console.error('Error:', error);
}
}
getMultipleEmbeddings();
# ======= Important Note =======
# If you use a model in the China (Beijing) region, you need to replace the base_url with: https://dashscope.aliyuncs.com/compatible-mode/v1/embeddings
# If you use a model in the China (Beijing) region, you need to replace the model with: text_embedding_v4
# === Please delete this comment when executing ====
curl --location 'https://dashscope-intl.aliyuncs.com/compatible-mode/v1/embeddings' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "text-embedding-v3",
"input": [
"The wind is swift, the sky is high, the apes shriek mournfully",
"The islet is clear, the sand is white, the birds fly back",
"The boundless forest sheds its leaves shower by shower",
"The endless river rolls its waves hour after hour"
],
"encoding_format": "float"
}'
DashScope
import dashscope
from http import HTTPStatus
# If you use a model in the China (Beijing) region, you need to replace the base_url with: https://dashscope.aliyuncs.com/api/v1
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
DASHSCOPE_MAX_BATCH_SIZE = 25
inputs = ['The wind is swift, the sky is high, the apes shriek mournfully', 'The islet is clear, the sand is white, the birds fly back', 'The boundless forest sheds its leaves shower by shower', 'The endless river rolls its waves hour after hour']
result = None
batch_counter = 0
for i in range(0, len(inputs), DASHSCOPE_MAX_BATCH_SIZE):
batch = inputs[i:i + DASHSCOPE_MAX_BATCH_SIZE]
resp = dashscope.TextEmbedding.call(
# If you use a model in the China (Beijing) region, you need to replace the model with: text_embedding_v4
model=dashscope.TextEmbedding.Models.text_embedding_v3,
input=batch,
dimension=1024 # Specify the vector dimension
)
if resp.status_code == HTTPStatus.OK:
if result is None:
result = resp
else:
for emb in resp.output['embeddings']:
emb['text_index'] += batch_counter
result.output['embeddings'].append(emb)
result.usage['total_tokens'] += resp.usage['total_tokens']
else:
print(resp)
batch_counter += len(batch)
print(result)
import java.util.Arrays;
import java.util.List;
import com.alibaba.dashscope.embeddings.TextEmbedding;
import com.alibaba.dashscope.embeddings.TextEmbeddingParam;
import com.alibaba.dashscope.embeddings.TextEmbeddingResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.Constants;
public final class Main {
static {
Constants.baseHttpApiUrl="https://dashscope-intl.aliyuncs.com/api/v1";
// The China (Beijing) region needs to be replaced with: https://dashscope.aliyuncs.com/api/v1
}
private static final int DASHSCOPE_MAX_BATCH_SIZE = 25;
public static void main(String[] args) {
List<String> inputs = Arrays.asList(
"The wind is swift, the sky is high, the apes shriek mournfully",
"The islet is clear, the sand is white, the birds fly back",
"The boundless forest sheds its leaves shower by shower",
"The endless river rolls its waves hour after hour"
);
TextEmbeddingResult result = null;
int batchCounter = 0;
for (int i = 0; i < inputs.size(); i += DASHSCOPE_MAX_BATCH_SIZE) {
List<String> batch = inputs.subList(i, Math.min(i + DASHSCOPE_MAX_BATCH_SIZE, inputs.size()));
TextEmbeddingParam param = TextEmbeddingParam.builder()
// The China (Beijing) region needs to be replaced with: TEXT_EMBEDDING_V4
.model(TextEmbedding.Models.TEXT_EMBEDDING_V3)
.texts(batch)
.build();
TextEmbedding textEmbedding = new TextEmbedding();
try {
TextEmbeddingResult resp = textEmbedding.call(param);
if (resp != null) {
if (result == null) {
result = resp;
} else {
for (var emb : resp.getOutput().getEmbeddings()) {
emb.setTextIndex(emb.getTextIndex() + batchCounter);
result.getOutput().getEmbeddings().add(emb);
}
result.getUsage().setTotalTokens(result.getUsage().getTotalTokens() + resp.getUsage().getTotalTokens());
}
} else {
System.out.println(resp);
}
} catch (ApiException | NoApiKeyException e) {
e.printStackTrace();
}
batchCounter += batch.size();
}
System.out.println(result);
}
}
# ======= Important Note =======
# If you use a model in the China (Beijing) region, you need to replace the base_url with: https://dashscope.aliyuncs.com/api/v1/services/embeddings/text-embedding/text-embedding
# If you use a model in the China (Beijing) region, you need to replace the model with: text_embedding_v4
# === Please delete this comment when executing ====
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/services/embeddings/text-embedding/text-embedding' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "text-embedding-v3",
"input": {
"texts": [
"The wind is swift, the sky is high, the apes shriek mournfully",
"The islet is clear, the sand is white, the birds fly back",
"The boundless forest sheds its leaves shower by shower",
"The endless river rolls its waves hour after hour"
]
},
"parameters": {
"dimension": 1024
}
}'
Plain text file input
The embedding model can generate embedding vectors based on the document you upload. This example uses the texts_to_embedding.txt file.
OpenAI compatible
import os
from openai import OpenAI
client = OpenAI(
api_key=os.getenv("DASHSCOPE_API_KEY"), # If you have not configured environment variables, replace this with your API key
# If you use a model in the China (Beijing) region, you need to replace the base_url with: https://dashscope.aliyuncs.com/compatible-mode/v1
base_url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1" # base_url for Model Studio service
)
with open('texts_to_embedding.txt', 'r', encoding='utf-8') as f:
completion = client.embeddings.create(
# If you use a model in the China (Beijing) region, you need to replace the model with: text-embedding-v4
model="text-embedding-v3",
input=f
)
print(completion.model_dump_json())
import OpenAI from "openai";
import process from 'process';
import fs from 'fs/promises';
// Initialize the OpenAI client
const openai = new OpenAI({
apiKey: process.env.DASHSCOPE_API_KEY, // Read from environment variable
// If you use a model in the China (Beijing) region, you need to replace the baseURL with: https://dashscope.aliyuncs.com/compatible-mode/v1
baseURL: 'https://dashscope-intl.aliyuncs.com/compatible-mode/v1'
});
async function getEmbeddingsFromFile() {
try {
// Read the file content
const fileContent = await fs.readFile('texts_to_embedding.txt', 'utf-8');
// Create embedding vectors
const completion = await openai.embeddings.create({
// If you use a model in the China (Beijing) region, you need to replace the model with: text-embedding-v4
model: "text-embedding-v3",
input: fileContent
});
console.log(JSON.stringify(completion, null, 2));
} catch (error) {
console.error('Error:', error);
}
}
getEmbeddingsFromFile();
# ======= Important Note =======
# If you use a model in the China (Beijing) region, you need to replace the base_url with: https://dashscope.aliyuncs.com/api/v1/embeddings
# If you use a model in the China (Beijing) region, you need to replace the model with: text-embedding-v4
# === Please delete this comment when executing ====
curl --location 'https://dashscope-intl.aliyuncs.com/compatible-mode/v1/embeddings' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "text-embedding-v3",
"input": '"$(cat texts_to_embedding.txt | jq -R -s 'split("\n")[:-1]')"'
}'
DashScope
from http import HTTPStatus
import dashscope
from dashscope import TextEmbedding
# If you use a model in the China (Beijing) region, you need to replace the base_url with: https://dashscope.aliyuncs.com/api/v1
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
with open('texts_to_embedding.txt', 'r', encoding='utf-8') as f:
resp = TextEmbedding.call(
# If you use a model in the China (Beijing) region, you need to replace the model with: text_embedding_v4
model=TextEmbedding.Models.text_embedding_v3,
input=f
)
if resp.status_code == HTTPStatus.OK:
print(resp)
else:
print(resp)
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import com.alibaba.dashscope.embeddings.TextEmbedding;
import com.alibaba.dashscope.embeddings.TextEmbeddingParam;
import com.alibaba.dashscope.embeddings.TextEmbeddingResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.Constants;
public final class Main {
static {
Constants.baseHttpApiUrl="https://dashscope-intl.aliyuncs.com/api/v1";
// The China (Beijing) region needs to be replaced with: https://dashscope.aliyuncs.com/api/v1
}
public static void main(String[] args) {
try (BufferedReader reader = new BufferedReader(new FileReader("<path to the content root of the file>"))) {
StringBuilder content = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
content.append(line).append("\n");
}
TextEmbeddingParam param = TextEmbeddingParam.builder()
// The China (Beijing) region needs to be replaced with: TEXT_EMBEDDING_V4
.model(TextEmbedding.Models.TEXT_EMBEDDING_V3)
.text(content.toString())
.build();
TextEmbedding textEmbedding = new TextEmbedding();
TextEmbeddingResult result = textEmbedding.call(param);
if (result != null) {
System.out.println(result);
} else {
System.out.println("Failed to get embedding: " + result);
}
} catch (IOException | ApiException | NoApiKeyException e) {
e.printStackTrace();
}
}
}
# ======= Important Note =======
# If you use a model in the China (Beijing) region, you need to replace the base_url with: https://dashscope.aliyuncs.com/api/v1/services/embeddings/text-embedding/text-embedding
# If you use a model in the China (Beijing) region, you need to replace the model with: text-embedding-v4
# === Please delete this comment when executing ====
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/services/embeddings/text-embedding/text-embedding' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"model": "text-embedding-v3",
"input": {
"texts": '"$(cat texts_to_embedding.txt | jq -R -s 'split("\n")[:-1]')"'
},
"parameters": {
"dimension": 1024
}
}'
Sample output
OpenAI compatible
{
"data": [
{
"embedding": [
0.0023064255,
-0.009327292,
....
-0.0028842222,
],
"index": 0,
"object": "embedding"
}
],
"model":"text-embedding-v3",
"object":"list",
"usage":{"prompt_tokens":26,"total_tokens":26},
"id":"f62c2ae7-0906-9758-ab34-47c5764f07e2"
}
DashScope
{
"status_code": 200,
"request_id": "617b3670-6f9e-9f47-ad57-997ed8aeba6a",
"code": "",
"message": "",
"output": {
"embeddings": [
{
"embedding": [
0.09393704682588577,
2.4155092239379883,
-1.8923076391220093,
.,
.,
.
],
"text_index": 0
}
]
},
"usage": {
"total_tokens": 26
}
}
Get started with multimodal embedding(Only available in the China (Beijing) region)
You must have obtained an API key and set the API key as an environment variable. If you want to call through SDK, you must also install the DashScope SDK.
Text input
import dashscope
import json
from http import HTTPStatus
text = "Example of a general multimodal representation model"
input = [{'text': text}]
resp = dashscope.MultiModalEmbedding.call(
model="multimodal-embedding-v1",
input=input
)
if resp.status_code == HTTPStatus.OK:
print(json.dumps(resp.output, ensure_ascii=False, indent=4))
Image input
import dashscope
import json
from http import HTTPStatus
image = "https://dashscope.oss-cn-beijing.aliyuncs.com/images/256_1.png"
input = [{'image': image}]
resp = dashscope.MultiModalEmbedding.call(
model="multimodal-embedding-v1",
input=input
)
if resp.status_code == HTTPStatus.OK:
print(json.dumps(resp.output, ensure_ascii=False, indent=4))
Video input
The multimodal-embedding-v1 model supports video file input only in URL format. It does not currently support direct input of local videos.
import dashscope
import json
from http import HTTPStatus
# In actual use, please replace the URL with your video URL
video = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250107/lbcemt/new+video.mp4"
input = [{'video': video}]
# Call the model API
resp = dashscope.MultiModalEmbedding.call(
model="multimodal-embedding-v1",
input=input
)
if resp.status_code == HTTPStatus.OK:
print(json.dumps(resp.output, ensure_ascii=False, indent=4))
Sample output
{
"status_code": 200,
"request_id": "23478d14-55c6-98cc-9706-29d23de742fb",
"code": "",
"message": "",
"output": {
"embeddings": [
{
"index": 0,
"embedding": [
-0.0396728515625,
0.00650787353515625,
-0.0223388671875,
...
],
"type": "image"
}
]
},
"usage": {
"input_tokens": 0,
"image_count": 1,
"duration": 0
}
}
Usage examples
Implement semantic recommendation
API reference
General text embedding
Multimodal embedding
Error codes
If the call failed and an error message is returned, see Error messages for troubleshooting.
Limitations
Before you call the embedding model, make sure that the token length of your input does not exceed the limit. The number of Chinese characters is not exactly equivalent to the number of tokens. You can estimate that one Chinese character is approximately one to two tokens, or use the Token Calculator to calculate the exact number.
The following input type and format limits apply to the multimodal embedding API:
Input type | Language/format limit | Length/Size limit |
Text | Chinese/English | 512 tokens. Text content exceeding 512 tokens will be truncated. |
Image | JPG, PNG, BMP | Supports input in Base64 format or as a URL. The maximum acceptable image size is 3 MB. |
Video | MP4, MPEG, MPG, WEBM, AVI, FLV, MKV, MOV | The maximum acceptable video size is 10 MB. |
The API supports the upload of a single text segment, a single image, or a single video file. It also allows combinations of different types, such as text and image. However, only one combination is allowed per call, and each type of content can be included at most once per call. Files must also meet the length and size requirements.
For information about rate limits, see Rate limits.