---
title: bge-small-zh-v1.5-onnx
canonical_url: "https://www.modelscope.cn/models/lyf219/bge-small-zh-v1.5-onnx"
md_url: "https://www.modelscope.cn/models/lyf219/bge-small-zh-v1.5-onnx.md"
repository: lyf219/bge-small-zh-v1.5-onnx
chinese_name: bge-small-zh-v1.5-onnx
last_updated: 2026-10-02
pipeline_tag: sentence-embedding
tasks:
  - sentence-embedding
model_type:
  - bert
architectures:
  - BertModel
downloads: 2
stars: 0
---

# bge-small-zh-v1.5-onnx

> bge-small-zh-v1.5-onnx - lyf219 在 ModelScope 开源的模型。bge-small-zh-v1.5 (ONNX)

- **Repository**: lyf219/bge-small-zh-v1.5-onnx
- **Tasks**: sentence-embedding
- **Downloads**: 2
- **Stars**: 0
- **Last updated**: 2026-10-02

Source: https://www.modelscope.cn/models/lyf219/bge-small-zh-v1.5-onnx

---

# bge-small-zh-v1.5 (ONNX)

**BAAI/bge-small-zh-v1.5** 的 ONNX Runtime 格式再分发，由 **RAG Local Light** 项目转换发布（[项目主页](https://gitee.com/liuyanfu001/raglocal)）。

- 原模型：`BAAI/bge-small-zh-v1.5`（Hugging Face / ModelScope）
- 转换工具：`optimum-cli export onnx`，FP32 精度，**同权重同精度**，与官方 PyTorch 版输出完全一致（实测余弦 1.0、检索 top5 100% 重合）
- License：MIT（可免费商用，版权归 BAAI / FlagEmbedding）

## 规格

| 项目 | 值 |
|---|---|
| 输出维度 | 512 |
| 最大输入 token | 512 |
| 语言 | 中文（中英均可） |
| 池化方式 | CLS |
| 归一化 | L2 Normalize |
| 模型文件 | bge-small-zh-v1.5.onnx（90MB） |

## 使用

**Query 检索必须加指令前缀**（否则相关性分布偏差）：

```
为这个句子生成表示以用于检索相关文章：{query}
```

**文档入库不加指令**，直接编码原文。

示例（Python + onnxruntime）：

```python
from tokenizers import Tokenizer
import onnxruntime as ort
import numpy as np

tok = Tokenizer.from_file("tokenizer.json")
sess = ort.InferenceSession("bge-small-zh-v1.5.onnx", providers=["CPUExecutionProvider"])

def embed(texts, is_query=False):
    if is_query:
        texts = ["为这个句子生成表示以用于检索相关文章：" + t for t in texts]
    enc = tok.encode_batch(texts)
    pad = tok.token_to_id("<pad>") or 0
    max_len = max(len(e.ids) for e in enc)
    ids = np.array([e.ids + [pad] * (max_len - len(e.ids)) for e in enc], dtype=np.int64)
    mask = np.array([[1] * len(e.ids) + [0] * (max_len - len(e.ids)) for e in enc], dtype=np.int64)
    out = sess.run(None, {"input_ids": ids, "attention_mask": mask,
                          "token_type_ids": np.zeros_like(ids)})[0]
    vec = out[:, 0, :]
    return vec / np.linalg.norm(vec, axis=1, keepdims=True)
```

## 文件清单

```
config.json                模型配置
bge-small-zh-v1.5.onnx     ONNX 权重（90MB）
tokenizer.json             tokenizer（HuggingFace 格式）
vocab.txt                  词表
special_tokens_map.json    特殊 token 映射
tokenizer_config.json      tokenizer 配置
```

## 引用

```
@misc{bge_embedding,
  title={C-Pack: Packaged Resources To Advance General Chinese Embedding},
  author={Shitao Xiao and Zheng Liu and Peitian Zhang and Niklas Muennighoff},
  year={2023}, eprint={2309.07597}, archivePrefix={arXiv}, primaryClass={cs.CL}}
```
