This model was converted to GGUF format from codefuse-ai/F2LLM-v2-4B using llama.cpp (release b10269). Refer to the original model card for more details on the model.
Original Model Card
F2LLM-v2-4B
F2LLM-v2 is a family of general-purpose, multilingual embedding models in 8 distinct sizes ranging from 80M to 14B. Trained on a curated composite of 60 million publicly available high-quality data, F2LLM-v2 supports more than 200 languages, with a particular emphasis on previously underserved mid- and low-resource languages.
F2LLM-v2 is fully open. We release base models in 5 sizes, instruct models in 8 sizes, the training data, the training code, and intermediate checkpoints. The three smallest instruct models are pruned and trained from the 0.6B base model.
1from sentence_transformers import SentenceTransformer
2model = SentenceTransformer("codefuse-ai/F2LLM-v2-4B", device="cuda:0", model_kwargs={"torch_dtype":"bfloat16"})3# Some sample query and documents4query ="What is F2LLM used for?"5documents =[6'We present F2LLM, a family of fully open embedding LLMs that achieve a strong balance between model size, training data, and embedding performance.',7'F2LLM is a model for computing text embeddings that can be used for various NLP tasks such as information retrieval, semantic search, and text classification.',8'F2LLM 是 CodeFuse 开源的系列嵌入模型。',9'F2LLM — это модель вычисления встраивания текста, которую можно использовать для различных задач НЛП, таких как поиск информации, семантический поиск и классификация текста.'10]11# Encode the query and documents separately. The encode_query method uses the query prompt12query_embedding = model.encode_query(query)13document_embeddings = model.encode_document(documents)14print(query_embedding.shape, document_embeddings.shape)15# (2560,) (4, 2560)16# Compute cosine similarity between the query and documents17similarity = model.similarity(query_embedding, document_embeddings)18print(similarity)19# tensor([[0.6348, 0.8547, 0.7168, 0.8356]])
1from transformers import AutoModel, AutoTokenizer
2import torch
3import torch.nn.functional as F
4model_path ="codefuse-ai/F2LLM-v2-4B"5tokenizer = AutoTokenizer.from_pretrained(model_path)6model = AutoModel.from_pretrained(model_path, torch_dtype=torch.bfloat16, device_map={'':0})7query ="What is F2LLM used for?"8query_prompt ="Instruct: Given a question, retrieve passages that can help answer the question.\nQuery: "9documents =[10'We present F2LLM, a family of fully open embedding LLMs that achieve a strong balance between model size, training data, and embedding performance.',11'F2LLM is a model for computing text embeddings that can be used for various NLP tasks such as information retrieval, semantic search, and text classification.',12'F2LLM 是 CodeFuse 开源的系列嵌入模型。',13'F2LLM — это модель вычисления встраивания текста, которую можно использовать для различных задач НЛП, таких как поиск информации, семантический поиск и классификация текста.'14]15defencode(sentences):16 batch_size =len(sentences)17# the tokenizer will automatically add eos token18 tokenized_inputs = tokenizer(sentences, padding=True, return_tensors='pt').to(model.device)19 last_hidden_state = model(**tokenized_inputs).last_hidden_state
20 eos_positions = tokenized_inputs.attention_mask.sum(dim=1)-121 embeddings = last_hidden_state[torch.arange(batch_size, device=model.device), eos_positions]22 embeddings = F.normalize(embeddings, p=2, dim=1)23return embeddings
24# Encode the query and documents25query_embedding = encode([query_prompt + query])26document_embeddings = encode(documents)27print(query_embedding.shape, document_embeddings.shape)28# torch.Size([1, 2560]) torch.Size([4, 2560])29# Compute cosine similarity between the query and documents30similarity = query_embedding @ document_embeddings.T
31print(similarity)32# tensor([[0.6328, 0.8555, 0.7148, 0.8398]], device='cuda:0',33# dtype=torch.bfloat16, grad_fn=<MmBackward0>)
Prompts
The model supports custom instructions in the following format:
text
1Instruct: your_instruction
2Query:
In general, for retrieval and reranking tasks:
use the prompt for queries
do not prepend the prompt to documents/passages
For symmetric tasks such as STS, clustering, and bitext mining, you can encode the documents either with or without prompts. The model is trained to support both scenarios.
Intermediate Checkpoints
To facilitate future research, we release intermediate checkpoints in the intermediate_checkpoints branch.
Citation
@misc{f2llm-v2,
title={F2LLM-v2: Inclusive, Performant, and Efficient Embeddings for a Multilingual World},
author={Ziyin Zhang and Zihan Liao and Hang Yu and Peng Di and Rui Wang},
year={2026},
eprint={2603.19223},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2603.19223},
}