Jina Code Embeddings: A Small but Performant Code Embedding Model
Intended Usage & Model Info
jina-code-embeddings
is an embedding model for code retrieval.
The model supports various types of code retrieval (text-to-code, code-to-code, code-to-text, code-to-completion) and technical question answering across 15+ programming languages.
Multilingual support
(15+ programming languages) and compatibility with a wide range of domains, including web development, software development, machine learning, data science, and educational coding problems.
Task-specific instruction prefixes
for NL2Code, Code2Code, Code2NL, Code2Completion, and Technical QA, which can be selected at inference time.
Flexible embedding size
: dense embeddings are 896-dimensional by default but can be truncated to as low as 64 with minimal performance loss.
import torch
import torch.nn.functional as F
from vllm import LLM
INSTRUCTION_CONFIG = {
"nl2code": {
"query": "Find the most relevant code snippet given the following query:\n",
"passage": "Candidate code snippet:\n"
},
"qa": {
"query": "Find the most relevant answer given the following question:\n",
"passage": "Candidate answer:\n"
},
"code2code": {
"query": "Find an equivalent code snippet given the following code snippet:\n",
"passage": "Candidate code snippet:\n"
},
"code2nl": {
"query": "Find the most relevant comment given the following code snippet:\n",
"passage": "Candidate comment:\n"
},
"code2completion": {
"query": "Find the most relevant completion given the following start of code snippet:\n",
"passage": "Candidate completion:\n"
}
}
defadd_instruction(instruction, text):
returnf"{instruction}{text}"defcosine_similarity(x, y):
x = F.normalize(x, p=2, dim=1)
y = F.normalize(y, p=2, dim=1)
return x @ y.T
# Build the queries and documents
queries = [
add_instruction(INSTRUCTION_CONFIG["nl2code"]["query"], "print hello world in python"),
add_instruction(INSTRUCTION_CONFIG["nl2code"]["query"], "initialize array of 5 zeros in c++"),
]
documents = [
add_instruction(INSTRUCTION_CONFIG["nl2code"]["passage"], "print('Hello World!')"),
add_instruction(INSTRUCTION_CONFIG["nl2code"]["passage"], "int arr[5] = {0, 0, 0, 0, 0};"),
]
all_inputs = queries + documents
# vLLM embedding model
llm = LLM(
model="jinaai/jina-code-embeddings-0.5b",
task="embed"
)
# Encode with vLLM
outputs = llm.encode(all_inputs)
# Collect embeddings into a single tensor
emb_list = []
for out in outputs:
vec = out.outputs.data.detach()
emb_list.append(vec)
embeddings = torch.stack(emb_list, dim=0)
# Split into query and passage embeddings
n_q = len(queries)
query_embeddings = embeddings[:n_q]
passage_embeddings = embeddings[n_q:]
# Cosine similarity matrix (queries x documents)
scores = cosine_similarity(query_embeddings, passage_embeddings)
print(scores)
# tensor([[0.8171, 0.1230],# [0.1207, 0.5513]])
Citation
Please refer to our
technical report of jina-code-embeddings
for training details and benchmarks. If you find it useful in your research, please cite the following paper:
@misc{kryvosheieva2025efficientcodeembeddingscode,
title={Efficient Code Embeddings from Code Generation Models},
author={Daria Kryvosheieva and Saba Sturua and Michael Günther and Scott Martens and Han Xiao},
year={2025},
eprint={2508.21290},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2508.21290},
}
Contact
Join our
Discord community
and chat with other community members about ideas.
Runs of jinaai jina-code-embeddings-0.5b on huggingface.co
57.4K
Total runs
0
24-hour runs
-1.4K
3-day runs
-4.9K
7-day runs
-22.2K
30-day runs
More Information About jina-code-embeddings-0.5b huggingface.co Model
More jina-code-embeddings-0.5b license Visit here:
jina-code-embeddings-0.5b huggingface.co is an AI model on huggingface.co that provides jina-code-embeddings-0.5b's model effect (), which can be used instantly with this jinaai jina-code-embeddings-0.5b model. huggingface.co supports a free trial of the jina-code-embeddings-0.5b model, and also provides paid use of the jina-code-embeddings-0.5b. Support call jina-code-embeddings-0.5b model through api, including Node.js, Python, http.
jina-code-embeddings-0.5b huggingface.co is an online trial and call api platform, which integrates jina-code-embeddings-0.5b's modeling effects, including api services, and provides a free online trial of jina-code-embeddings-0.5b, you can try jina-code-embeddings-0.5b online for free by clicking the link below.
jinaai jina-code-embeddings-0.5b online free url in huggingface.co:
jina-code-embeddings-0.5b is an open source model from GitHub that offers a free installation service, and any user can find jina-code-embeddings-0.5b on GitHub to install. At the same time, huggingface.co provides the effect of jina-code-embeddings-0.5b install, users can directly use jina-code-embeddings-0.5b installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
jina-code-embeddings-0.5b install url in huggingface.co: