---
title: lychee-embed
canonical_url: "https://www.modelscope.cn/models/vec-ai/lychee-embed"
md_url: "https://www.modelscope.cn/models/vec-ai/lychee-embed.md"
repository: vec-ai/lychee-embed
chinese_name: "立知-文本向量模型"
last_updated: 2025-08-18
license: "Apache License 2.0"
pipeline_tag: sentence-embedding
tasks:
  - sentence-embedding
model_type:
  - qwen2
architectures:
  - Qwen2Model
base_model:
  - Qwen/Qwen2.5-1.5B
base_model_relation: finetune
parameters: 1.5B
tensor_type:
  - BF16
library_name:
  - pytorch
  - transformer
  - safetensors
frameworks:
  - Pytorch
domain:
  - nlp
inference_backends:
  - "deploy_task emb/text"
  - "vllm 0.9.2"
downloads: 67
stars: 0
---

# lychee-embed

> lychee-embed - vec-ai 在 ModelScope 开源的模型。立知文本向量模型 Lychee-embed

vec-ai/lychee-embed 是 ModelScope 魔搭社区上的 1.5B 参数sentence-embedding模型，采用 Apache License 2.0 许可，基于 Qwen/Qwen2.5-1.5B 构建，可用 deploy_task emb/text、vllm 0.9.2 部署。

- **Repository**: vec-ai/lychee-embed
- **License**: Apache License 2.0
- **Tasks**: sentence-embedding
- **Parameters**: 1.5B
- **Base model**: Qwen/Qwen2.5-1.5B
- **Inference backends**: deploy_task emb/text, vllm 0.9.2
- **Downloads**: 67
- **Stars**: 0
- **Last updated**: 2025-08-18

Source: https://www.modelscope.cn/models/vec-ai/lychee-embed

---

[Github](https://github.com/vec-ai/lychee-embed) | [Paper](https://openreview.net/pdf?id=NC6G1KCxlt)

# 立知文本向量模型 Lychee-embed

立知文本向量模型 (`Lychee-embed`) 是基于 `Qwen2.5` 基础模型开发的最新通用文本向量模型，适用于文本检索（语义相关性）、文本相似性等多种下游任务，支持 `Qwen2.5` 的多种语言。立知文本向量模型由哈工大深圳自然语言处理团队联合开发，基于创新的多阶段训练框架（预热、任务学习、合并、退火）构建，首批开源 1.5B 参数版本。

![多阶段训练框架](framework-crop.png)


**Lychee-embed** 立知文本向量模型:

- 模型类别: Text Embedding
- 语言支持: 100+ Languages
- 参数大小: 1.5B
- 上下文窗口: 8k
- 向量维度大小: 最高 1536, 支持从 32 到 1536 以 32 为步长的多种设置
- 参数精度: BF16

更多细节请查阅[论文]()。


### 模型列表

| Model Type       | Models               | Size | Layers | Sequence Length | Embedding Dimension | MRL Support | Instruction Aware |
|------------------|----------------------|------|--------|-----------------|---------------------|-------------|----------------|
| Text Embedding   | [lychee-embed](https://modelscope.cn/models/vec-ai/lychee-embed) | 1.5B | 28     | 8K             | 1636                | Yes         | Yes            |
| Text Reranking   | [lychee-rerank](https://modelscope.cn/models/vec-ai/lychee-rerank) | 1.5B | 28     | 8K             | -                   | -           | Yes            |


> **注意**:
> - `MRL Support` 表示嵌入模型是否支持自定义最终嵌入的维度。 
> - `Instruction Aware` 表示嵌入或重排序模型是否支持根据不同的任务定制输入指令。
> - 我们的评估表明，对于大多数下游任务，使用指令（instruct）通常比不使用它们能提高1%到5%的性能。因此，我们建议开发者为他们的任务和场景创建定制化的指令。在多语言环境中，我们也建议用户用英语编写指令，因为模型训练过程中使用的大多数指令最初都是用英语编写的。


## 使用方法

📌 **提示**: 我们建议开发者根据特定场景、任务和语言定制`instruct`。我们的测试表明，在大多数检索场景中，不在`query`侧使用`instruct`会导致检索性能下降约1%至5%。


### Sentence Transformers Usage

```python
# Requires transformers>=4.51.0
# Requires sentence-transformers>=2.7.0

from sentence_transformers import SentenceTransformer

# Load the model
model = SentenceTransformer("vec-ai/lychee-embed")

# We recommend enabling flash_attention_2 for better acceleration and memory saving,
# together with setting `padding_side` to "left":
# model = SentenceTransformer(
#     "vec-ai/lychee-embed",
#     model_kwargs={"attn_implementation": "flash_attention_2", "device_map": "auto"},
#     tokenizer_kwargs={"padding_side": "left"},
# )

# The queries and documents to embed
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.",
]

# Encode the queries and documents. Note that queries benefit from using a prompt
# Here we use the prompt called "query" stored under `model.prompts`, but you can
# also pass your own prompt via the `prompt` argument
query_embeddings = model.encode(queries, prompt_name="query")
document_embeddings = model.encode(documents)

# Compute the (cosine) similarity between the query and document embeddings
similarity = model.similarity(query_embeddings, document_embeddings)
print(similarity)
# tensor([[0.8952, 0.4001],
#         [0.4668, 0.8334]])
```

### Transformers Usage

```python
# Requires transformers>=4.51.0

import torch
from transformers import AutoTokenizer, AutoModel


def last_token_pool(last_hidden_states: torch.Tensor,
                 attention_mask: torch.Tensor) -> torch.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(task_description: str, query: str) -> str:
    return f'Instruct: {task_description}\nQuery:{query}'

# Each query must come with a one-sentence instruction that describes the task
task = 'Given a web search query, retrieve relevant passages that answer the query'

queries = [
    get_detailed_instruct(task, 'What is the capital of China?'),
    get_detailed_instruct(task, 'Explain gravity')
]
# No need to add instruction for retrieval documents
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."
]
input_texts = queries + documents

tokenizer = AutoTokenizer.from_pretrained('vec-ai/lychee-embed', padding_side='left')
model = AutoModel.from_pretrained('vec-ai/lychee-embed')

# We recommend enabling flash_attention_2 for better acceleration and memory saving.
# model = AutoModel.from_pretrained('vec-ai/lychee-embed', attn_implementation="flash_attention_2", torch_dtype=torch.float16).cuda()

max_length = 8192

# Tokenize the input texts
batch_dict = tokenizer(
    input_texts,
    padding=True,
    truncation=True,
    max_length=max_length,
    return_tensors="pt",
)
batch_dict.to(model.device)
outputs = model(**batch_dict)
embeddings = last_token_pool(outputs.last_hidden_state, batch_dict['attention_mask'])

# normalize embeddings
embeddings = torch.nn.functional.normalize(embeddings, p=2, dim=1)
scores = (embeddings[:2] @ embeddings[2:].T)
print(scores.tolist())
# [[0.8952088952064514, 0.40010833740234375], [0.4668009877204895, 0.8333653807640076]]
```

### vLLM Usage

```python
# Requires vllm>=0.8.5
import torch
from vllm import LLM

def get_detailed_instruct(task_description: str, query: str) -> str:
    return f'Instruct: {task_description}\nQuery:{query}'

# Each query must come with a one-sentence instruction that describes the task
task = 'Given a web search query, retrieve relevant passages that answer the query'

queries = [
    get_detailed_instruct(task, 'What is the capital of China?'),
    get_detailed_instruct(task, 'Explain gravity')
]
# No need to add instruction for retrieval documents
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."
]
input_texts = queries + documents

model = LLM(model="vec-ai/lychee-embed", task="embed")

outputs = model.embed(input_texts)
embeddings = torch.tensor([o.outputs.embedding for o in outputs])
scores = (embeddings[:2] @ embeddings[2:].T)
print(scores.tolist())
# [[0.9007290601730347, 0.4043760895729065], [0.469818651676178, 0.8317853212356567]]
```


## Evaluation

| Model | Param | MTEB | CMTEB | MMTEB | MLDR | MTEB-Code | ToolBench | FollowIR | BRIGHT |
|---|---|---|---|---|---|---|---|---|---|
| BGE-multilingual | 9.24B  | 69.88 | 68.44 | 61.25  | 49.10 | 62.04  | 63.65  | -2.13 | 17.68 |
| NV-Embed-v2  | 7.85B  | 72.31  | - | 56.25 | - | 63.74 | 50.54 | 1.04 | 19.28 |
| GritLM-7B | 7.24B  | 66.8 | - | 60.93 | - | 73.6 | 35.42 | 3.45 | 20.63 |
| E5-mistral    | 7.11B  | 66.6 | 59.92 | 60.28 | - | 69.2 | 31.79 | -0.62 | 17.54 |
| GTE-Qwen2-7B     | 7.62B  | 69.88 | 71.62 | 62.51 | 56.53 | 62.17 | 59.48 | 4.94 | 22.89 |
| GTE-Qwen2-1.5B   | 1.54B  | 67.19 | 67.12 | 59.47 | 52.11 | 61.98 | 62.57 | 0.74 | 18.47 |
| BGE-M3 (Dense)             | 0.56B  | 59.84 | 61.79 | 59.54 | 52.50 | 58.22  | 58.45 | -3.11 | 11.94 |
| Jina-v3                   | 0.57B  | 65.52 | 63.07 | 58.37 | 40.71 | 58.85 | 59.64 | -1.34 | 11.34 |
|Qwen3-Embedding-8B | 7.57B | | 73.84 | 70.58 | | 80.68 |
|Qwen3-Embedding-4B | 4.02B | | 72.27 | 69.45 | | 80.06 |
|Qwen3-Embedding-0.6B | 0.60B | | 66.33 | 64.33 | | 75.41 |
| **Lychee-embed** | 1.54B | 68.39 |69.77 | 58.43 | 53.85 | 72.54 | 86.35 | 5.74 | 19.47 |

更多细节请查阅[论文]()。

## Citation

如果您发现我们的工作有帮助，请考虑给我们一个引用。

```
@inproceedings{zhang2025phased,
title={Phased Training for LLM-powered Text Retrieval Models Beyond Data Scaling},
author={Xin Zhang and Yanzhao Zhang and Wen Xie and Dingkun Long and Mingxin Li and Pengjun Xie and Meishan Zhang and Wenjie Li and Min Zhang},
booktitle={Second Conference on Language Modeling},
year={2025},
url={https://openreview.net/forum?id=NC6G1KCxlt}
}
```

<!-- ### 当前模型的贡献者未提供更加详细的模型介绍。模型文件和权重，可浏览“模型文件”页面获取。
#### 您可以通过如下git clone命令，或者ModelScope SDK来下载模型

SDK下载
```bash
#安装ModelScope
pip install modelscope
```
```python
#SDK模型下载
from modelscope import snapshot_download
model_dir = snapshot_download('vec-ai/lychee-embed')
```
Git下载
```
#Git模型下载
git clone https://www.modelscope.cn/vec-ai/lychee-embed.git
```

<p style="color: lightgrey;">如果您是本模型的贡献者，我们邀请您根据<a href="https://modelscope.cn/docs/ModelScope%E6%A8%A1%E5%9E%8B%E6%8E%A5%E5%85%A5%E6%B5%81%E7%A8%8B%E6%A6%82%E8%A7%88" style="color: lightgrey; text-decoration: underline;">模型贡献文档</a>，及时完善模型卡片内容。</p> -->
