from sentence_transformers import SentenceTransformer
import torch
model = SentenceTransformer(
"tencent/KaLM-Embedding-Gemma3-12B-2511",
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(
"tencent/KaLM-Embedding-Gemma3-12B-2511",
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]])'''
Citation
If you find this model useful, please consider giving a star and citation.
@misc{zhao2025kalmembeddingv2,
title={KaLM-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},
year={2025},
eprint={2506.20923},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2506.20923},
}
@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},
}
KaLM-Embedding-Gemma3-12B-2511 huggingface.co is an AI model on huggingface.co that provides KaLM-Embedding-Gemma3-12B-2511's model effect (), which can be used instantly with this tencent KaLM-Embedding-Gemma3-12B-2511 model. huggingface.co supports a free trial of the KaLM-Embedding-Gemma3-12B-2511 model, and also provides paid use of the KaLM-Embedding-Gemma3-12B-2511. Support call KaLM-Embedding-Gemma3-12B-2511 model through api, including Node.js, Python, http.
KaLM-Embedding-Gemma3-12B-2511 huggingface.co is an online trial and call api platform, which integrates KaLM-Embedding-Gemma3-12B-2511's modeling effects, including api services, and provides a free online trial of KaLM-Embedding-Gemma3-12B-2511, you can try KaLM-Embedding-Gemma3-12B-2511 online for free by clicking the link below.
tencent KaLM-Embedding-Gemma3-12B-2511 online free url in huggingface.co:
KaLM-Embedding-Gemma3-12B-2511 is an open source model from GitHub that offers a free installation service, and any user can find KaLM-Embedding-Gemma3-12B-2511 on GitHub to install. At the same time, huggingface.co provides the effect of KaLM-Embedding-Gemma3-12B-2511 install, users can directly use KaLM-Embedding-Gemma3-12B-2511 installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
KaLM-Embedding-Gemma3-12B-2511 install url in huggingface.co: