Model reference · open weights
SFR-Embedding-Code-400M_R is an open-weight embedding model from Salesforce. AxForge deploys and operates it for you on dedicated EU-owned hardware — with the licence handled where one is required.
Available as managed deployment — configured and operated for you on dedicated EU hardware, quoted per deployment.
What it is
| Maker | Salesforce |
|---|---|
| Type | Embedding models |
| Task | Embeddings |
| Parameters (lead) | 434M |
| Context | 8k tokens |
| Runs with | sentence-transformers |
| Released | 2025-01-16 |
| Popularity | 7k downloads / month |
| Licence | Commercial licence needed |
About
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!
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.
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.
| Model | Model Size | CoIR AVG (NDCG@10) |
|---|---|---|
| SFR-Embedding-Code | 2B | 67.4 |
| CodeSage-Large-v2 | 1.3B | 64.2 |
| CodeSage-Large | 1.3B | 61.0 |
| SFR-Embedding-Code | 400M | 61.9 |
| CodeRankEmbed | 137M | 60.1 |
| CodeSage-Base | 356M | 57.5 |
| Voyage-Code-002 | - | 56.3 |
| CodeSage-Small | 130M | 54.4 |
SFR-Embedding Team († indicates co-leaders)
import torch.nn.functional as F
from transformers import AutoModel, AutoTokenizer
input_texts = [
"how to implement quick sort in Python?",
"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",
]
model_path = 'Salesforce/SFR-Embedding-Code-400M_R'
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModel.from_pretrained(model_path, trust_remote_code=True)
# Tokenize the input texts
batch_dict = tokenizer(input_texts, max_length=8192, padding=True, truncation=True, return_tensors='pt')
outputs = model(**batch_dict)
embeddings = outputs.last_hidden_state[:, 0]
# normalize embeddings
embeddings = F.normalize(embeddings, p=2, dim=1)
scores = (embeddings[:1] @ embeddings[1:].T) * 100
print("Similarity Scores:", scores.tolist())
# Similarity Scores: [[74.84745025634766, 65.39266967773438]]
from sentence_transformers import SentenceTransformer
from sentence_transformers.util import cos_sim
sentences = [
"how to implement quick sort in Python?",
"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",
]
model = SentenceTransformer('Salesforce/SFR-Embedding-Code-400M_R', trust_remote_code=True)
embeddings = model.encode(sentences)
similarities = cos_sim(embeddings[0], embeddings[1:])
print(similarities)
# tensor([[0.7485, 0.6539]])
@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}
}
From the published model card. Full card on the HuggingFace links in the sidebar.
Using it via the API
Once AxForge deploys sfr-embedding-code-400m-r for you, it answers on the OpenAI-compatible API — the same base URL and keys as every other model. (sfr-embedding-code-400m-r below is illustrative; you get the exact model name on deployment.)
$ curl -sS https://api.axforge.ai/v1/embeddings \
-H "Authorization: Bearer $AXFORGE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"sfr-embedding-code-400m-r","input":"text to embed"}'
Create an account — your API key is available in the console. 5M tokens/month currently included with every new account at launch.