alt.freeweights.embed / bge-code-v1
From: BAAI <huggingface.co/BAAI>Newsgroups: alt.freeweights.embedSubject:

bge-code-v1

Date: 2026-11-14Commit: bd67852Signed: 2DC28CC7B26A283B ✓

Sentence similarity model with 1.5B parameters. Safetensors weights, 6.19 GB in all. Published by BAAI under Apache-2.0.

1.5B params6.19GBbge-code-v1safetensorspermissive
FactsParams1.5BSize6.19 GBFormatssafetensorsTasksentence similarityLicenseApache-2.0From sourcepermissive
$ fw get BAAI/bge-code-v1
# manifest sha256 966009d37fd6… · 6.19 GB · 17 files
$ fw verify ./bge-code-v1 BAAI/bge-code-v1
From sourceHosted (signed)BAAI/bge-code-v1Last check: 2026-11-14 21:08 UTC

Get help: custom fine-tune or private deploy. We review your setup before we quote.

Works with

Evaluate with

Overview

Size
6.19 GB
Weights
6.17 GB (safetensors)
Parameters
1.5B
Formats
safetensors
Task
sentence similarity
License
Apache-2.0 (permissive)
Files
17, each with a sha256
Publisher
BAAI
Added
2026-11-14
Section
alt.freeweights.embed
Lineage

Original release from the publisher.

Where these bytes come from
Publisher at the pinned commit→You

Sources are tried in order. A file counts only when its size and sha256 match the manifest. Sources are checked when you ask for them, not on a timer.

Sources
BadgeHostLast checkResult
From sourcehuggingface.co2026-11-14 21:08 UTCpassed

Model card

From the publisher at commit bd67852. Shown as plain text with links; images open at the publisher.

FlagEmbedding#

For more details please refer to our Github: FlagEmbedding.

BGE-Code-v1 is an LLM-based code embedding model that supports code retrieval, text retrieval, and multilingual retrieval. It primarily demonstrates the following capabilities:

  • Superior Code Retrieval Performance: The model demonstrates exceptional code retrieval capabilities, supporting natural language queries in both English and Chinese, as well as 20 programming languages.
  • Robust Text Retrieval Capabilities: The model maintains strong text retrieval capabilities comparable to text embedding models of similar scale.
  • Extensive Multilingual Support: BGE-Code-v1 offers comprehensive multilingual retrieval capabilities, excelling in languages such as English, Chinese, Japanese, French, and more.

Usage#

Using FlagEmbedding#
git clone https://github.com/FlagOpen/FlagEmbedding.git
cd FlagEmbedding
pip install -e .
from FlagEmbedding import FlagLLMModel
queries = [
    "Delete the record with ID 4 from the 'Staff' table.", 
    'Delete all records in the "Livestock" table where age is greater than 5'
]
documents = [
    "DELETE FROM Staff WHERE StaffID = 4;",
    "DELETE FROM Livestock WHERE age > 5;"
]
model = FlagLLMModel('BAAI/bge-code-v1', 
                     query_instruction_format="<instruct>{}\n<query>{}",
                     query_instruction_for_retrieval="Given a question in text, retrieve SQL queries that are appropriate responses to the question.",
                     trust_remote_code=True,
                     use_fp16=True) # Setting use_fp16 to True speeds up computation with a slight performance degradation
embeddings_1 = model.encode_queries(queries)
embeddings_2 = model.encode_corpus(documents)
similarity = embeddings_1 @ embeddings_2.T
print(similarity)

By default, FlagLLMModel will use all available GPUs when encoding. Please set os.environ["CUDA_VISIBLE_DEVICES"] to select specific GPUs. You also can set os.environ["CUDA_VISIBLE_DEVICES"]="" to make all GPUs unavailable.

Using Sentence Transformers#
from sentence_transformers import SentenceTransformer
import torch

# Load the model, optionally in float16 precision for faster inference
model = SentenceTransformer(
    "BAAI/bge-code-v1",
    trust_remote_code=True,
    model_kwargs={"torch_dtype": torch.float16},
)

# Prepare a prompt given an instruction
instruction = 'Given a question in text, retrieve SQL queries that are appropriate responses to the question.'
prompt = f'<instruct>{instruction}\n<query>'
# Prepare queries and documents
queries = [
    "Delete the record with ID 4 from the 'Staff' table.", 
    'Delete all records in the "Livestock" table where age is greater than 5'
]
documents = [
    "DELETE FROM Staff WHERE StaffID = 4;",
    "DELETE FROM Livestock WHERE age > 5;"
]

# Compute the query and document embeddings
query_embeddings = model.encode(queries, prompt=prompt)
document_embeddings = model.encode(documents)

# Compute the cosine similarity between the query and document embeddings
similarities = model.similarity(query_embeddings, document_embeddings)
print(similarities)
Using HuggingFace Transformers#
import torch
import torch.nn.functional as F

from torch import Tensor
from transformers import AutoTokenizer, AutoModel


def last_token_pool(last_hidden_states: Tensor,
                 attention_mask: Tensor) -> Tensor:
    left_padding = (attention_mask[:, -1].sum() == attention_mask.shape[0])
    if left_padding:
        return last_hidden_states[:, -1]
    else:
        sequence_lengths = attention_mask.sum(dim=1) - 1
        batch_size = last_hidden_states.shape[0]
        return last_hidden_states[torch.arange(batch_size, device=last_hidden_states.device), sequence_lengths]


def get_detailed_instruct(task_description: str, query: str) -> str:
    return f'<instruct>{task_description}\n<query>{query}'


instruction = 'Given a question in text, retrieve SQL queries that are appropriate responses to the question.'
queries = [
    "Delete the record with ID 4 from the 'Staff' table.", 
    'Delete all records in the "Livestock" table where age is greater than 5'
]
documents = [
    "DELETE FROM Staff WHERE StaffID = 4;",
    "DELETE FROM Livestock WHERE age > 5;"
]
input_texts = queries + documents

tokenizer = AutoTokenizer.from_pretrained('BAAI/bge-code-v1', trust_remote_code=True)
model = AutoModel.from_pretrained('BAAI/bge-code-v1', trust_remote_code=True)
model.eval()

max_length = 4096
# Tokenize the input texts
batch_dict = tokenizer(input_texts, max_length=max_length, padding=True, truncation=True, return_tensors='pt', pad_to_multiple_of=8)

with torch.no_grad():
    outputs = model(**batch_dict)
    embeddings = last_token_pool(outputs.last_hidden_state, batch_dict['attention_mask'])
    
# normalize embeddings
embeddings = F.normalize(embeddings, p=2, dim=1)
scores = (embeddings[:2] @ embeddings[2:].T) * 100
print(scores.tolist())

Evaluation#

BGE-Code-v1 achieves state-of-the-art performance on both the CoIR and CodeRAG benchmarks.

  • CoIR
CodeXEmbed-2BCodeXEmbed-7BVoyage-Code-002Voyage-Code-003BGE-Code-v1
Apps76.8685.3826.5293.6298.08
CosQA40.4742.4729.7934.4546.72
Text2SQL78.4278.9469.2662.8764.35
CSN87.8789.6781.7989.3589.53
CSN-CCR97.6697.9573.4590.0598.30
CodeTrans-Contest90.3094.4572.7794.9694.38
CodeTrans-DL38.5740.4627.4838.5746.13
StackOverFlow-QA94.4796.3367.6897.1795.35
CodeFeedBack-ST86.3687.5365.3590.6790.56
CodeFeedBack-MT65.5168.8328.7493.5894.38
AVG75.6578.2056.2678.5381.77
  • CodedRAG
HummanEvalMBPPDS-1000ODEXRepoEvalSWE-bench-LiteAVG
SFR100.099.019.337.183.862.767.0
Jina-v2-code100.097.726.219.990.558.365.4
CodeXEmbed-2B100.097.425.423.988.752.464.6
Voyage-Code-002100.099.033.126.694.329.163.7
BGE-Code-v1100.099.240.936.193.167.472.8
Instructions for Evaluation#
{
    "Apps": "Given a code contest problem description, retrieve relevant code that can help solve the problem.",
    "CosQA": "Given a web search query, retrieve relevant code that can help answer the query.",
    "Text2SQL": "Given a question in text, retrieve SQL queries that are appropriate responses to the question.",
    "CSN": "Given a piece of code, retrieve the document string that summarizes the code.",
    "CSN-CCR": "Given a piece of code segment, retrieve the code segment that is the latter part of the code.",
    "CodeTrans-DL": "Given a piece of code, retrieve code that is semantically equivalent to the input code.",
    "CodeTrans-Contest": "Given a piece of Python code, retrieve C++ code that is semantically equivalent to the input code.",
    "StackOverFlow-QA": "Given a question that consists of a mix of text and code snippets, retrieve relevant answers that also consist of a mix of text and code snippets, and can help answer the question.",
    "CodeFeedBack-ST": "Given a question that consists of a mix of text and code snippets, retrieve relevant answers that also consist of a mix of text and code snippets, and can help answer the question.",
    "CodeFeedBack-MT": "Given a multi-turn conversation history that consists of a mix of text and code snippets, retrieve relevant answers that also consist of a mix of text and code snippets, and can help answer the question.",
    "HummanEval": "Given a question that consists of a mix of text and code snippets, retrieve relevant answers that also consist of a mix of text and code snippets, and can help answer the question.",
    "MBPP": "Given a textual explanation of code functionality, retrieve the corresponding code implementation.",
    "DS-1000": "Given a question that consists of a mix of text and code snippets, retrieve relevant answers that also consist of a mix of text and code snippets, and can help answer the question.",
    "ODEX": "Given a question, retrieve relevant answers that also consist of a mix of text and code snippets, and can help answer the question.",
    "RepoEval": "Given a piece of code segment, retrieve the code segment that is the latter part of the code.",
    "SWE-bench-Lite": "Given a code snippet containing a bug and a natural language description of the bug or error, retrieve code snippets that demonstrate solutions or fixes for similar bugs or errors (the desired documents)."
}

Citation#

If you find this repository useful, please consider giving a star :star: and citation

@misc{bge_code,
    title={Towards A Generalist Code Embedding Model Based On Massive Data Synthesis}, 
    author={Chaofan Li and Jianlyu Chen and Yingxia Shao and Defu Lian and Zheng Liu},
    year={2025},
    eprint={2505.12697},
    archivePrefix={arXiv},
    primaryClass={cs.IR},
    url={https://arxiv.org/abs/2505.12697}, 
}

Files

17 files · 6.19 GBWeights 6.17 GB (safetensors). Sizes and sha256 from the signed manifest.
Hide all 17 files with their sha256
FileSizesha256
.gitattributes1.57 KB34448b82c17d60fec9b65b1f093c115ddbaadc04beb1b0140b6bfed2e012a930
1_Pooling/config.json297 B40d120b92655c16390bd52c43540ada5f74ab94991d00838df6742c0d640d35b
README.md10.6 KB486da577912bb4157c4c9798207619201c013ca745f2adb53eb9e8574dc2b6cb
added_tokens.json650 B59122dc49ad6df74c3b16a679c55cfd7cdf23760b50a4d14171d66363c5d4899
config.json711 Bfa661128c559d1657bfc2a2467286d1e17b5f9eb36ffa01eac5a6ee6d99c1ed9
config_sentence_transformers.json205 B4eb845e9d24d1940a55a4c5cf6fae3221a478fd92929a07c2608840128ae45ab
merges.txt1.67 MB8831e4f1a044471340f7c0a83d7bd71306a5b867e95fd870f74d0c5308a904d5
model-00001-of-00002.safetensors5.00 GB3f0012a815833b137559c60485e3d087fb029e034b7b5e5c18fa9cabcc3faafc
model-00002-of-00002.safetensors1.18 GB93d0d51780cad746744bed246b4c13e520e458ba36509c33aff1ed0c9ac16d71
model.safetensors.index.json25.7 KB4042f7a1ef4bd421dbc6f7197451e3b2d7192f62e12cd9fd3dc51429bd6c89b1
modules.json349 B84e40c8e006c9b1d6c122e02cba9b02458120b5fb0c87b746c41e0207cf642cf
sentence_bert_config.json55 B1140b92d307aec9383d897169c9f489f3a568787b80bf760f5d7cc9d25169a65
special_tokens_map.json365 B540a4eb9f9b9fb06b7e601c5ef07ee66a647bacf00c659aa0275fb6ad645a0eb
tokenization_qwen.py10.9 KBe732e66a6c26d581076e85e09bec94ab4b2b4e7bd25eb672fc8d267bd78a5456
tokenizer.json11.4 MBa56524092f5d0676e63537511b535e73e7580a7efe440247ef3fa43d019a0af0
tokenizer_config.json7.56 KBdae4986efd0a0783e641f815f6ec139aaf671e225069e28e33af8b9de7f13e89
vocab.json2.78 MBca10d7e9fb3ed18575dd1e277a2579c16d108e32f27439684afa0e10b1440910
VersionsEach time the pinned upstream commit or file list changed in this repo. Newest first.
Upstream commitDateContents
bd67852057 pinned now manifest updated, same commit2026-11-14 21:08 UTC17 files · 6.19 GB
bd678520572026-11-14 21:08 UTC17 files · 6.19 GB

Use it

$ fw get BAAI/bge-code-v1
# manifest sha256 966009d37fd6… · 6.19 GB · 17 files
$ fw verify ./bge-code-v1 BAAI/bge-code-v1
fw.pyChecks the signature and every sha256, tries each source in order, resumes.
$ python3 fw.py get https://freeweights.allternit.com/manifests/BAAI/bge-code-v1.json --dir ./bge-code-v1 $ python3 fw.py verify ./bge-code-v1 ./BAAI__bge-code-v1.json
hfThe Hugging Face CLI with one setting. Same repo id.
$ HF_ENDPOINT=https://freeweights.allternit.com hf download BAAI/bge-code-v1 --revision bd67852057c5d7ddcc7b8234d9d6c410117ed851 --local-dir ./bge-code-v1
transformersLoad the weights in Python.
import os os.environ["HF_ENDPOINT"] = "https://freeweights.allternit.com" from transformers import AutoModel, AutoTokenizer tok = AutoTokenizer.from_pretrained("BAAI/bge-code-v1", revision="bd67852057c5d7ddcc7b8234d9d6c410117ed851") model = AutoModel.from_pretrained("BAAI/bge-code-v1", revision="bd67852057c5d7ddcc7b8234d9d6c410117ed851", device_map="auto")
sentence-transformersEmbed text with sentence-transformers.
import os os.environ["HF_ENDPOINT"] = "https://freeweights.allternit.com" from sentence_transformers import SentenceTransformer model = SentenceTransformer("BAAI/bge-code-v1", revision="bd67852057c5d7ddcc7b8234d9d6c410117ed851") vectors = model.encode(["Hello"])

License

Name
Apache License 2.0
Id
Apache-2.0
Class
Permissive
Redistribution
yes
Listing
Hosted (signed)
Decided
License as declared by the publisher. No person read it. 2026-11-14
Text in
README.md
Text sha256
486da577912bb4157c4c9798207619201c013ca745f2adb53eb9e8574dc2b6cb
Terms gate
No extra terms beyond the license.

Read the license text

Licenses are checked against the license table. A custom license passes only after a person reads it.

Provenance

From: BAAI <huggingface.co/BAAI>Newsgroups: alt.freeweights.embedSubject: bge-code-v1Date: 2026-11-14Commit: bd67852Signed: 2DC28CC7B26A283B ✓
Upstream
BAAI/bge-code-v1
Pinned commit
bd67852057c5d7ddcc7b8234d9d6c410117ed851
Manifest
bge-code-v1.json · .minisig
Manifest sha256
966009d37fd6bd88d4529ca101701b9c273aba74a517e9532599b0f052f6ea3b
Signature
minisign, Ed25519, key 2DC28CC7B26A283B
Created
2026-11-14 21:08 UTC
Generator
freeweights-manifest/0.1.0
Takedowns
None.

How to verify

$ curl -O https://freeweights.allternit.com/manifests/BAAI/bge-code-v1.json $ curl -O https://freeweights.allternit.com/manifests/BAAI/bge-code-v1.json.minisig $ minisign -Vm bge-code-v1.json -P RWQ7KGqyx4zCLXtUFOqvfv8L3g+8fpKJ1FsuxPyOYMF+4KufbUxKq1Oq $ shasum -a 256 <file> # compare with the Files tab

A manifest whose signature fails must be rejected. A file whose size or sha256 does not match must be discarded. Verify a download

Model tree

No related models in this catalog.Nothing here lists this model as its parent, and it names no parent.
Get it
Download
$ HF_ENDPOINT=https://freeweights.allternit.com hf download BAAI/bge-code-v1
Open in Freeweights Studio

Pull, verify and run it in the Allternit app on Desktop, web or phone.

Signed manifest
minisign, key 2DC28CC7B26A283B. bge-code-v1.json. Provenance. Takedown history: none.
From: sentence-transformers <huggingface.co/sentence-transformers>Subject: all-MiniLM-L6-v1
From: unsloth <huggingface.co/unsloth>Subject: all-MiniLM-L6-v2
From: mlx-community <huggingface.co/mlx-community>Subject: all-MiniLM-L6-v2-4bit
From: sentence-transformers <huggingface.co/sentence-transformers>Subject: all-mpnet-base-v1
From: sentence-transformers <huggingface.co/sentence-transformers>Subject: allenai-specter
From: sentence-transformers <huggingface.co/sentence-transformers>Subject: bert-base-nli-max-tokens