Model reference · open weights

SFR-Embedding-Code-2B_R

Embeddings Salesforce Embeddings 1 build Non-commercial 2k dl/mo

SFR-Embedding-Code-2B_R is an open-weight embedding model from Salesforce. SFR-Embedding-Code-2B_R (BF16) weighs 5.2 GB; the smallest configuration that runs it is RTX 3060 12 GB.

For self-hosting, compare this build's requirements below with the GPU you plan to rent.

  • SFR-Embedding-Code-2B_R is a 2.6B parameter feature-extraction model developed by Salesforce for multilingual and multi-task code and text retrieval.
  • It supports a context length of 8192 tokens and is released under the cc-by-nc-4.0 license.
  • The model is a fine-tuned version of Gemma and is intended for research purposes only.

Summary of the Salesforce/SFR-Embedding-Code-2B_R model card, 2026-10-01

What it is

Released bySalesforce
Released2025-01-17
Parameters2.6B
VRAM5.2 GB for the weights

What it runs on

Memory and cards for SFR-Embedding-Code-2B_R (BF16)

5.2 GBweights, file size
1.1 GBruntime overhead
CardRunsMemory
RTX 3060 12 GBfits11.6 GB
RTX 4060 Ti 16 GBfits15.4 GB
RTX 3090 24 GBfits23.4 GB
RTX 4090 24 GBfits23.4 GB
RTX 5090 32 GBfits31.0 GB
L40S 48 GBfits44.0 GB
A100 80 GBfits78.2 GB
H100 80 GBfits78.1 GB
RTX PRO 6000 Blackwell 96 GBfits93.8 GB
DGX Spark (GB10) 128 GB unifiedfits107 GB
H200 141 GBfits138 GB
B200 180 GBfits176 GB

From the model card

What Salesforce says about SFR-Embedding-Code-2B_R

Read the model card

SFR-Embedding by Salesforce Research.

The Salesforce/SFR-Embedding-Code is a generalist embedding model family for multilingual and multi-task code and Text retrieval. It demonstrates superior performance compared to various open-source code embedding models across multiple code retrieval tasks.

Check out our paper for more details!

We also offer 400M-size model Salesforce/SFR-Embedding-Code-400_R

Ethical Considerations

This release is for research purposes only in support of an academic paper. Our models, datasets, and code are not specifically designed or evaluated for all downstream purposes. We strongly recommend users evaluate and address potential concerns related to accuracy, safety, and fairness before deploying this model. We encourage users to consider the common limitations of AI, comply with applicable laws, and leverage best practices when selecting use cases, particularly for high-risk scenarios where errors or misuse could significantly impact people’s lives, rights, or safety. For further guidance on use cases, refer to our AUP and AI AUP.

License Statement:

Users need to make their own assessment regarding any obligations or responsibilities under the corresponding licenses or terms and conditions pertaining to the original datasets and data. This release is for research purposes only in support of an academic paper.

This released model is a fine-tuned version of Gemma and Gemma is provided under and subject to the Gemma Terms of Use found at ai.google.dev/gemma/terms. Additionally, the use of this model is restricted as set forth in the Gemma Prohibited Use Policy at ai.google.dev/gemma/prohibited_use_policy ("Prohibited Use Policy"), which is hereby incorporated by reference into this Agreement.

Performance on CoIR Benchmark

ModelModel SizeCoIR AVG (NDCG@10)
SFR-Embedding-Code2B67.4
CodeSage-Large-v21.3B64.2
CodeSage-Large1.3B61.0
SFR-Embedding-Code400M61.9
CodeRankEmbed137M60.1
CodeSage-Base356M57.5
Voyage-Code-002-56.3
CodeSage-Small130M54.4

SFR-Embedding Team († indicates co-leaders)

  • Ye Liu
  • Rui Meng
  • Shafiq Rayhan Joty
  • Silvio Savarese
  • Caiming Xiong †
  • Yingbo Zhou †
  • Semih Yavuz †

How to run

Transformers
import torch.nn.functional as F
from transformers import AutoTokenizer, AutoModel

# Each query needs to be accompanied by an corresponding instruction describing the task.
query_instruction_example = "Given Code or Text, retrieval relevant content"
queries = [
    "how to implement quick sort in Python?"
]

# No instruction needed for retrieval passages
passages = [
    "def quick_sort(arr):\n    if len(arr)  pivot]\n    return quick_sort(left) + middle + quick_sort(right)",
    "def bubble_sort(arr):\n    n = len(arr)\n    for i in range(n):\n        for j in range(0, n-i-1):\n            if arr[j] > arr[j+1]:\n                arr[j], arr[j+1] = arr[j+1], arr[j]\n    return arr"
]

# load model with tokenizer
model = AutoModel.from_pretrained('Salesforce/SFR-Embedding-Code-2B_R', trust_remote_code=True)

# get the embeddings
max_length = 32768
query_embeddings = model.encode_queries(queries, instruction=query_instruction_example, max_length=max_length)
passage_embeddings = model.encode_corpus(passages, max_length=max_length)

# normalize embeddings
query_embeddings = F.normalize(query_embeddings, p=2, dim=1)
passage_embeddings = F.normalize(passage_embeddings, p=2, dim=1)

scores = (query_embeddings @ passage_embeddings.T) * 100
print(scores.tolist())
# [[69.26929473876953, 58.41606903076172]]
Sentence Transformers
from sentence_transformers import SentenceTransformer

# Each query needs to be accompanied by an corresponding instruction describing the task.
query_instruction_example = "Instruct: Given Code or Text, retrieval relevant content\nQuery: "
queries = ["how to implement quick sort in Python?"]

# No instruction needed for retrieval passages
passages = [
    "def quick_sort(arr):\n    if len(arr)  pivot]\n    return quick_sort(left) + middle + quick_sort(right)",
    "def bubble_sort(arr):\n    n = len(arr)\n    for i in range(n):\n        for j in range(0, n-i-1):\n            if arr[j] > arr[j+1]:\n                arr[j], arr[j+1] = arr[j+1], arr[j]\n    return arr"
]

# Load the Sentence Transformer model, including pooling
model = SentenceTransformer('Salesforce/SFR-Embedding-Code-2B_R', trust_remote_code=True)

# Compute the embeddings for both queries and passages. Use 'prompt' for queries only
query_embeddings = model.encode(queries, prompt=query_instruction_example)
passage_embeddings = model.encode(passages)

# Compute the similarities between the queries and passages
similarities = model.similarity(query_embeddings, passage_embeddings)
print(similarities)
# tensor([[0.6927, 0.5842]])

Citation

@article{liu2024codexembed,
  title={CodeXEmbed: A Generalist Embedding Model Family for Multiligual and Multi-task Code Retrieval},
  author={Liu, Ye and Meng, Rui and Jot, Shafiq and Savarese, Silvio and Xiong, Caiming and Zhou, Yingbo and Yavuz, Semih},
  journal={arXiv preprint arXiv:2411.12644},
  year={2024}
}

Quoted from the model card on Hugging Face. The full card is behind the Hugging Face link above.

© 2026 AxForge · EU-hosted AI infrastructure Pricing Docs Trust Privacy Terms