说明文档
<h1 align="center">Snowflake 的 Arctic-embed-l-v2.0</h1> <h4 align="center"> <p> <a href=#news>新闻</a> | <a href=#models>模型</a> | <a href=#usage>使用</a> | <a href="#evaluation">评估</a> | <a href="#contact">联系方式</a> | <a href="#faq">常见问题</a> <a href="#license">许可证</a> | <a href="#acknowledgement">致谢</a> <p> </h4>
<img referrerpolicy="no-referrer-when-downgrade" src="https://static.scarf.sh/a.png?x-pxid=18f5b1a3-da66-4f25-92d3-21da829509c3" />
新闻
- 2024/12/11: 发布技术报告
- 2024/12/04: 发布 snowflake-arctic-embed-l-v2.0 和 snowflake-arctic-embed-m-v2.0,这是我们专门针对多语言工作负载设计的最新模型。
模型
Snowflake arctic-embed-l-v2.0 是 Snowflake 发布的最新嵌入模型套件,旨在优化检索性能和推理效率。 Arctic Embed 2.0 为多语言嵌入模型树立了新的标准,在保证英语性能的同时,实现了高质量的多语言文本检索。 Arctic Embed 2.0 基于宽松的 Apache 2.0 许可证发布,非常适合需要可靠、企业级大规模多语言搜索和检索的应用场景。
主要特点:
-
兼顾多语言:在英语和非英语检索方面表现出色,在 MTEB Retrieval、CLEF 和 MIRACL 等基准测试中优于领先的开源和专有模型。
-
推理效率高:其 303M 非嵌入参数推理速度快、效率高,可满足任何规模的需求。
-
易于压缩:通过 Matryoshka 表示学习 (MRL) 和量化感知嵌入训练,使用小至 128 字节/向量的嵌入即可实现高质量检索。请注意,与我们的 v1.5 模型一样,该模型的 MRL 为 256 维,高质量 128 字节压缩通过 4 位量化实现(例如使用
pq256x4fs快速扫描 FAISS 索引 或使用随 1.5 模型发布的示例代码)。 -
直接替换:arctic-embed-l-v2.0 基于 BAAI/bge-m3-retromae 构建,允许直接替换推理,可与任何新库、内核、推理引擎等配合使用。
-
长上下文支持:arctic-embed-l-v2.0 基于 BAAI/bge-m3-retromae 构建,通过使用 RoPE 可支持最高 8192 的上下文窗口。
质量基准
与大多数其他开源模型不同,Arctic-embed-l-v2.0 在英语(通过 MTEB Retrieval)和多语言(通过 MIRACL 和 CLEF)方面都表现出色。 您不再需要支持多种模型来赋能高质量的英语和多语言检索。以下所有数字均为所讨论数据集的平均 NDCG@10。
| 模型名称 | # 参数 | # 非嵌入参数 | # 维度 | BEIR (15) | MIRACL (4) | CLEF (Focused) | CLEF (Full) |
|---|---|---|---|---|---|---|---|
| snowflake-arctic-l-v2.0 | 568M | 303M | 1024 | 55.6 | 55.8 | 52.9 | 54.3 |
| snowflake-arctic-m | 109M | 86M | 768 | 54.9 | 24.9 | 34.4 | 29.1 |
| snowflake-arctic-l | 335M | 303M | 1024 | 56.0 | 34.8 | 38.2 | 33.7 |
| me5 base | 560M | 303M | 1024 | 51.4 | 54.0 | 43.0 | 34.6 |
| bge-m3 (BAAI) | 568M | 303M | 1024 | 48.8 | 56.8 | 40.8 | 41.3 |
| gte (Alibaba) | 305M | 113M | 768 | 51.1 | 52.3 | 47.7 | 53.1 |
除了高质量的检索能力外,arctic 生成的嵌入还易于压缩。利用 MRL 进行向量截断可将向量大小减少 4 倍,而质量下降不到 3%。 将 MRL 处理后的向量与向量压缩 (Int4) 结合,可实现每个文档 128 字节的检索能力。
| 模型 | BEIR (15) | 相对性能 | MIRACL (4) | 相对性能 | CLEF (5) | 相对性能 | CLEF (Full) | 相对性能 | |
|---|---|---|---|---|---|---|---|---|---|
| snowflake-arctic-l-v2.0 | 1024 | 55.6 | 不适用 | 55.8 | 不适用 | 52.9 | 不适用 | 54.3 | 不适用 |
| snowflake-arctic-l-v2.0 | 256 | 54.3 | -0.18% | 54.3 | -2.70% | 51.9 | -1.81% | 53.4 | -1.53% |
使用方法
使用 Sentence Transformers
from sentence_transformers import SentenceTransformer
# 加载模型
model_name = 'Snowflake/snowflake-arctic-embed-l-v2.0'
model = SentenceTransformer(model_name)
# 定义查询和文档
queries = ['what is snowflake?', 'Where can I get the best tacos?']
documents = ['The Data Cloud!', 'Mexico City of Course!']
# 计算嵌入:使用 `prompt_name="query"` 来编码查询!
query_embeddings = model.encode(queries, prompt_name="query")
document_embeddings = model.encode(documents)
# 计算余弦相似度分数
scores = model.similarity(query_embeddings, document_embeddings)
# 输出结果
for query, query_scores in zip(queries, scores):
doc_score_pairs = list(zip(documents, query_scores))
doc_score_pairs = sorted(doc_score_pairs, key=lambda x: x[1], reverse=True)
print("Query:", query)
for document, score in doc_score_pairs:
print(score, document)
使用 Huggingface Transformers
您可以使用 transformers 包来使用 Snowflake 的 arctic-embed 模型,如下所示。为了获得最佳检索质量,请使用 CLS token 对每个文本部分进行嵌入,并在查询上使用以下查询前缀(仅在查询上使用)。
import torch
from transformers import AutoModel, AutoTokenizer
model_name = 'Snowflake/snowflake-arctic-embed-l-v2.0'
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModel.from_pretrained(model_name, add_pooling_layer=False)
model.eval()
query_prefix = 'query: '
queries = ['what is snowflake?', 'Where can I get the best tacos?']
queries_with_prefix = ["{}{}".format(query_prefix, i) for i in queries]
query_tokens = tokenizer(queries_with_prefix, padding=True, truncation=True, return_tensors='pt', max_length=8192)
documents = ['The Data Cloud!', 'Mexico City of Course!']
document_tokens = tokenizer(documents, padding=True, truncation=True, return_tensors='pt', max_length=8192)
# 计算 token 嵌入
with torch.no_grad():
query_embeddings = model(**query_tokens)[0][:, 0]
document_embeddings = model(**document_tokens)[0][:, 0]
# 归一化嵌入
query_embeddings = torch.nn.functional.normalize(query_embeddings, p=2, dim=1)
document_embeddings = torch.nn.functional.normalize(document_embeddings, p=2, dim=1)
scores = torch.mm(query_embeddings, document_embeddings.transpose(0, 1))
for query, query_scores in zip(queries, scores):
doc_score_pairs = list(zip(documents, query_scores))
doc_score_pairs = sorted(doc_score_pairs, key=lambda x: x[1], reverse=True)
#输出段落和分数
print("Query:", query)
for document, score in doc_score_pairs:
print(score, document)
这将产生以下分数
Query: what is snowflake?
tensor(0.2715) The Data Cloud!
tensor(0.0661) Mexico City of Course!
Query: Where can I get the best tacos?
tensor(0.2797) Mexico City of Course!
tensor(0.1250) The Data Cloud!
使用 Huggingface Transformers.js
如果还没有安装,您可以使用以下命令从 NPM 安装 Transformers.js JavaScript 库:
npm i @huggingface/transformers
然后您可以按如下方式使用该模型进行检索:
import { pipeline, dot } from '@huggingface/transformers';
// 创建特征提取管道
const extractor = await pipeline('feature-extraction', 'Snowflake/snowflake-arctic-embed-m-v2.0', {
dtype: 'q8',
});
// 生成句子嵌入
const sentences = [
'query: what is snowflake?',
'The Data Cloud!',
'Mexico City of Course!',
]
const output = await extractor(sentences, { normalize: true, pooling: 'cls' });
// 计算相似度分数
const [source_embeddings, ...document_embeddings ] = output.tolist();
const similarities = document_embeddings.map(x => dot(source_embeddings, x));
console.log(similarities); // [0.24783534471401417, 0.05313122704326892]
联系方式
如果您对此项目有任何问题或建议,欢迎提交 issue 或 pull request。 您也可以发送电子邮件给 Daniel Campos(daniel.campos@snowflake.com)。
许可证
Arctic 基于 Apache-2 许可证授权。发布的模型可免费用于商业目的。
Snowflake/snowflake-arctic-embed-l-v2.0
作者 Snowflake
创建时间: 2024-11-08 16:55:31+00:00
更新时间: 2025-07-28 14:00:58+00:00
在 Hugging Face 上查看