Embedding开源模型重磅玩家:北京智源人工智能研究院最新Embedding模型发布!登顶MTEB,免费商用授权!
Embedding模型作为大语言模型(Large Language Model,LLM)的一个重要辅助,是很多LLM应用必不可少的部分。但是,现实中开源的Emebdding模型却很少。最近,北京智源人工智能研究院(BAAI)开源了BGE系列Embedding模型,不仅在MTEB排行榜中登顶冠军,还是免费商用授权的大模型,支持中文,应该可以满足相当多人的需要。

Embedding模型的重要性
Embedding模型,简单来说,是一种能够将词、短语或整个句子转化为向量形式的技术。这些向量能够捕捉到语义的丰富含义,使计算机可以像处理数字一样来处理文本。在大语言模型时代,Embedding模型可以帮助大模型处理更长的上下文,也可以将大模型与私有数据结合。
关于Embedding的具体介绍和其重要性参考:AI大模型领域的热门技术——Embedding入门介绍以及为什么Embedding在大语言模型中很重要,这里就不再赘述。
但是,尽管开源的LLM很多,强大的embedding模型却很少,尤其是支持中文的可商用的开源embedding模型更少。而此次BAAI发布的BGE系列Embedding模型则是一个天大的好消息!
BGE系列Embedding模型介绍和训练细节
BGE全称是BAAI General Embedding,即北京智源人工智能研究院通用Embedding模型,它可以将任意文本映射到低维的稠密向量。本次发布的BGE系列包含7个版本,其中4个是中文优化的Embedding模型,3个是英文的Embedding模型。
BGE模型的训练有2个阶段:分别是预训练阶段和微调阶段。
在预训练阶段,BGE模型通过使用RetroMAE方法在中英文数据集上进行了预训练。其中英文数据集维Pile、维基百科和msmarco,而中文数据集则来自于wudao。训练使用了24个A100(40G)。
wudao数据集:https://www.datalearner.com/blog/1051648084659749
在微调阶段,BGE使用三元组数据(query, positive, negative)进行微调。使用了48个A100(40G)的资源。目前,该数据没有开源,不过官方宣称未来将开源。
BGE系列模型如下:
BGE系列模型名称 | 预训练文件大小 | 输入长度 | 输出维度 | 是否中文优化 | DataLearner模型地址 |
---|---|---|---|---|---|
bge-large-zh | 1.3GB | / | 1024 | ✅ | https://www.datalearner.com/ai-models/pretrained-models/bge-large-zh |
bge-large-zh-noinstruct | 1.3GB | / | 1024 | ✅ | https://www.datalearner.com/ai-models/pretrained-models/bge-large-zh-noinstruct |
bge-base-zh | 409MB | / | 768 | ✅ | https://www.datalearner.com/ai-models/pretrained-models/bge-base-zh |
bge-small-zh | 95.8MB | / | 512 | ✅ | https://www.datalearner.com/ai-models/pretrained-models/bge-small-zh |
bge-large-en | 1.34GB | 512 | 1024 | ❌ | https://www.datalearner.com/ai-models/pretrained-models/bge-large-en |
bge-base-en | 438MB | 512 | 1024 | ❌ | https://www.datalearner.com/ai-models/pretrained-models/bge-base-en |
bge-small-en | 134MB | 512 | 1024 | ❌ | https://www.datalearner.com/ai-models/pretrained-models/bge-small-en |
BGE系列Embedding模型的效果
目前,Embedding领域的评测比较有影响力范围覆盖较全的是HuggingFace的MTEB排行榜。MTEB全称Massive Text Embedding Benchmark,收集了97个Embedding模型的数据,在74个数据集上评测结果。不过这个排行榜的评测只支持英文。
在MTEB目前的排行榜中,排名前2的就是BGE的两个英文模型,分别是bge-large-en和bge-base-en。

而中文的embedding评测目前缺少足够有权威的排行榜。因此,BAAI自己也发布了一个关于Embedding模型的评测数据,称为C-MTEB,这里的C就是Chinese了。在这个榜单中,目前覆盖了10个模型的评测结果:
Model | Embedding dimension | Avg | Retrieval | STS | PairClassification | Classification | Reranking | Clustering |
---|---|---|---|---|---|---|---|---|
bge-large-zh | 1024 | 64.20 | 71.53 | 53.23 | 78.94 | 72.26 | 65.11 | 48.39 |
bge-large-zh-noinstruct | 1024 | 63.53 | 70.55 | 50.98 | 76.77 | 72.49 | 64.91 | 50.01 |
BAAI/bge-base-zh | 768 | 62.96 | 69.53 | 52.05 | 77.5 | 70.98 | 64.91 | 47.63 |
BAAI/bge-small-zh | 512 | 58.27 | 63.07 | 46.87 | 70.35 | 67.78 | 61.48 | 45.09 |
m3e-base | 768 | 57.10 | 56.91 | 48.15 | 63.99 | 70.28 | 59.34 | 47.68 |
m3e-large | 1024 | 57.05 | 54.75 | 48.64 | 64.3 | 71.22 | 59.66 | 48.88 |
text-embedding-ada-002(OpenAI) | 1536 | 53.02 | 52.0 | 40.61 | 69.56 | 67.38 | 54.28 | 45.68 |
luotuo | 1024 | 49.37 | 44.4 | 39.41 | 66.62 | 65.29 | 49.25 | 44.39 |
text2vec | 768 | 47.63 | 38.79 | 41.71 | 67.41 | 65.18 | 49.45 | 37.66 |
text2vec-large | 1024 | 47.36 | 41.94 | 41.98 | 70.86 | 63.42 | 49.16 | 30.02 |
可以看到,BGE的模型效果也都是很好的。
BGE系列Embedding模型的使用
BGE模型支持BAAI自己的FlagEmbedding框架,也支持HuggingFace的Sentence-Transformers框架,使用很简单。这里给出Sentence-Transformers框架使用方法:
from sentence_transformers import SentenceTransformer
sentences = ["样例数据-1", "样例数据-2"]
model = SentenceTransformer('BAAI/bge-large-zh')
embeddings_1 = model.encode(sentences, normalize_embeddings=True)
embeddings_2 = model.encode(sentences, normalize_embeddings=True)
smilarity = embeddings_1 @ embeddings_2.T
print(smilarity)
需要注意的是,如果你用BGE来做检索任务,那么需要对每一个查询增加一条指令,如下所示:
from langchain.embeddings import HuggingFaceInstructEmbeddings
encode_kwargs = {'normalize_embeddings': True}
model = HuggingFaceInstructEmbeddings(
model_name='BAAI/bge-large-en',
embed_instruction="",
query_instruction="Represent this sentence for searching relevant passages: ",
encode_kwargs=encode_kwargs
)
BGE系列的Embedding模型的总结
BGE系列模型在MTEB榜单霸榜之后就引起了很多人的关注。对于我们来说,BGE最大的好处是支持中文,且商用免费授权,是中文embedding模型中为数不多的优质选择。而它英文榜单霸榜也引起了很多人的使用,推特上也十分火爆。
不过,BGE一个问题是它的输入序列只有512,这在很多场景下可能不够用。而OpenAI的text-embedding-ada-002最高支持8K的序列长度。不过,在开源领域,512的序列长度输入是主流的输入长度了。MTEB榜单前20名中,除了OpenAI的模型支持8K序列输入,其它模型都是只支持512序列输入。
关于BGE的开源地址、模型权重下载地址等,请参考DataLearner的Embedding模型列表:
https://www.datalearner.com/ai-models/pretrained-models?&aiArea=1005&language=-1&contextLength=-1&openSource=-1&publisher=-1

欢迎大家关注DataLearner官方微信,接受最新的AI技术推送
