Lychee-embed is the latest generalist text embedding model based on the Qwen2.5 model. It is suitable for text retrieval (semantic correlation), text similarity and other downstream tasks, and supports multiple languages of Qwen2.5.
Lychee-embed is jointly developed by the NLP Team of Harbin Institute of Technology, Shenzhen and is built based on an innovative multi-stage training framework (warm-up, task-learning, model merging, annealing).
The first batch of open source is 1.5B parameter version.
The multi-stage training framework
Lychee-embed:
Model Type: Text Embedding
Language Support: 100+ Languages
Param Size: 1.5B
Context Length: 8k
Embedding Dim: 1536, Supports diverse settings with 32 steps from 32 to 1536
MRL Support indicates whether the embedding model supports custom dimensions for the final embedding.
Instruction Aware notes whether the embedding or reranking model supports customizing the input instruction according to different tasks.
Like most embedding models, for most downstream tasks, using instructions (instruct) typically yields an improvement of 1% to 5% compared to not using them. Therefore, we recommend that developers create tailored instructions specific to their tasks and scenarios. In multilingual contexts, we also advise users to write their instructions in English, as most instructions utilized during the model training process were originally written in English.
Model Usage
📌 Tips: We recommend that developers customize the instruct according to their specific scenarios, tasks, and languages. Our tests have shown that in most retrieval scenarios, not using an instruct on the query side can lead to a drop in retrieval performance by approximately 1% to 5%.
Sentence Transformers Usage
python
1# Requires transformers>=4.51.02# Requires sentence-transformers>=2.7.034from sentence_transformers import SentenceTransformer
56# Load the model7model = SentenceTransformer("vec-ai/lychee-embed")89# We recommend enabling flash_attention_2 for better acceleration and memory saving,10# together with setting `padding_side` to "left":11# model = SentenceTransformer(12# "vec-ai/lychee-embed",13# model_kwargs={"attn_implementation": "flash_attention_2", "device_map": "auto"},14# tokenizer_kwargs={"padding_side": "left"},15# )1617# The queries and documents to embed18queries =[19"What is the capital of China?",20"Explain gravity",21]22documents =[23"The capital of China is Beijing.",24"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.",25]2627# Encode the queries and documents. Note that queries benefit from using a prompt28# Here we use the prompt called "query" stored under `model.prompts`, but you can29# also pass your own prompt via the `prompt` argument30query_embeddings = model.encode(queries, prompt_name="query")31document_embeddings = model.encode(documents)3233# Compute the (cosine) similarity between the query and document embeddings34similarity = model.similarity(query_embeddings, document_embeddings)35print(similarity)36# tensor([[0.8952, 0.4001],37# [0.4668, 0.8334]])
Transformers Usage
python
1# Requires transformers>=4.51.023import torch
4from transformers import AutoTokenizer, AutoModel
567deflast_token_pool(last_hidden_states: torch.Tensor,8 attention_mask: torch.Tensor)-> torch.Tensor:9 left_padding =(attention_mask[:,-1].sum()== attention_mask.shape[0])10if left_padding:11return last_hidden_states[:,-1]12else:13 sequence_lengths = attention_mask.sum(dim=1)-114 batch_size = last_hidden_states.shape[0]15return last_hidden_states[torch.arange(batch_size, device=last_hidden_states.device), sequence_lengths]161718defget_detailed_instruct(task_description:str, query:str)->str:19returnf'Instruct: {task_description}\nQuery:{query}'2021# Each query must come with a one-sentence instruction that describes the task22task ='Given a web search query, retrieve relevant passages that answer the query'2324queries =[25 get_detailed_instruct(task,'What is the capital of China?'),26 get_detailed_instruct(task,'Explain gravity')27]28# No need to add instruction for retrieval documents29documents =[30"The capital of China is Beijing.",31"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."32]33input_texts = queries + documents
3435tokenizer = AutoTokenizer.from_pretrained('vec-ai/lychee-embed', padding_side='left')36model = AutoModel.from_pretrained('vec-ai/lychee-embed')3738# We recommend enabling flash_attention_2 for better acceleration and memory saving.39# model = AutoModel.from_pretrained('vec-ai/lychee-embed', attn_implementation="flash_attention_2", torch_dtype=torch.float16).cuda()4041max_length =81924243# Tokenize the input texts44batch_dict = tokenizer(45 input_texts,46 padding=True,47 truncation=True,48 max_length=max_length,49 return_tensors="pt",50)51batch_dict.to(model.device)52outputs = model(**batch_dict)53embeddings = last_token_pool(outputs.last_hidden_state, batch_dict['attention_mask'])5455# normalize embeddings56embeddings = torch.nn.functional.normalize(embeddings, p=2, dim=1)57scores =(embeddings[:2] @ embeddings[2:].T)58print(scores.tolist())59# [[0.8952088952064514, 0.40010833740234375], [0.4668009877204895, 0.8333653807640076]]
vLLM Usage
python
1# Requires vllm>=0.8.52import torch
3from vllm import LLM
45defget_detailed_instruct(task_description:str, query:str)->str:6returnf'Instruct: {task_description}\nQuery:{query}'78# Each query must come with a one-sentence instruction that describes the task9task ='Given a web search query, retrieve relevant passages that answer the query'1011queries =[12 get_detailed_instruct(task,'What is the capital of China?'),13 get_detailed_instruct(task,'Explain gravity')14]15# No need to add instruction for retrieval documents16documents =[17"The capital of China is Beijing.",18"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."19]20input_texts = queries + documents
2122model = LLM(model="vec-ai/lychee-embed", task="embed")2324outputs = model.embed(input_texts)25embeddings = torch.tensor([o.outputs.embedding for o in outputs])26scores =(embeddings[:2] @ embeddings[2:].T)27print(scores.tolist())28# [[0.9007290601730347, 0.4043760895729065], [0.469818651676178, 0.8317853212356567]]
If you find our work helpful, feel free to give us a cite.
@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}
}