超强!阿里开源 Qwen3 Embedding 系列模型,多语言文本嵌入与重排的新标杆
前两天阿里通义实验室重磅开源了 Qwen3-Embedding 系列模型,不仅提供了文本嵌入 Embedding 模型,还提供了重排 Reranker 模型。作为千问家族的最新成员,这个系列在 MMTEB、MTEB 及 MTEB-Code 三大权威评测中全面达到 SOTA 性能,并且支持多达 119 种语言处理任务,每个类别还提供了 0.6B/4B/8B 多参数版本。Qwen3 Embedding
前言
前两天阿里通义实验室重磅开源了 Qwen3-Embedding 系列模型,不仅提供了文本嵌入 Embedding 模型,还提供了重排 Reranker 模型。作为千问家族的最新成员,这个系列在 MMTEB、MTEB 及 MTEB-Code 三大权威评测中全面达到 SOTA 性能,并且支持多达 119 种语言处理任务,每个类别还提供了 0.6B/4B/8B 多参数版本。Qwen3 Embedding 系列模型目前已经在 HuggingFace 和 ModelScope 开源,并支持阿里云百炼平台 API 一键调用,可高效赋能智能搜索系统、跨语言RAG应用、多语言聊天助手、代码语义检索等 AI 核心应用场景。

Qwen3 Embedding 系列模型发布后,全球技术爱好者迅速跟进,推上Xenova 还放了一个Qwen3-Embedding 可视化Demo:
https://huggingface.co/spaces/webml-community/qwen3-embedding-webgpu

嵌入模型(将文本转化为稠密向量)和重排模型(对检索结果进行精细化排序)是大模型时代信息检索、RAG 和 Agent 系统的核心技术。以我比较熟悉的Qanything的架构为例:

它采用的是**“初筛+精排”两阶段架构**:
- 初筛阶段:嵌入模型(Embedding)快速扫描海量数据,锁定潜在相关结果
- 精排阶段:重排模型(Reranker)对候选结果深度分析,优化排序精度
为何需要两阶段?随着知识库不断增大,单靠嵌入模型检索会出现明显问题:
- 📉 精度衰减:数据量越大,检索结果相关性越不稳定(如图绿线所示)
- ⚖️ 排序失准:粗筛难以区分相似内容的细微差异
加入重排模块后实现关键突破:
-
🔍 精度补偿:精排阶段修正初筛误差
-
📈 规模增益:知识库越庞大,系统整体准确率越高(真正实现“数据越多,效果越好”)

Qwen3 Embedding 和 Reranker 系列模型都很能打,我已经准备尝试在RAG系统中替换这两大模块了,以下我们来看看Qwen3 Embedding系列模型的核心亮点。
🚀 性能登顶:多语言嵌入模型的全球新王者
- MTEB 多语言榜单全球第一:Qwen3-Embedding-8B 以 70.58 分登顶(截至2025.6.5)
- 代码检索碾压优势:MTEB-Code 基准得分 80.68(较 Gemini 提升 8.1%)
- 轻量化突破:0.6B 模型在中文 CMTEB 任务上也达 64.33 分,越级超过gte-Qwen2-7B-instruct-7B 模型


🔧 训练策略和****关键创新点
1. 多阶段训练流程
| 阶段 | 嵌入模型 | 重排序模型 |
|---|---|---|
| 弱监督预训练 | 1.5亿合成数据对 | 跳过 |
| 监督微调 | 700万标注数据 + 1200万精选合成数据 | 高质量标注数据 |
| 模型合并 | 球面线性插值 | 球面线性插值 |
2. 关键创新点
-
LLM驱动的数据合成
-
- 使用 Qwen3-32B 生成 1.5亿 多任务、多语言文本对。
- 通过角色扮演(从Persona Hub选角色)和多维控制(任务类型、语言、长度、难度)提升数据多样性和真实性。
- 示例:为文档生成“PhD难度+角色+总结型问题”的查询。
-
高质量数据筛选
用余弦相似度 >0.7 过滤合成数据,得到1200万高质量子集用于SFT。
-
模型合并技术
合并训练过程中多个检查点,显著提升模型鲁棒性和泛化能力(消融实验显示性能提升1.77分)。
🧩 灵活架构:按需定制,适配全场景
Qwen3-Embedding 系列不是“一刀切”的解决方案。它提供从 0.6B 到 8B 的 3 种参数规模,满足从边缘设备到大型云服务的不同部署需求:
- 表征维度自定义:用户可根据实际场景调整嵌入维度,显著节省存储和计算成本;
- 指令适配优化:支持自定义指令模板,提升特定任务、语言或场景下的表现;
- 模块化组合:开发者可灵活组合嵌入(Embedding)与重排(Reranker)模块,轻松实现功能扩展。

🌐 语言无界:100+ 语言支持,实现真正跨语言理解
Qwen3-Embedding 系列支持 119 种语言和方言,涵盖全球主流自然语言及多种编程语言(如Python、Java、C++等)。它不仅具备强大的多语言理解能力,更拥有跨语言语义对齐能力,真正实现:
- 多语言文档的语义统一表达
- 跨语言检索与问答
- 多语言知识图谱构建
- 混合代码与文本的联合搜索
无论用户来自欧洲、亚洲、非洲还是美洲,Qwen3-Embedding 都能无缝处理其语言数据,助力企业构建真正“全球化”的智能应用。
🔬 实测 Qwen3-Embedding & Qwen3-Reranker
说了这么多,我还想上手体验一下开源的Qwen3 Embedding系列模型,用的是千问官方Github上的例子:
https://github.com/QwenLM/Qwen3-Embedding
用的是最小的0.6B模型,简单修改了一下代码,这样可以直接从ModelScope上下载模型并运行。
这是修改后的 qwen3_embedding_transformers.py 代码:
import osfrom typing import Dict, Optional, List, Unionimport torchfrom torch import nnimport torch.nn.functional as Ffrom torch import Tensorfrom modelscope.hub.snapshot_download import snapshot_downloadfrom transformers import AutoTokenizer, AutoModelfrom transformers.utils import is_flash_attn_2_availableimport numpy as npfrom collections import defaultdict
class Qwen3Embedding(): def __init__(self, model_name_or_path, instruction=None, use_fp16: bool = True, use_cuda: bool = True, max_length=8192): if instruction is None: instruction = 'Given a web search query, retrieve relevant passages that answer the query' self.instruction = instruction if is_flash_attn_2_available() and use_cuda: self.model = AutoModel.from_pretrained(model_name_or_path, trust_remote_code=True, attn_implementation="flash_attention_2", torch_dtype=torch.float16) else: self.model = AutoModel.from_pretrained(model_name_or_path, trust_remote_code=True, torch_dtype=torch.float16) if use_cuda: self.model = self.model.cuda() self.tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, trust_remote_code=True, padding_side='left') self.max_length=max_length def last_token_pool(self, last_hidden_states: Tensor, attention_mask: Tensor) -> Tensor: left_padding = (attention_mask[:, -1].sum() == attention_mask.shape[0]) if left_padding: return last_hidden_states[:, -1] else: sequence_lengths = attention_mask.sum(dim=1) - 1 batch_size = last_hidden_states.shape[0] return last_hidden_states[torch.arange(batch_size, device=last_hidden_states.device), sequence_lengths] def get_detailed_instruct(self, task_description: str, query: str) -> str: if task_description is None: task_description = self.instruction return f'Instruct: {task_description}\nQuery:{query}' def encode(self, sentences: Union[List[str], str], is_query: bool = False, instruction=None, dim: int = -1): if isinstance(sentences, str): sentences = [sentences] if is_query: sentences = [self.get_detailed_instruct(instruction, sent) for sent in sentences] inputs = self.tokenizer(sentences, padding=True, truncation=True, max_length=self.max_length, return_tensors='pt') inputs.to(self.model.device) model_outputs = self.model(**inputs) output = self.last_token_pool(model_outputs.last_hidden_state, inputs['attention_mask']) if dim != -1: output = output[:, :dim] output = F.normalize(output, p=2, dim=1) return output
if __name__ == "__main__": model_id = "Qwen/Qwen3-Embedding-0.6B" model_path = snapshot_download(model_id) model = Qwen3Embedding(model_path) queries = ['What is the capital of China?', 'Explain gravity'] documents = [ "The capital of China is Beijing.", "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." ] query_outputs = model.encode(queries, is_query=True) doc_outputs = model.encode(documents) print('query outputs', query_outputs) print('doc outputs', doc_outputs) scores = (query_outputs @ doc_outputs.T) * 100 print(scores.tolist())
运行后结果如下:

这是 qwen3_reranker_transformers.py 代码,修改逻辑如上:
import logging
from typing import Dict, Optional, List
import os
import json
import logging
import os
import queue
import sys
from collections import defaultdict
from contextlib import nullcontext
from dataclasses import dataclass, field
from pathlib import Path
from tqdm import tqdm
from typing import Union, List, Tuple, Any
import numpy as np
import torch
from torch import Tensor, nn
from modelscope.hub.snapshot_download import snapshot_download
import torch.nn.functional as F
from torch.utils.data._utils.worker import ManagerWatchdog
from tqdm import tqdm
from transformers import AutoTokenizer, AutoModelForCausalLM, AutoModelForSequenceClassification, AutoModel, is_torch_npu_available
logger = logging.getLogger(__name__)
class Qwen3Reranker: def __init__( self, model_name_or_path: str, max_length: int = 4096, instruction=None, attn_type='causal', ) -> None: n_gpu = torch.cuda.device_count() self.max_length=max_length self.tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, trust_remote_code=True, padding_side='left') self.lm = AutoModelForCausalLM.from_pretrained(model_name_or_path).cuda().eval() #self.lm = AutoModelForCausalLM.from_pretrained(model_name_or_path, trust_remote_code=True, torch_dtype=torch.float16, attn_implementation="flash_attention_2").cuda().eval() self.token_false_id = self.tokenizer.convert_tokens_to_ids("no") self.token_true_id = self.tokenizer.convert_tokens_to_ids("yes") self.prefix = "<|im_start|>system\nJudge whether the Document meets the requirements based on the Query and the Instruct provided. Note that the answer can only be \"yes\" or \"no\".<|im_end|>\n<|im_start|>user\n" self.suffix = "<|im_end|>\n<|im_start|>assistant\n<think>\n\n</think>\n\n" self.prefix_tokens = self.tokenizer.encode(self.prefix, add_special_tokens=False) self.suffix_tokens = self.tokenizer.encode(self.suffix, add_special_tokens=False) self.instruction = instruction if self.instruction is None: self.instruction = "Given the user query, retrieval the relevant passages" def format_instruction(self, instruction, query, doc): if instruction is None: instruction = self.instruction output = "<Instruct>: {instruction}\n<Query>: {query}\n<Document>: {doc}".format(instruction=instruction,query=query, doc=doc) return output def process_inputs(self, pairs): out = self.tokenizer( pairs, padding=False, truncation='longest_first', return_attention_mask=False, max_length=self.max_length - len(self.prefix_tokens) - len(self.suffix_tokens) ) for i, ele in enumerate(out['input_ids']): out['input_ids'][i] = self.prefix_tokens + ele + self.suffix_tokens out = self.tokenizer.pad(out, padding=True, return_tensors="pt", max_length=self.max_length) for key in out: out[key] = out[key].to(self.lm.device) return out @torch.no_grad() def compute_logits(self, inputs, **kwargs): batch_scores = self.lm(**inputs).logits[:, -1, :] true_vector = batch_scores[:, self.token_true_id] false_vector = batch_scores[:, self.token_false_id] batch_scores = torch.stack([false_vector, true_vector], dim=1) batch_scores = torch.nn.functional.log_softmax(batch_scores, dim=1) scores = batch_scores[:, 1].exp().tolist() return scores def compute_scores( self, pairs, instruction=None, **kwargs ): pairs = [self.format_instruction(instruction, query, doc) for query, doc in pairs] inputs = self.process_inputs(pairs) scores = self.compute_logits(inputs) return scores
if __name__ == '__main__': model_id = "Qwen/Qwen3-Reranker-0.6B" model_path = snapshot_download(model_id) model = Qwen3Reranker(model_name_or_path=model_path, instruction="Retrieval document that can answer user's query", max_length=2048) queries = ['What is the capital of China?', 'Explain gravity'] documents = [ "The capital of China is Beijing.", "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." ] pairs = list(zip(queries, documents)) instruction="Given the user query, retrieval the relevant passages" new_scores = model.compute_scores(pairs, instruction) print('scores', new_scores)
运行结果如下:
scores [0.998421311378479, 0.9987399578094482]
写在最后
Qwen3 Embedding 系列模型发布后,由于 Embedding 和 Reranker 模型的 SOTA 性能、出色的泛化能力、灵活的架构配置和超多语言的支持,技术社区最大的呼声就是赶紧支持和适配其他知名开源框架,以应用于相关业务:


最后
为什么要学AI大模型
当下,⼈⼯智能市场迎来了爆发期,并逐渐进⼊以⼈⼯通⽤智能(AGI)为主导的新时代。企业纷纷官宣“ AI+ ”战略,为新兴技术⼈才创造丰富的就业机会,⼈才缺⼝将达 400 万!
DeepSeek问世以来,生成式AI和大模型技术爆发式增长,让很多岗位重新成了炙手可热的新星,岗位薪资远超很多后端岗位,在程序员中稳居前列。

与此同时AI与各行各业深度融合,飞速发展,成为炙手可热的新风口,企业非常需要了解AI、懂AI、会用AI的员工,纷纷开出高薪招聘AI大模型相关岗位。
最近很多程序员朋友都已经学习或者准备学习 AI 大模型,后台也经常会有小伙伴咨询学习路线和学习资料,我特别拜托北京清华大学学士和美国加州理工学院博士学位的鲁为民老师给大家这里给大家准备了一份涵盖了AI大模型入门学习思维导图、精品AI大模型学习书籍手册、视频教程、实战学习等录播视频 全系列的学习资料,这些学习资料不仅深入浅出,而且非常实用,让大家系统而高效地掌握AI大模型的各个知识点。
这份完整版的大模型 AI 学习资料已经上传CSDN,朋友们如果需要可以微信扫描下方CSDN官方认证二维码免费领取【保证100%免费】
AI大模型系统学习路线
在面对AI大模型开发领域的复杂与深入,精准学习显得尤为重要。一份系统的技术路线图,不仅能够帮助开发者清晰地了解从入门到精通所需掌握的知识点,还能提供一条高效、有序的学习路径。

但知道是一回事,做又是另一回事,初学者最常遇到的问题主要是理论知识缺乏、资源和工具的限制、模型理解和调试的复杂性,在这基础上,找到高质量的学习资源,不浪费时间、不走弯路,又是重中之重。
AI大模型入门到实战的视频教程+项目包
看视频学习是一种高效、直观、灵活且富有吸引力的学习方式,可以更直观地展示过程,能有效提升学习兴趣和理解力,是现在获取知识的重要途径

光学理论是没用的,要学会跟着一起敲,要动手实操,才能将自己的所学运用到实际当中去,这时候可以搞点实战案例来学习。
海量AI大模型必读的经典书籍(PDF)
阅读AI大模型经典书籍可以帮助读者提高技术水平,开拓视野,掌握核心技术,提高解决问题的能力,同时也可以借鉴他人的经验。对于想要深入学习AI大模型开发的读者来说,阅读经典书籍是非常有必要的。
600+AI大模型报告(实时更新)
这套包含640份报告的合集,涵盖了AI大模型的理论研究、技术实现、行业应用等多个方面。无论您是科研人员、工程师,还是对AI大模型感兴趣的爱好者,这套报告合集都将为您提供宝贵的信息和启示。
AI大模型面试真题+答案解析
我们学习AI大模型必然是想找到高薪的工作,下面这些面试题都是总结当前最新、最热、最高频的面试题,并且每道题都有详细的答案,面试前刷完这套面试题资料,小小offer,不在话下

这份完整版的大模型 AI 学习资料已经上传CSDN,朋友们如果需要可以微信扫描下方CSDN官方认证二维码免费领取【保证100%免费】

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。
更多推荐




所有评论(0)