jina-code-embeddings
Collection
high quality code embeddings trained from code generation models β’ 7 items β’ Updated
β’ 13
MLX port of Jina AI's code embedding model for Apple Silicon.
pip install mlx tokenizers huggingface_hub
import mlx.core as mx
from tokenizers import Tokenizer
from model import JinaCodeEmbeddingModel
import json
# Load config
with open("config.json") as f:
config = json.load(f)
# Load model
model = JinaCodeEmbeddingModel(config)
weights = mx.load("model.safetensors")
model.load_weights(list(weights.items()))
mx.eval(model.parameters())
# Load tokenizer
tokenizer = Tokenizer.from_file("tokenizer.json")
# Encode a natural language query for code search
query_embeddings = model.encode(
["print hello world in python"],
tokenizer,
task="nl2code",
prompt_type="query",
)
# Encode code passages
code_embeddings = model.encode(
["print('Hello World!')"],
tokenizer,
task="nl2code",
prompt_type="passage",
)
mx.eval(query_embeddings, code_embeddings)
Each task uses specific prefixes for queries and passages:
| Task | Query Prefix | Passage Prefix |
|---|---|---|
| nl2code | Find the most relevant code snippet given the following query: | Candidate code snippet: |
| qa | Find the most relevant answer given the following question: | Candidate answer: |
| code2code | Find an equivalent code snippet given the following code snippet: | Candidate code snippet: |
| code2nl | Find the most relevant comment given the following code snippet: | Candidate comment: |
| code2completion | Find the most relevant completion given the following start of code snippet: | Candidate completion: |
Supports Matryoshka embedding truncation to: 64, 128, 256, 512, 896
embeddings = model.encode(texts, tokenizer, task="nl2code", prompt_type="query", truncate_dim=256)
jina-code-embeddings-0.5b-mlx/
βββ model.safetensors # Model weights (float16)
βββ model.py # Model implementation
βββ config.json # Model configuration
βββ tokenizer.json # Tokenizer
βββ tokenizer_config.json
βββ vocab.json
βββ merges.txt
βββ README.md
@misc{kryvosheieva2025efficientcodeembeddingscode,
title={Efficient Code Embeddings from Code Generation Models},
author={Daria Kryvosheieva and Saba Sturua and Michael G\"unther and Scott Martens and Han Xiao},
year={2025},
eprint={2508.21290},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2508.21290},
}
CC BY-NC 4.0
Quantized
Base model
Qwen/Qwen2.5-0.5B