dengcao commited on
Commit
949513f
·
verified ·
1 Parent(s): d6e039e

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +348 -346
README.md CHANGED
@@ -1,347 +1,349 @@
1
- # 使用说明
2
-
3
- ·本项目为Docker一键部署安装包,旨在解决Qwen3-Embedding-0.6B模型无法通过Vllm平台直接部署的问题,方便新手朋友快速通过Docker一键部署。
4
-
5
- ·采用vllm最新的开发版制作了Docker镜像dengcao/vllm-openai: v0.9.2-dev,经测试正常,可放心使用。
6
-
7
- 自从Qwen3-Embedding/Qwen3-Reranker系列模型发布以来,迅速在向量嵌入模型和重排模型中掀起了使用热潮,但遗憾的是,许多新手朋友无法正常使用Vllm部署Qwen3-Embedding-0.6B模型,会遇到各种各样的问题。于是,特意做了这个一键部署包,方便大家使用。
8
-
9
- ## Docker desktop(Windows用户)使用方法如下:
10
-
11
- (前提是先在windows部署好Docker desktop)
12
-
13
- 1、下载本项目到windows任意目录。比如:C:\Users\Administrator\vLLM。
14
-
15
- 2、打开:Windows PowerShell,输入:wsl,确定后进入WSL。依次执行下列命令:
16
-
17
- ```
18
- cd /mnt/c/Users/Administrator/vLLM
19
-
20
- docker compose up -d
21
- ```
22
-
23
- 等待下载docker镜像和加载容器完成即可。
24
-
25
- ### 当然以上命令也可以直接在windows命令窗口这样执行:
26
-
27
- ```
28
- cd C:\Users\Administrator\vLLM
29
-
30
- docker compose up -d
31
- ```
32
-
33
- ## Linux用户的Docker版本,可参考以上方法。
34
-
35
- ## 调用Qwen3-Embedding-0.6B模型API接口:
36
-
37
- ### Docker内的容器APP调用:
38
-
39
- ```
40
- API请求地址:http://host.docker.internal:8007/v1/embeddings
41
-
42
- 请求Key:NOT_NEED
43
- ```
44
-
45
- ### Docker外部的APP调用:
46
-
47
- ```
48
- API请求地址:http://localhost:8007/v1/embeddings
49
-
50
- 请求Key:NOT_NEED
51
- ```
52
-
53
- ### 此方法已经在FastGPT上测试通过,可正常Embedding向量嵌入。
54
-
55
-
56
- ---
57
- license: apache-2.0
58
- base_model:
59
- - Qwen/Qwen3-0.6B-Base
60
- tags:
61
- - transformers
62
- - sentence-transformers
63
- - sentence-similarity
64
- - feature-extraction
65
- - text-embeddings-inference
66
- ---
67
- # Qwen3-Embedding-0.6B
68
-
69
- <p align="center">
70
- <img src="https://qianwen-res.oss-accelerate-overseas.aliyuncs.com/logo_qwen3.png" width="400"/>
71
- <p>
72
-
73
- ## Highlights
74
-
75
- The Qwen3 Embedding model series is the latest proprietary model of the Qwen family, specifically designed for text embedding and ranking tasks. Building upon the dense foundational models of the Qwen3 series, it provides a comprehensive range of text embeddings and reranking models in various sizes (0.6B, 4B, and 8B). This series inherits the exceptional multilingual capabilities, long-text understanding, and reasoning skills of its foundational model. The Qwen3 Embedding series represents significant advancements in multiple text embedding and ranking tasks, including text retrieval, code retrieval, text classification, text clustering, and bitext mining.
76
-
77
- **Exceptional Versatility**: The embedding model has achieved state-of-the-art performance across a wide range of downstream application evaluations. The 8B size embedding model ranks **No.1** in the MTEB multilingual leaderboard (as of June 5, 2025, score **70.58**), while the reranking model excels in various text retrieval scenarios.
78
-
79
- **Comprehensive Flexibility**: The Qwen3 Embedding series offers a full spectrum of sizes (from 0.6B to 8B) for both embedding and reranking models, catering to diverse use cases that prioritize efficiency and effectiveness. Developers can seamlessly combine these two modules. Additionally, the embedding model allows for flexible vector definitions across all dimensions, and both embedding and reranking models support user-defined instructions to enhance performance for specific tasks, languages, or scenarios.
80
-
81
- **Multilingual Capability**: The Qwen3 Embedding series offer support for over 100 languages, thanks to the multilingual capabilites of Qwen3 models. This includes various programming languages, and provides robust multilingual, cross-lingual, and code retrieval capabilities.
82
-
83
- ## Model Overview
84
-
85
- **Qwen3-Embedding-0.6B** has the following features:
86
-
87
- - Model Type: Text Embedding
88
- - Supported Languages: 100+ Languages
89
- - Number of Paramaters: 0.6B
90
- - Context Length: 32k
91
- - Embedding Dimension: Up to 1024, supports user-defined output dimensions ranging from 32 to 1024
92
-
93
- For more details, including benchmark evaluation, hardware requirements, and inference performance, please refer to our [blog](https://qwenlm.github.io/blog/qwen3-embedding/), [GitHub](https://github.com/QwenLM/Qwen3-Embedding).
94
-
95
- ## Qwen3 Embedding Series Model list
96
-
97
- | Model Type | Models | Size | Layers | Sequence Length | Embedding Dimension | MRL Support | Instruction Aware |
98
- |------------------|----------------------|------|--------|-----------------|---------------------|-------------|----------------|
99
- | Text Embedding | [Qwen3-Embedding-0.6B](https://huggingface.co/Qwen/Qwen3-Embedding-0.6B) | 0.6B | 28 | 32K | 1024 | Yes | Yes |
100
- | Text Embedding | [Qwen3-Embedding-4B](https://huggingface.co/Qwen/Qwen3-Embedding-4B) | 4B | 36 | 32K | 2560 | Yes | Yes |
101
- | Text Embedding | [Qwen3-Embedding-8B](https://huggingface.co/Qwen/Qwen3-Embedding-8B) | 8B | 36 | 32K | 4096 | Yes | Yes |
102
- | Text Reranking | [Qwen3-Reranker-0.6B](https://huggingface.co/Qwen/Qwen3-Reranker-0.6B) | 0.6B | 28 | 32K | - | - | Yes |
103
- | Text Reranking | [Qwen3-Reranker-4B](https://huggingface.co/Qwen/Qwen3-Reranker-4B) | 4B | 36 | 32K | - | - | Yes |
104
- | Text Reranking | [Qwen3-Reranker-8B](https://huggingface.co/Qwen/Qwen3-Reranker-8B) | 8B | 36 | 32K | - | - | Yes |
105
-
106
- > **Note**:
107
- > - `MRL Support` indicates whether the embedding model supports custom dimensions for the final embedding.
108
- > - `Instruction Aware` notes whether the embedding or reranking model supports customizing the input instruction according to different tasks.
109
- > - Our evaluation indicates that, for most downstream tasks, using instructions (instruct) typically yields an improvement of 1% to 5% compared to not using them. Therefore, we recommend that developers create tailored instructions specific to their tasks and scenarios. In multilingual contexts, we also advise users to write their instructions in English, as most instructions utilized during the model training process were originally written in English.
110
-
111
- ## Usage
112
-
113
- With Transformers versions earlier than 4.51.0, you may encounter the following error:
114
- ```
115
- KeyError: 'qwen3'
116
- ```
117
-
118
- ### Sentence Transformers Usage
119
-
120
- ```python
121
- # Requires transformers>=4.51.0
122
- # Requires sentence-transformers>=2.7.0
123
-
124
- from sentence_transformers import SentenceTransformer
125
-
126
- # Load the model
127
- model = SentenceTransformer("Qwen/Qwen3-Embedding-0.6B")
128
-
129
- # We recommend enabling flash_attention_2 for better acceleration and memory saving,
130
- # together with setting `padding_side` to "left":
131
- # model = SentenceTransformer(
132
- # "Qwen/Qwen3-Embedding-0.6B",
133
- # model_kwargs={"attn_implementation": "flash_attention_2", "device_map": "auto"},
134
- # tokenizer_kwargs={"padding_side": "left"},
135
- # )
136
-
137
- # The queries and documents to embed
138
- queries = [
139
- "What is the capital of China?",
140
- "Explain gravity",
141
- ]
142
- documents = [
143
- "The capital of China is Beijing.",
144
- "Gravity is a force that attracts two bodies towards each other. It gives weight to physical objects and is responsible for the movement of planets around the sun.",
145
- ]
146
-
147
- # Encode the queries and documents. Note that queries benefit from using a prompt
148
- # Here we use the prompt called "query" stored under `model.prompts`, but you can
149
- # also pass your own prompt via the `prompt` argument
150
- query_embeddings = model.encode(queries, prompt_name="query")
151
- document_embeddings = model.encode(documents)
152
-
153
- # Compute the (cosine) similarity between the query and document embeddings
154
- similarity = model.similarity(query_embeddings, document_embeddings)
155
- print(similarity)
156
- # tensor([[0.7646, 0.1414],
157
- # [0.1355, 0.6000]])
158
- ```
159
-
160
- ### Transformers Usage
161
-
162
- ```python
163
- # Requires transformers>=4.51.0
164
-
165
- import torch
166
- import torch.nn.functional as F
167
-
168
- from torch import Tensor
169
- from transformers import AutoTokenizer, AutoModel
170
-
171
-
172
- def last_token_pool(last_hidden_states: Tensor,
173
- attention_mask: Tensor) -> Tensor:
174
- left_padding = (attention_mask[:, -1].sum() == attention_mask.shape[0])
175
- if left_padding:
176
- return last_hidden_states[:, -1]
177
- else:
178
- sequence_lengths = attention_mask.sum(dim=1) - 1
179
- batch_size = last_hidden_states.shape[0]
180
- return last_hidden_states[torch.arange(batch_size, device=last_hidden_states.device), sequence_lengths]
181
-
182
-
183
- def get_detailed_instruct(task_description: str, query: str) -> str:
184
- return f'Instruct: {task_description}\nQuery:{query}'
185
-
186
- # Each query must come with a one-sentence instruction that describes the task
187
- task = 'Given a web search query, retrieve relevant passages that answer the query'
188
-
189
- queries = [
190
- get_detailed_instruct(task, 'What is the capital of China?'),
191
- get_detailed_instruct(task, 'Explain gravity')
192
- ]
193
- # No need to add instruction for retrieval documents
194
- documents = [
195
- "The capital of China is Beijing.",
196
- "Gravity is a force that attracts two bodies towards each other. It gives weight to physical objects and is responsible for the movement of planets around the sun."
197
- ]
198
- input_texts = queries + documents
199
-
200
- tokenizer = AutoTokenizer.from_pretrained('Qwen/Qwen3-Embedding-0.6B', padding_side='left')
201
- model = AutoModel.from_pretrained('Qwen/Qwen3-Embedding-0.6B')
202
-
203
- # We recommend enabling flash_attention_2 for better acceleration and memory saving.
204
- # model = AutoModel.from_pretrained('Qwen/Qwen3-Embedding-0.6B', attn_implementation="flash_attention_2", torch_dtype=torch.float16).cuda()
205
-
206
- max_length = 8192
207
-
208
- # Tokenize the input texts
209
- batch_dict = tokenizer(
210
- input_texts,
211
- padding=True,
212
- truncation=True,
213
- max_length=max_length,
214
- return_tensors="pt",
215
- )
216
- batch_dict.to(model.device)
217
- outputs = model(**batch_dict)
218
- embeddings = last_token_pool(outputs.last_hidden_state, batch_dict['attention_mask'])
219
-
220
- # normalize embeddings
221
- embeddings = F.normalize(embeddings, p=2, dim=1)
222
- scores = (embeddings[:2] @ embeddings[2:].T)
223
- print(scores.tolist())
224
- # [[0.7645568251609802, 0.14142508804798126], [0.13549736142158508, 0.5999549627304077]]
225
- ```
226
-
227
- ### vLLM Usage
228
-
229
- ```python
230
- # Requires vllm>=0.8.5
231
- import torch
232
- import vllm
233
- from vllm import LLM
234
-
235
- def get_detailed_instruct(task_description: str, query: str) -> str:
236
- return f'Instruct: {task_description}\nQuery:{query}'
237
-
238
- # Each query must come with a one-sentence instruction that describes the task
239
- task = 'Given a web search query, retrieve relevant passages that answer the query'
240
-
241
- queries = [
242
- get_detailed_instruct(task, 'What is the capital of China?'),
243
- get_detailed_instruct(task, 'Explain gravity')
244
- ]
245
- # No need to add instruction for retrieval documents
246
- documents = [
247
- "The capital of China is Beijing.",
248
- "Gravity is a force that attracts two bodies towards each other. It gives weight to physical objects and is responsible for the movement of planets around the sun."
249
- ]
250
- input_texts = queries + documents
251
-
252
- model = LLM(model="Qwen/Qwen3-Embedding-0.6B", task="embed")
253
-
254
- outputs = model.embed(input_texts)
255
- embeddings = torch.tensor([o.outputs.embedding for o in outputs])
256
- scores = (embeddings[:2] @ embeddings[2:].T)
257
- print(scores.tolist())
258
- # [[0.7620252966880798, 0.14078938961029053], [0.1358368694782257, 0.6013815999031067]]
259
- ```
260
-
261
- 📌 **Tip**: We recommend that developers customize the `instruct` according to their specific scenarios, tasks, and languages. Our tests have shown that in most retrieval scenarios, not using an `instruct` on the query side can lead to a drop in retrieval performance by approximately 1% to 5%.
262
-
263
- ### Text Embeddings Inference (TEI) Usage
264
-
265
- You can either run / deploy TEI on NVIDIA GPUs as:
266
-
267
- ```bash
268
- docker run --gpus all -p 8080:80 -v hf_cache:/data --pull always ghcr.io/huggingface/text-embeddings-inference:cpu-1.7.2 --model-id Qwen/Qwen3-Embedding-0.6B --dtype float16
269
- ```
270
-
271
- Or on CPU devices as:
272
-
273
- ```bash
274
- docker run -p 8080:80 -v hf_cache:/data --pull always ghcr.io/huggingface/text-embeddings-inference:1.7.2 --model-id Qwen/Qwen3-Embedding-0.6B
275
- ```
276
-
277
- And then, generate the embeddings sending a HTTP POST request as:
278
-
279
- ```bash
280
- curl http://localhost:8080/embed \
281
- -X POST \
282
- -d '{"inputs": ["Instruct: Given a web search query, retrieve relevant passages that answer the query\nQuery: What is the capital of China?", "Instruct: Given a web search query, retrieve relevant passages that answer the query\nQuery: Explain gravity"]}' \
283
- -H "Content-Type: application/json"
284
- ```
285
-
286
- ## Evaluation
287
-
288
- ### MTEB (Multilingual)
289
-
290
- | Model | Size | Mean (Task) | Mean (Type) | Bitxt Mining | Class. | Clust. | Inst. Retri. | Multi. Class. | Pair. Class. | Rerank | Retri. | STS |
291
- |----------------------------------|:-------:|:-------------:|:-------------:|:--------------:|:--------:|:--------:|:--------------:|:---------------:|:--------------:|:--------:|:--------:|:------:|
292
- | NV-Embed-v2 | 7B | 56.29 | 49.58 | 57.84 | 57.29 | 40.80 | 1.04 | 18.63 | 78.94 | 63.82 | 56.72 | 71.10|
293
- | GritLM-7B | 7B | 60.92 | 53.74 | 70.53 | 61.83 | 49.75 | 3.45 | 22.77 | 79.94 | 63.78 | 58.31 | 73.33|
294
- | BGE-M3 | 0.6B | 59.56 | 52.18 | 79.11 | 60.35 | 40.88 | -3.11 | 20.1 | 80.76 | 62.79 | 54.60 | 74.12|
295
- | multilingual-e5-large-instruct | 0.6B | 63.22 | 55.08 | 80.13 | 64.94 | 50.75 | -0.40 | 22.91 | 80.86 | 62.61 | 57.12 | 76.81|
296
- | gte-Qwen2-1.5B-instruct | 1.5B | 59.45 | 52.69 | 62.51 | 58.32 | 52.05 | 0.74 | 24.02 | 81.58 | 62.58 | 60.78 | 71.61|
297
- | gte-Qwen2-7b-Instruct | 7B | 62.51 | 55.93 | 73.92 | 61.55 | 52.77 | 4.94 | 25.48 | 85.13 | 65.55 | 60.08 | 73.98|
298
- | text-embedding-3-large | - | 58.93 | 51.41 | 62.17 | 60.27 | 46.89 | -2.68 | 22.03 | 79.17 | 63.89 | 59.27 | 71.68|
299
- | Cohere-embed-multilingual-v3.0 | - | 61.12 | 53.23 | 70.50 | 62.95 | 46.89 | -1.89 | 22.74 | 79.88 | 64.07 | 59.16 | 74.80|
300
- | Gemini Embedding | - | 68.37 | 59.59 | 79.28 | 71.82 | 54.59 | 5.18 | **29.16** | 83.63 | 65.58 | 67.71 | 79.40|
301
- | **Qwen3-Embedding-0.6B** | 0.6B | 64.33 | 56.00 | 72.22 | 66.83 | 52.33 | 5.09 | 24.59 | 80.83 | 61.41 | 64.64 | 76.17|
302
- | **Qwen3-Embedding-4B** | 4B | 69.45 | 60.86 | 79.36 | 72.33 | 57.15 | **11.56** | 26.77 | 85.05 | 65.08 | 69.60 | 80.86|
303
- | **Qwen3-Embedding-8B** | 8B | **70.58** | **61.69** | **80.89** | **74.00** | **57.65** | 10.06 | 28.66 | **86.40** | **65.63** | **70.88** | **81.08** |
304
-
305
- > **Note**: For compared models, the scores are retrieved from MTEB online [leaderboard](https://huggingface.co/spaces/mteb/leaderboard) on May 24th, 2025.
306
-
307
- ### MTEB (Eng v2)
308
-
309
- | MTEB English / Models | Param. | Mean(Task) | Mean(Type) | Class. | Clust. | Pair Class. | Rerank. | Retri. | STS | Summ. |
310
- |--------------------------------|:--------:|:------------:|:------------:|:--------:|:--------:|:-------------:|:---------:|:--------:|:-------:|:-------:|
311
- | multilingual-e5-large-instruct | 0.6B | 65.53 | 61.21 | 75.54 | 49.89 | 86.24 | 48.74 | 53.47 | 84.72 | 29.89 |
312
- | NV-Embed-v2 | 7.8B | 69.81 | 65.00 | 87.19 | 47.66 | 88.69 | 49.61 | 62.84 | 83.82 | 35.21 |
313
- | GritLM-7B | 7.2B | 67.07 | 63.22 | 81.25 | 50.82 | 87.29 | 49.59 | 54.95 | 83.03 | 35.65 |
314
- | gte-Qwen2-1.5B-instruct | 1.5B | 67.20 | 63.26 | 85.84 | 53.54 | 87.52 | 49.25 | 50.25 | 82.51 | 33.94 |
315
- | stella_en_1.5B_v5 | 1.5B | 69.43 | 65.32 | 89.38 | 57.06 | 88.02 | 50.19 | 52.42 | 83.27 | 36.91 |
316
- | gte-Qwen2-7B-instruct | 7.6B | 70.72 | 65.77 | 88.52 | 58.97 | 85.9 | 50.47 | 58.09 | 82.69 | 35.74 |
317
- | gemini-embedding-exp-03-07 | - | 73.3 | 67.67 | 90.05 | 59.39 | 87.7 | 48.59 | 64.35 | 85.29 | 38.28 |
318
- | **Qwen3-Embedding-0.6B** | 0.6B | 70.70 | 64.88 | 85.76 | 54.05 | 84.37 | 48.18 | 61.83 | 86.57 | 33.43 |
319
- | **Qwen3-Embedding-4B** | 4B | 74.60 | 68.10 | 89.84 | 57.51 | 87.01 | 50.76 | 68.46 | 88.72 | 34.39 |
320
- | **Qwen3-Embedding-8B** | 8B | 75.22 | 68.71 | 90.43 | 58.57 | 87.52 | 51.56 | 69.44 | 88.58 | 34.83 |
321
-
322
- ### C-MTEB (MTEB Chinese)
323
-
324
- | C-MTEB | Param. | Mean(Task) | Mean(Type) | Class. | Clust. | Pair Class. | Rerank. | Retr. | STS |
325
- |------------------|--------|------------|------------|--------|--------|-------------|---------|-------|-------|
326
- | multilingual-e5-large-instruct | 0.6B | 58.08 | 58.24 | 69.80 | 48.23 | 64.52 | 57.45 | 63.65 | 45.81 |
327
- | bge-multilingual-gemma2 | 9B | 67.64 | 75.31 | 59.30 | 86.67 | 68.28 | 73.73 | 55.19 | - |
328
- | gte-Qwen2-1.5B-instruct | 1.5B | 67.12 | 67.79 | 72.53 | 54.61 | 79.5 | 68.21 | 71.86 | 60.05 |
329
- | gte-Qwen2-7B-instruct | 7.6B | 71.62 | 72.19 | 75.77 | 66.06 | 81.16 | 69.24 | 75.70 | 65.20 |
330
- | ritrieve_zh_v1 | 0.3B | 72.71 | 73.85 | 76.88 | 66.5 | 85.98 | 72.86 | 76.97 | 63.92 |
331
- | **Qwen3-Embedding-0.6B** | 0.6B | 66.33 | 67.45 | 71.40 | 68.74 | 76.42 | 62.58 | 71.03 | 54.52 |
332
- | **Qwen3-Embedding-4B** | 4B | 72.27 | 73.51 | 75.46 | 77.89 | 83.34 | 66.05 | 77.03 | 61.26 |
333
- | **Qwen3-Embedding-8B** | 8B | 73.84 | 75.00 | 76.97 | 80.08 | 84.23 | 66.99 | 78.21 | 63.53 |
334
-
335
-
336
- ## Citation
337
-
338
- If you find our work helpful, feel free to give us a cite.
339
-
340
- ```
341
- @article{qwen3embedding,
342
- title={Qwen3 Embedding: Advancing Text Embedding and Reranking Through Foundation Models},
343
- author={Zhang, Yanzhao and Li, Mingxin and Long, Dingkun and Zhang, Xin and Lin, Huan and Yang, Baosong and Xie, Pengjun and Yang, An and Liu, Dayiheng and Lin, Junyang and Huang, Fei and Zhou, Jingren},
344
- journal={arXiv preprint arXiv:2506.05176},
345
- year={2025}
346
- }
 
 
347
  ```
 
1
+ ---
2
+ license: apache-2.0
3
+ base_model:
4
+ - Qwen/Qwen3-0.6B-Base
5
+ tags:
6
+ - transformers
7
+ - sentence-transformers
8
+ - sentence-similarity
9
+ - feature-extraction
10
+ - text-embeddings-inference
11
+ ---
12
+
13
+ # 使用说明
14
+
15
+ ·本项目为Docker一键部署安装包,旨在解决Qwen3-Embedding-0.6B模型无法通过Vllm平台直接部署的问题,方便新手朋友快速通过Docker一键部署。
16
+
17
+ ·采用vllm最新的开发版制作了Docker镜像dengcao/vllm-openai: v0.9.2-dev,经测试正常,可放心使用。
18
+
19
+ 自从Qwen3-Embedding/Qwen3-Reranker系列模型发布以来,迅速在向量嵌入模型和重排模型中掀起了使用热潮,但遗憾的是,许多新手朋友无法正常使用Vllm部署Qwen3-Embedding-0.6B模型,会遇到各种各样的问题。于是,特意做了这个一键部署包,方便大家使用。
20
+
21
+ ## Docker desktop(Windows用户)使用方法如下:
22
+
23
+ (前提是先在windows部署好Docker desktop)
24
+
25
+ 1、下载本项目到windows任意目录。比如:C:\Users\Administrator\vLLM。
26
+
27
+ 2、打开:Windows PowerShell,输入:wsl,确定后进入WSL。依次执行下列命令:
28
+
29
+ ```
30
+ cd /mnt/c/Users/Administrator/vLLM
31
+
32
+ docker compose up -d
33
+ ```
34
+
35
+ 等待下载docker镜像和加载容器完成即可。
36
+
37
+ ### 当然以上命令也可以直接在windows命令窗口这样执行:
38
+
39
+ ```
40
+ cd C:\Users\Administrator\vLLM
41
+
42
+ docker compose up -d
43
+ ```
44
+
45
+ ## Linux用户的Docker版本,可参考以上方法。
46
+
47
+ ## 调用Qwen3-Embedding-0.6B模型API接口:
48
+
49
+ ### Docker内的容器APP调用:
50
+
51
+ ```
52
+ API请求地址:http://host.docker.internal:8007/v1/embeddings
53
+
54
+ 请求Key:NOT_NEED
55
+ ```
56
+
57
+ ### Docker外部的APP调用:
58
+
59
+ ```
60
+ API请求地址:http://localhost:8007/v1/embeddings
61
+
62
+ 请求Key:NOT_NEED
63
+ ```
64
+
65
+ ### 此方法已经在FastGPT上测试通过,可正常Embedding向量嵌入。
66
+
67
+
68
+
69
+ # Qwen3-Embedding-0.6B
70
+
71
+ <p align="center">
72
+ <img src="https://qianwen-res.oss-accelerate-overseas.aliyuncs.com/logo_qwen3.png" width="400"/>
73
+ <p>
74
+
75
+ ## Highlights
76
+
77
+ The Qwen3 Embedding model series is the latest proprietary model of the Qwen family, specifically designed for text embedding and ranking tasks. Building upon the dense foundational models of the Qwen3 series, it provides a comprehensive range of text embeddings and reranking models in various sizes (0.6B, 4B, and 8B). This series inherits the exceptional multilingual capabilities, long-text understanding, and reasoning skills of its foundational model. The Qwen3 Embedding series represents significant advancements in multiple text embedding and ranking tasks, including text retrieval, code retrieval, text classification, text clustering, and bitext mining.
78
+
79
+ **Exceptional Versatility**: The embedding model has achieved state-of-the-art performance across a wide range of downstream application evaluations. The 8B size embedding model ranks **No.1** in the MTEB multilingual leaderboard (as of June 5, 2025, score **70.58**), while the reranking model excels in various text retrieval scenarios.
80
+
81
+ **Comprehensive Flexibility**: The Qwen3 Embedding series offers a full spectrum of sizes (from 0.6B to 8B) for both embedding and reranking models, catering to diverse use cases that prioritize efficiency and effectiveness. Developers can seamlessly combine these two modules. Additionally, the embedding model allows for flexible vector definitions across all dimensions, and both embedding and reranking models support user-defined instructions to enhance performance for specific tasks, languages, or scenarios.
82
+
83
+ **Multilingual Capability**: The Qwen3 Embedding series offer support for over 100 languages, thanks to the multilingual capabilites of Qwen3 models. This includes various programming languages, and provides robust multilingual, cross-lingual, and code retrieval capabilities.
84
+
85
+ ## Model Overview
86
+
87
+ **Qwen3-Embedding-0.6B** has the following features:
88
+
89
+ - Model Type: Text Embedding
90
+ - Supported Languages: 100+ Languages
91
+ - Number of Paramaters: 0.6B
92
+ - Context Length: 32k
93
+ - Embedding Dimension: Up to 1024, supports user-defined output dimensions ranging from 32 to 1024
94
+
95
+ For more details, including benchmark evaluation, hardware requirements, and inference performance, please refer to our [blog](https://qwenlm.github.io/blog/qwen3-embedding/), [GitHub](https://github.com/QwenLM/Qwen3-Embedding).
96
+
97
+ ## Qwen3 Embedding Series Model list
98
+
99
+ | Model Type | Models | Size | Layers | Sequence Length | Embedding Dimension | MRL Support | Instruction Aware |
100
+ |------------------|----------------------|------|--------|-----------------|---------------------|-------------|----------------|
101
+ | Text Embedding | [Qwen3-Embedding-0.6B](https://huggingface.co/Qwen/Qwen3-Embedding-0.6B) | 0.6B | 28 | 32K | 1024 | Yes | Yes |
102
+ | Text Embedding | [Qwen3-Embedding-4B](https://huggingface.co/Qwen/Qwen3-Embedding-4B) | 4B | 36 | 32K | 2560 | Yes | Yes |
103
+ | Text Embedding | [Qwen3-Embedding-8B](https://huggingface.co/Qwen/Qwen3-Embedding-8B) | 8B | 36 | 32K | 4096 | Yes | Yes |
104
+ | Text Reranking | [Qwen3-Reranker-0.6B](https://huggingface.co/Qwen/Qwen3-Reranker-0.6B) | 0.6B | 28 | 32K | - | - | Yes |
105
+ | Text Reranking | [Qwen3-Reranker-4B](https://huggingface.co/Qwen/Qwen3-Reranker-4B) | 4B | 36 | 32K | - | - | Yes |
106
+ | Text Reranking | [Qwen3-Reranker-8B](https://huggingface.co/Qwen/Qwen3-Reranker-8B) | 8B | 36 | 32K | - | - | Yes |
107
+
108
+ > **Note**:
109
+ > - `MRL Support` indicates whether the embedding model supports custom dimensions for the final embedding.
110
+ > - `Instruction Aware` notes whether the embedding or reranking model supports customizing the input instruction according to different tasks.
111
+ > - Our evaluation indicates that, for most downstream tasks, using instructions (instruct) typically yields an improvement of 1% to 5% compared to not using them. Therefore, we recommend that developers create tailored instructions specific to their tasks and scenarios. In multilingual contexts, we also advise users to write their instructions in English, as most instructions utilized during the model training process were originally written in English.
112
+
113
+ ## Usage
114
+
115
+ With Transformers versions earlier than 4.51.0, you may encounter the following error:
116
+ ```
117
+ KeyError: 'qwen3'
118
+ ```
119
+
120
+ ### Sentence Transformers Usage
121
+
122
+ ```python
123
+ # Requires transformers>=4.51.0
124
+ # Requires sentence-transformers>=2.7.0
125
+
126
+ from sentence_transformers import SentenceTransformer
127
+
128
+ # Load the model
129
+ model = SentenceTransformer("Qwen/Qwen3-Embedding-0.6B")
130
+
131
+ # We recommend enabling flash_attention_2 for better acceleration and memory saving,
132
+ # together with setting `padding_side` to "left":
133
+ # model = SentenceTransformer(
134
+ # "Qwen/Qwen3-Embedding-0.6B",
135
+ # model_kwargs={"attn_implementation": "flash_attention_2", "device_map": "auto"},
136
+ # tokenizer_kwargs={"padding_side": "left"},
137
+ # )
138
+
139
+ # The queries and documents to embed
140
+ queries = [
141
+ "What is the capital of China?",
142
+ "Explain gravity",
143
+ ]
144
+ documents = [
145
+ "The capital of China is Beijing.",
146
+ "Gravity is a force that attracts two bodies towards each other. It gives weight to physical objects and is responsible for the movement of planets around the sun.",
147
+ ]
148
+
149
+ # Encode the queries and documents. Note that queries benefit from using a prompt
150
+ # Here we use the prompt called "query" stored under `model.prompts`, but you can
151
+ # also pass your own prompt via the `prompt` argument
152
+ query_embeddings = model.encode(queries, prompt_name="query")
153
+ document_embeddings = model.encode(documents)
154
+
155
+ # Compute the (cosine) similarity between the query and document embeddings
156
+ similarity = model.similarity(query_embeddings, document_embeddings)
157
+ print(similarity)
158
+ # tensor([[0.7646, 0.1414],
159
+ # [0.1355, 0.6000]])
160
+ ```
161
+
162
+ ### Transformers Usage
163
+
164
+ ```python
165
+ # Requires transformers>=4.51.0
166
+
167
+ import torch
168
+ import torch.nn.functional as F
169
+
170
+ from torch import Tensor
171
+ from transformers import AutoTokenizer, AutoModel
172
+
173
+
174
+ def last_token_pool(last_hidden_states: Tensor,
175
+ attention_mask: Tensor) -> Tensor:
176
+ left_padding = (attention_mask[:, -1].sum() == attention_mask.shape[0])
177
+ if left_padding:
178
+ return last_hidden_states[:, -1]
179
+ else:
180
+ sequence_lengths = attention_mask.sum(dim=1) - 1
181
+ batch_size = last_hidden_states.shape[0]
182
+ return last_hidden_states[torch.arange(batch_size, device=last_hidden_states.device), sequence_lengths]
183
+
184
+
185
+ def get_detailed_instruct(task_description: str, query: str) -> str:
186
+ return f'Instruct: {task_description}\nQuery:{query}'
187
+
188
+ # Each query must come with a one-sentence instruction that describes the task
189
+ task = 'Given a web search query, retrieve relevant passages that answer the query'
190
+
191
+ queries = [
192
+ get_detailed_instruct(task, 'What is the capital of China?'),
193
+ get_detailed_instruct(task, 'Explain gravity')
194
+ ]
195
+ # No need to add instruction for retrieval documents
196
+ documents = [
197
+ "The capital of China is Beijing.",
198
+ "Gravity is a force that attracts two bodies towards each other. It gives weight to physical objects and is responsible for the movement of planets around the sun."
199
+ ]
200
+ input_texts = queries + documents
201
+
202
+ tokenizer = AutoTokenizer.from_pretrained('Qwen/Qwen3-Embedding-0.6B', padding_side='left')
203
+ model = AutoModel.from_pretrained('Qwen/Qwen3-Embedding-0.6B')
204
+
205
+ # We recommend enabling flash_attention_2 for better acceleration and memory saving.
206
+ # model = AutoModel.from_pretrained('Qwen/Qwen3-Embedding-0.6B', attn_implementation="flash_attention_2", torch_dtype=torch.float16).cuda()
207
+
208
+ max_length = 8192
209
+
210
+ # Tokenize the input texts
211
+ batch_dict = tokenizer(
212
+ input_texts,
213
+ padding=True,
214
+ truncation=True,
215
+ max_length=max_length,
216
+ return_tensors="pt",
217
+ )
218
+ batch_dict.to(model.device)
219
+ outputs = model(**batch_dict)
220
+ embeddings = last_token_pool(outputs.last_hidden_state, batch_dict['attention_mask'])
221
+
222
+ # normalize embeddings
223
+ embeddings = F.normalize(embeddings, p=2, dim=1)
224
+ scores = (embeddings[:2] @ embeddings[2:].T)
225
+ print(scores.tolist())
226
+ # [[0.7645568251609802, 0.14142508804798126], [0.13549736142158508, 0.5999549627304077]]
227
+ ```
228
+
229
+ ### vLLM Usage
230
+
231
+ ```python
232
+ # Requires vllm>=0.8.5
233
+ import torch
234
+ import vllm
235
+ from vllm import LLM
236
+
237
+ def get_detailed_instruct(task_description: str, query: str) -> str:
238
+ return f'Instruct: {task_description}\nQuery:{query}'
239
+
240
+ # Each query must come with a one-sentence instruction that describes the task
241
+ task = 'Given a web search query, retrieve relevant passages that answer the query'
242
+
243
+ queries = [
244
+ get_detailed_instruct(task, 'What is the capital of China?'),
245
+ get_detailed_instruct(task, 'Explain gravity')
246
+ ]
247
+ # No need to add instruction for retrieval documents
248
+ documents = [
249
+ "The capital of China is Beijing.",
250
+ "Gravity is a force that attracts two bodies towards each other. It gives weight to physical objects and is responsible for the movement of planets around the sun."
251
+ ]
252
+ input_texts = queries + documents
253
+
254
+ model = LLM(model="Qwen/Qwen3-Embedding-0.6B", task="embed")
255
+
256
+ outputs = model.embed(input_texts)
257
+ embeddings = torch.tensor([o.outputs.embedding for o in outputs])
258
+ scores = (embeddings[:2] @ embeddings[2:].T)
259
+ print(scores.tolist())
260
+ # [[0.7620252966880798, 0.14078938961029053], [0.1358368694782257, 0.6013815999031067]]
261
+ ```
262
+
263
+ 📌 **Tip**: We recommend that developers customize the `instruct` according to their specific scenarios, tasks, and languages. Our tests have shown that in most retrieval scenarios, not using an `instruct` on the query side can lead to a drop in retrieval performance by approximately 1% to 5%.
264
+
265
+ ### Text Embeddings Inference (TEI) Usage
266
+
267
+ You can either run / deploy TEI on NVIDIA GPUs as:
268
+
269
+ ```bash
270
+ docker run --gpus all -p 8080:80 -v hf_cache:/data --pull always ghcr.io/huggingface/text-embeddings-inference:cpu-1.7.2 --model-id Qwen/Qwen3-Embedding-0.6B --dtype float16
271
+ ```
272
+
273
+ Or on CPU devices as:
274
+
275
+ ```bash
276
+ docker run -p 8080:80 -v hf_cache:/data --pull always ghcr.io/huggingface/text-embeddings-inference:1.7.2 --model-id Qwen/Qwen3-Embedding-0.6B
277
+ ```
278
+
279
+ And then, generate the embeddings sending a HTTP POST request as:
280
+
281
+ ```bash
282
+ curl http://localhost:8080/embed \
283
+ -X POST \
284
+ -d '{"inputs": ["Instruct: Given a web search query, retrieve relevant passages that answer the query\nQuery: What is the capital of China?", "Instruct: Given a web search query, retrieve relevant passages that answer the query\nQuery: Explain gravity"]}' \
285
+ -H "Content-Type: application/json"
286
+ ```
287
+
288
+ ## Evaluation
289
+
290
+ ### MTEB (Multilingual)
291
+
292
+ | Model | Size | Mean (Task) | Mean (Type) | Bitxt Mining | Class. | Clust. | Inst. Retri. | Multi. Class. | Pair. Class. | Rerank | Retri. | STS |
293
+ |----------------------------------|:-------:|:-------------:|:-------------:|:--------------:|:--------:|:--------:|:--------------:|:---------------:|:--------------:|:--------:|:--------:|:------:|
294
+ | NV-Embed-v2 | 7B | 56.29 | 49.58 | 57.84 | 57.29 | 40.80 | 1.04 | 18.63 | 78.94 | 63.82 | 56.72 | 71.10|
295
+ | GritLM-7B | 7B | 60.92 | 53.74 | 70.53 | 61.83 | 49.75 | 3.45 | 22.77 | 79.94 | 63.78 | 58.31 | 73.33|
296
+ | BGE-M3 | 0.6B | 59.56 | 52.18 | 79.11 | 60.35 | 40.88 | -3.11 | 20.1 | 80.76 | 62.79 | 54.60 | 74.12|
297
+ | multilingual-e5-large-instruct | 0.6B | 63.22 | 55.08 | 80.13 | 64.94 | 50.75 | -0.40 | 22.91 | 80.86 | 62.61 | 57.12 | 76.81|
298
+ | gte-Qwen2-1.5B-instruct | 1.5B | 59.45 | 52.69 | 62.51 | 58.32 | 52.05 | 0.74 | 24.02 | 81.58 | 62.58 | 60.78 | 71.61|
299
+ | gte-Qwen2-7b-Instruct | 7B | 62.51 | 55.93 | 73.92 | 61.55 | 52.77 | 4.94 | 25.48 | 85.13 | 65.55 | 60.08 | 73.98|
300
+ | text-embedding-3-large | - | 58.93 | 51.41 | 62.17 | 60.27 | 46.89 | -2.68 | 22.03 | 79.17 | 63.89 | 59.27 | 71.68|
301
+ | Cohere-embed-multilingual-v3.0 | - | 61.12 | 53.23 | 70.50 | 62.95 | 46.89 | -1.89 | 22.74 | 79.88 | 64.07 | 59.16 | 74.80|
302
+ | Gemini Embedding | - | 68.37 | 59.59 | 79.28 | 71.82 | 54.59 | 5.18 | **29.16** | 83.63 | 65.58 | 67.71 | 79.40|
303
+ | **Qwen3-Embedding-0.6B** | 0.6B | 64.33 | 56.00 | 72.22 | 66.83 | 52.33 | 5.09 | 24.59 | 80.83 | 61.41 | 64.64 | 76.17|
304
+ | **Qwen3-Embedding-4B** | 4B | 69.45 | 60.86 | 79.36 | 72.33 | 57.15 | **11.56** | 26.77 | 85.05 | 65.08 | 69.60 | 80.86|
305
+ | **Qwen3-Embedding-8B** | 8B | **70.58** | **61.69** | **80.89** | **74.00** | **57.65** | 10.06 | 28.66 | **86.40** | **65.63** | **70.88** | **81.08** |
306
+
307
+ > **Note**: For compared models, the scores are retrieved from MTEB online [leaderboard](https://huggingface.co/spaces/mteb/leaderboard) on May 24th, 2025.
308
+
309
+ ### MTEB (Eng v2)
310
+
311
+ | MTEB English / Models | Param. | Mean(Task) | Mean(Type) | Class. | Clust. | Pair Class. | Rerank. | Retri. | STS | Summ. |
312
+ |--------------------------------|:--------:|:------------:|:------------:|:--------:|:--------:|:-------------:|:---------:|:--------:|:-------:|:-------:|
313
+ | multilingual-e5-large-instruct | 0.6B | 65.53 | 61.21 | 75.54 | 49.89 | 86.24 | 48.74 | 53.47 | 84.72 | 29.89 |
314
+ | NV-Embed-v2 | 7.8B | 69.81 | 65.00 | 87.19 | 47.66 | 88.69 | 49.61 | 62.84 | 83.82 | 35.21 |
315
+ | GritLM-7B | 7.2B | 67.07 | 63.22 | 81.25 | 50.82 | 87.29 | 49.59 | 54.95 | 83.03 | 35.65 |
316
+ | gte-Qwen2-1.5B-instruct | 1.5B | 67.20 | 63.26 | 85.84 | 53.54 | 87.52 | 49.25 | 50.25 | 82.51 | 33.94 |
317
+ | stella_en_1.5B_v5 | 1.5B | 69.43 | 65.32 | 89.38 | 57.06 | 88.02 | 50.19 | 52.42 | 83.27 | 36.91 |
318
+ | gte-Qwen2-7B-instruct | 7.6B | 70.72 | 65.77 | 88.52 | 58.97 | 85.9 | 50.47 | 58.09 | 82.69 | 35.74 |
319
+ | gemini-embedding-exp-03-07 | - | 73.3 | 67.67 | 90.05 | 59.39 | 87.7 | 48.59 | 64.35 | 85.29 | 38.28 |
320
+ | **Qwen3-Embedding-0.6B** | 0.6B | 70.70 | 64.88 | 85.76 | 54.05 | 84.37 | 48.18 | 61.83 | 86.57 | 33.43 |
321
+ | **Qwen3-Embedding-4B** | 4B | 74.60 | 68.10 | 89.84 | 57.51 | 87.01 | 50.76 | 68.46 | 88.72 | 34.39 |
322
+ | **Qwen3-Embedding-8B** | 8B | 75.22 | 68.71 | 90.43 | 58.57 | 87.52 | 51.56 | 69.44 | 88.58 | 34.83 |
323
+
324
+ ### C-MTEB (MTEB Chinese)
325
+
326
+ | C-MTEB | Param. | Mean(Task) | Mean(Type) | Class. | Clust. | Pair Class. | Rerank. | Retr. | STS |
327
+ |------------------|--------|------------|------------|--------|--------|-------------|---------|-------|-------|
328
+ | multilingual-e5-large-instruct | 0.6B | 58.08 | 58.24 | 69.80 | 48.23 | 64.52 | 57.45 | 63.65 | 45.81 |
329
+ | bge-multilingual-gemma2 | 9B | 67.64 | 75.31 | 59.30 | 86.67 | 68.28 | 73.73 | 55.19 | - |
330
+ | gte-Qwen2-1.5B-instruct | 1.5B | 67.12 | 67.79 | 72.53 | 54.61 | 79.5 | 68.21 | 71.86 | 60.05 |
331
+ | gte-Qwen2-7B-instruct | 7.6B | 71.62 | 72.19 | 75.77 | 66.06 | 81.16 | 69.24 | 75.70 | 65.20 |
332
+ | ritrieve_zh_v1 | 0.3B | 72.71 | 73.85 | 76.88 | 66.5 | 85.98 | 72.86 | 76.97 | 63.92 |
333
+ | **Qwen3-Embedding-0.6B** | 0.6B | 66.33 | 67.45 | 71.40 | 68.74 | 76.42 | 62.58 | 71.03 | 54.52 |
334
+ | **Qwen3-Embedding-4B** | 4B | 72.27 | 73.51 | 75.46 | 77.89 | 83.34 | 66.05 | 77.03 | 61.26 |
335
+ | **Qwen3-Embedding-8B** | 8B | 73.84 | 75.00 | 76.97 | 80.08 | 84.23 | 66.99 | 78.21 | 63.53 |
336
+
337
+
338
+ ## Citation
339
+
340
+ If you find our work helpful, feel free to give us a cite.
341
+
342
+ ```
343
+ @article{qwen3embedding,
344
+ title={Qwen3 Embedding: Advancing Text Embedding and Reranking Through Foundation Models},
345
+ author={Zhang, Yanzhao and Li, Mingxin and Long, Dingkun and Zhang, Xin and Lin, Huan and Yang, Baosong and Xie, Pengjun and Yang, An and Liu, Dayiheng and Lin, Junyang and Huang, Fei and Zhou, Jingren},
346
+ journal={arXiv preprint arXiv:2506.05176},
347
+ year={2025}
348
+ }
349
  ```