blink-code-16M is a fast static embedding model for code retrieval by Minish: a single 62,500 × 256 token embedding table (16.0M parameters, 64MB in float32) with mean pooling. It supersedes potion-code-16M-v2: it's the same size and better on every benchmark we measured, improving CoIR from 40.67 to 46.82.
Static models are models without any active parameters; all model parameters are just embedding parameters. Because of this, they are many orders of magnitude faster than transformers. Although this comes at a cost, this cost is much lower than you would expect.
With model2vec:
from model2vec import StaticModel
model = StaticModel.from_pretrained("minishlab/blink-code-16M")
embeddings = model.encode(["read a json file in python", "def load(path):\n with open(path) as f:\n return json.load(f)"])
With model2vec-rs
use anyhow::Result;
use model2vec_rs::model::StaticModel;
fn main() -> Result<()> {
let model = StaticModel::from_pretrained(
"minishlab/blink-code-16M",
)?;
let sentences = vec![
"read a json file".to_string(),
"fn read_json(path: &str) -> Value".to_string(),
];
let embeddings = model.encode(&sentences);
println!("Generated {} embeddings.", embeddings.len());
Ok(())
}
With Sentence Transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("minishlab/blink-code-16M")
embeddings = model.encode(["read a json file in python", "def load(path):\n with open(path) as f:\n return json.load(f)"])
All scores are nDCG@10 from mteb 2.27.1.
CoIR is the standard code retrieval benchmark: 10 tasks covering text-to-code, code-to-code, code-to-text and code Q&A.
| Model | Mean | Apps | CodeSearchNet | CodeFeedbackMT | CodeFeedbackST | CodeSearchNetCC | CodeTransContest | CodeTransDL | CosQA | StackOverflow | Text2SQL |
|---|---|---|---|---|---|---|---|---|---|---|---|
| blink-code-16M | 46.82 | 6.08 | 53.59 | 51.72 | 65.87 | 51.42 | 57.31 | 38.34 | 24.34 | 64.03 | 55.45 |
| BM25 | 42.31 | 4.76 | 40.86 | 59.19 | 68.15 | 53.97 | 47.78 | 34.42 | 18.75 | 70.26 | 24.94 |
| potion-code-16M-v2 | 40.67 | 5.05 | 46.34 | 46.50 | 54.40 | 43.70 | 48.55 | 33.48 | 24.39 | 60.13 | 44.12 |
| potion-code-16M | 38.78 | 4.11 | 43.10 | 45.09 | 52.24 | 43.09 | 45.40 | 32.81 | 22.19 | 58.10 | 41.66 |
The potion-code models ship with a 512-token cap in their tokenizer, which mteb applies: potion-code-16M-v2's card reports 39.08 with it, against 40.67 here without it.
RTEB(Code) is the code part of the Retrieval Embedding Benchmark. None of it is in our training data.
We use the public English tasks. Apps is left out (it is in CoIR above) and Code1 is one of RTEB's private sets.
| Model | Mean | DS1000 | HumanEval | MBPP | WikiSQL | FreshStack | SWE-bench |
|---|---|---|---|---|---|---|---|
| blink-code-16M | 34.67 | 29.17 | 64.84 | 56.75 | 30.94 | 22.92 | 3.39 |
| BM25 | 29.90 | 41.45 | 38.47 | 11.64 | 52.16 | 27.89 | 7.76 |
| potion-code-16M-v2 | 29.21 | 20.83 | 55.31 | 51.53 | 22.96 | 21.14 | 3.50 |
| potion-code-16M | 27.34 | 20.14 | 49.95 | 47.03 | 22.54 | 21.55 | 2.83 |
CodeEditSearch retrieves a code change (a diff) from its commit message, 1,000 commits per language from CommitPackFT. Seven of the 13 languages (TypeScript, C, C++, Rust, Swift, Scala, Shell) are not in our training data.
| Model | Mean | Python | JS | TS | Go | Ruby | Java | PHP | C | C++ | Rust | Swift | Scala | Shell |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| blink-code-16M | 49.58 | 53.1 | 54.5 | 54.7 | 52.6 | 54.0 | 51.7 | 50.7 | 41.4 | 41.8 | 44.2 | 49.6 | 47.5 | 48.8 |
| potion-code-16M-v2 | 46.50 | 51.6 | 51.2 | 50.5 | 49.3 | 50.6 | 49.5 | 47.2 | 37.4 | 36.4 | 43.7 | 47.8 | 44.2 | 45.0 |
| potion-code-16M | 45.06 | 49.7 | 50.1 | 49.6 | 47.2 | 49.3 | 48.3 | 46.1 | 36.5 | 34.3 | 43.8 | 47.1 | 40.6 | 43.4 |
| BM25 | 44.39 | 48.7 | 47.8 | 47.9 | 48.2 | 48.9 | 41.3 | 41.3 | 35.0 | 37.9 | 44.0 | 39.3 | 44.6 | 52.0 |
Combining blink-code-16M and BM25 with hybrid search gives the following results. We take the top 100 documents from each, scale each query's scores to [0, 1] (min-max) and average them with equal weight.
| Model | CoIR | RTEB(Code) | CodeEditSearch |
|---|---|---|---|
| blink-code-16M + BM25 | 49.36 | 36.00 | 54.71 |
| blink-code-16M | 46.82 | 34.67 | 49.58 |
| BM25 | 42.31 | 29.90 | 44.39 |
The combination adds 2.54 points on CoIR, 1.33 on RTEB(Code) and 5.13 on CodeEditSearch over blink-code-16M alone.
We followed a four-step procedure, starting from potion-code-16M-v2's recipe.
We train a 62,500-token uncased WordPiece tokenizer on 1.2M queries and documents from CornStack (Go, Java, JavaScript, PHP, Python and Ruby) plus the 4.1M texts of the CoIR train splits. We then distill CodeRankEmbed into it with Model2Vec, reducing the dimensions to 256 with PCA and applying SIF weighting.
We then distill CodeRankEmbed into the model with Tokenlearn, on 1.2M CornStack documents and queries embedded by CodeRankEmbed.
We train with a contrastive loss (in-batch negatives plus one hard negative per pair) for 3 epochs, with batch size 4096, learning rate 0.05 and a cosine schedule, on 4.5M triplets from two datasets we built for this model:
Decontamination. CoIR's train and test splits share queries and documents, so we remove every triplet whose query is a CoIR test query, or whose document or negative is a relevant CoIR test document (matched after whitespace normalization). This removes 19,073 CoIR train pairs (0.9%) and 6 CornStack triplets. See the dataset cards for details.
The final model is 20% of the Tokenlearn model from step 2 and 80% of the contrastive model from step 3.
To show the effect of each step of our training process, this table shows how much each one adds on our benchmarks (in brackets: the change from the row above). Each row adds one thing to the row above it.
| Step | CoIR | RTEB(Code) | CodeEditSearch | semble |
|---|---|---|---|---|
| 1. Distill CodeRankEmbed | 32.61 | 25.09 | 35.72 | 0.559 |
| 2. + Our code tokenizer with an expanded vocabulary | 34.50 (+1.89) | 23.82 (-1.27) | 39.82 (+4.10) | 0.609 (+0.050) |
| 3. + Tokenlearn | 40.03 (+5.53) | 26.75 (+2.93) | 44.23 (+4.41) | 0.638 (+0.029) |
| 4. + Contrastive training on CornStack | 42.60 (+2.57) | 33.41 (+6.66) | 49.81 (+5.58) | 0.653 (+0.015) |
| 5. + CoIR train pairs | 45.92 (+3.32) | 34.60 (+1.19) | 49.58 (-0.23) | 0.642 (-0.011) |
| 6. + Hard negatives from CodeRankEmbed | 46.19 (+0.27) | 34.42 (-0.18) | 49.20 (-0.38) | 0.644 (+0.002) |
| 7. + Hard negatives re-mined with the step-6 model | 46.74 (+0.55) | 34.88 (+0.46) | 49.20 (0.00) | 0.643 (-0.001) |
| 8. + Weight averaging | 46.82 (+0.08) | 34.67 (-0.21) | 49.58 (+0.38) | 0.652 (+0.009) |
semble is our code search library; we run only its semantic benchmark, to show the isolated effect of the model. We don't include semble results for the other models because trained models all saturate around 0.65, but we include it here as a control task for the effect of each step.
Model2Vec was developed by the Minish team consisting of Stephan Tulkens and Thomas van Dongen.
Please cite the Model2Vec repository if you use this model in your work.
@software{minishlab2024model2vec,
author = {Stephan Tulkens and {van Dongen}, Thomas},
title = {Model2Vec: Fast State-of-the-Art Static Embeddings},
year = {2024},
publisher = {Zenodo},
doi = {10.5281/zenodo.17270888},
url = {https://github.com/MinishLab/model2vec},
license = {MIT}
}