Downloads · 30 days
3.8K
4% of all-time downloads
KaLM-Embedding/KaLM-embedding-multilingual-mini-instruct-v2.5
KaLM-embedding-multilingual-mini-instruct-v2.5 is a feature extraction model from KaLM-Embedding. Use it when you need embeddings to search or compare text. It is set up for sentence-transformers. The card lists the license as apache-2.0.
<img src="imgs/logo.jpg" width="800"/ <p -- <h1 align="center"KaLM-Embedding-V2.5</h1
Downloads · 30 days
3.8K
4% of all-time downloads
All-time downloads
91.9K
Public
Parameters
494M
2 GB on disk
Likes
68
Public
Click a slice to open those files.
.safetensors2 GB · 99%
From the Hugging Face model README
KaLM-Embedding-V2.5 is a versatile and compact embedding model, which achieves SOTA performance among models of comparable size and competes with models 3–26x larger by leveraging superior training techniques and data.


Additionally, focal-style sample reweighting and online hard-negative mixing are employed to emphasize difficult samples and enrich hard negatives.





Since we have used the Qwen2 model, we advise you to install transformers>=4.37.0, or you might encounter the following error:
KeyError: 'qwen2'
Using this model becomes easy when you have sentence-transformers installed:
pip install -U sentence-transformers
Then you can use the model like this:
from sentence_transformers import SentenceTransformer
import torch
model = SentenceTransformer(
"KaLM-Embedding/KaLM-embedding-multilingual-mini-instruct-v2.5",
trust_remote_code=True,
model_kwargs={
"torch_dtype": torch.bfloat16,
"attn_implementation": "flash_attention_2", # Optional
},
)
model.max_seq_length = 512
sentences = ["This is an example sentence", "Each sentence is converted"]
embeddings = model.encode(
sentences,
normalize_embeddings=True,
batch_size=256,
show_progress_bar=True,
)
print(embeddings)
'''
[[-0.01043701 -0.02172852 0.0100708 ... -0.02807617 0.00157166
-0.03637695]
[-0.00424194 0.02966309 0.03686523 ... -0.02587891 0.01953125
-0.00125122]]
'''
We add task instructions for asymmetric tasks: retrieval, reranking, classification, and clustering. And, we add task instructions for both queries and passages in symmetric tasks, including STS and pair classification. If you want to add task instructions to the query, you can use the model like this:
from sentence_transformers import SentenceTransformer
import torch
model = SentenceTransformer(
"KaLM-Embedding/KaLM-embedding-multilingual-mini-instruct-v2.5",
trust_remote_code=True,
model_kwargs={
"torch_dtype": torch.bfloat16,
"attn_implementation": "flash_attention_2", # Optional
},
)
model.max_seq_length = 512
sentences = ["This is an example sentence", "Each sentence is converted"]
prompt = "Instruct: Classifying the category of french news.\nQuery:"
embeddings = model.encode(
sentences,
prompt=prompt,
normalize_embeddings=True,
batch_size=256,
show_progress_bar=True,
)
print(embeddings)
'''
[[-0.01867676 0.02319336 0.00280762 ... -0.02075195 0.00196838
-0.0703125 ]
[-0.0067749 0.03491211 0.01434326 ... -0.0043335 0.00509644
-0.04174805]]
'''
Or you can use encode_query and encode_document to automatically add the default prompt for queries ("Instruct: Given a query, retrieve documents that answer the query \n Query: ") and documents (""), respectively.
from sentence_transformers import SentenceTransformer
import torch
model = SentenceTransformer(
"KaLM-Embedding/KaLM-embedding-multilingual-mini-instruct-v2.5",
trust_remote_code=True,
model_kwargs={
"torch_dtype": torch.bfloat16,
"attn_implementation": "flash_attention_2", # Optional
},
)
model.max_seq_length = 512
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.",
]
query_embeddings = model.encode_query(queries)
document_embeddings = model.encode_document(documents)
similarities = model.similarity(query_embeddings, document_embeddings)
print(similarities)
'''
tensor([[0.9034, 0.2563],
[0.3153, 0.7396]])
'''
pip install -U vllm==0.8.5
import torch
import vllm
from vllm import LLM
def get_detailed_instruct(task_description: str, query: str) -> str:
return f'Instruct: {task_description}\nQuery:{query}'
task = 'Given a query, retrieve documents that answer the query'
queries = [
get_detailed_instruct(task, 'What is the capital of China?'),
get_detailed_instruct(task, '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."
]
input_texts = queries + documents
model = LLM(model="{MODEL_NAME_OR_PATH}", task="embed", trust_remote_code=True, dtype="float16")
outputs = model.embed(input_texts)
embeddings = torch.tensor([o.outputs.embedding for o in outputs])
scores = (embeddings[:2] @ embeddings[2:].T)
print(scores.tolist())
If you find this model useful, please consider giving a star and citation.
@inproceedings{
zhao2026kalmembeddingv2,
title={Ka{LM}-Embedding-V2: Superior Training Techniques and Data Inspire A Versatile Embedding Model},
author={Xinping Zhao and Xinshuo Hu and Zifei Shan and Shouzheng Huang and Yao Zhou and Xin Zhang and Zetian Sun and zhenyu liu and Dongfang Li and Xinyuan Wei and Youcheng Pan and Yang Xiang and Meishan Zhang and Haofen Wang and Jun Yu and Baotian Hu and Min Zhang},
booktitle={The Fourteenth International Conference on Learning Representations},
year={2026},
url={https://openreview.net/forum?id=Y7qzhvWhcz}
}
@misc{hu2025kalmembedding,
title={KaLM-Embedding: Superior Training Data Brings A Stronger Embedding Model},
author={Xinshuo Hu and Zifei Shan and Xinping Zhao and Zetian Sun and Zhenyu Liu and Dongfang Li and Shaolin Ye and Xinyuan Wei and Qian Chen and Baotian Hu and Haofen Wang and Jun Yu and Min Zhang},
year={2025},
eprint={2501.01028},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2501.01028},
}
If you encounter any issue, feel free to contact us via the email: [email protected], [email protected]