新闻
模型
API
keyboard_arrow_down
读取器
读取URL或搜索为大模型提供更好的依据。
向量模型
世界一流的多模态多语言向量模型。
重排器
世界一流的重排器,最大限度地提高搜索相关性。
Elastic Inference Service
在 Elasticsearch 中原生运行 Jina 模型。
MCP terminal命令行articlellms.txtsmart_toy代理人data_object模式menu_book文档



登录
login
Training Recipe
Getting Started
结论
star
甄选
新闻稿
九月 04, 2025

Jina Code Embeddings:0.5B 和 1.5B 参数规模下的 SOTA 代码检索向量模型

代码生成大模型 → 代码向量模型:0.5B/1.5B 模型在 25 个代码检索基准测试中实现了 SOTA 性能。
Jina AI
Jina AI • 6 分钟的读取量
Efficient Code Embeddings from Code Generation Models
jina-code-embeddings is a novel code embedding model suite designed to retrieve code from natural language queries, perform technical question-answering, and identify semantically similar code snippets across programming languages. It makes innovative use of an autoregressive backbone pre-trained on both text and code, generating embeddings via last-token pooling. We outline the training recipe and demonstrate state-of-the-art performance despite the relatively small size of the models, validating this approach to code embedding model construction.
arXiv.orgDaria Kryvosheieva
jina-code-embeddings-1.5b - Search Foundation Models
Efficient code embeddings from code generation models
Search Foundation ModelsJina AI
jinaai/jina-code-embeddings-1.5b · Hugging Face
We’re on a journey to advance and democratize artificial intelligence through open source and open science.

今天我们发布了jina-code-embeddings,这是一个新的代码向量模型套件,包含两种尺寸——0.5B 和 1.5B 参数——以及两者的 GGUF 量化版本。这些模型构建在自回归代码生成大模型之上,尽管尺寸紧凑,但实现了最先进的检索性能。它们支持超过 15 种编程语言,包括 Python、JavaScript、Java、C++、C#、Go、Rust、TypeScript、SQL、MATLAB、R、Swift、Kotlin、HTML/CSS、PHP、Ruby、Scala、Perl 和 Shell。

jina-code-embeddings 在 25 个代码检索基准测试中实现了 78.41% (0.5B) 和 79.04% (1.5B) 的平均性能。0.5B 模型优于 Qwen3-Embedding-0.6B 5 个百分点,但体积缩小了 20%,而 1.5B 变体与 voyage-code-3 (79.23%) 相匹配,并超过了 gemini-embedding-001 (77.38%)——这两者都是具有未公开架构的专有模型。

Model Parameters Overall AVG MTEB Code AVG
<strong>jina-code-embeddings-1.5b</strong> 1.54B 79.04% 78.94%
<strong>jina-code-embeddings-0.5b</strong> 494M 78.41% 78.72%
voyage-code-3 Unknown* 79.23% 79.84%
gemini-embedding-001 Unknown* 77.38% 76.48%
jina-embeddings-v4 3.8B 74.11% 74.87%
Qwen3-Embedding-0.6B 600M 73.49% 74.69%
*Closed-source models with undisclosed architecture

这两个模型都使用五个特定于任务的指令前缀进行训练,用于不同的检索场景,每个都支持查询和文档角色以实现非对称检索。例如,您可以使用 nl2code_query 来嵌入查询,使用 nl2code_document 来嵌入文档。

Task Use Case Instruction Prefix
nl2code "How to read CSV" → pandas.read_csv() "Find the most relevant code snippet given the following query:\n"
qa Technical Q&A retrieval "Find the most relevant answer given the following question:\n"
code2code Finding similar implementations "Find an equivalent code snippet given the following code snippet:\n"
code2nl Code to documentation "Find the most relevant comment given the following code snippet:\n"
code2completion Autocomplete scenarios "Find the most relevant completion given the following start of code snippet:\n"

tagTraining Recipe

我们使用预训练的代码生成模型作为向量模型骨干。我们的模型基于 Qwen2.5-Coder-0.5B 和 1.5B 构建,具有以下特点:

Feature jina-code-embeddings-0.5b jina-code-embeddings-1.5b
Base Model Qwen2.5-Coder-0.5B Qwen2.5-Coder-1.5B
Embedding Dimensions 896 1536
Matryoshka Dimensions 64, 128, 256, 512, 896 128, 256, 512, 1024, 1536
Max Sequence Length 32,768 tokens 32,768 tokens
Pooling Strategy Last-token pooling Last-token pooling
Attention FlashAttention2 FlashAttention2
Data Type BFloat16 BFloat16

传统的代码向量模型面临一个根本性的瓶颈:没有足够高质量的注释-代码对用于监督训练。通过从在跨越 92 多种编程语言的 5.5 万亿个词元上预训练的 Qwen2.5-Coder 开始,我们继承了对编程结构的深刻语义理解、跨语言模式识别以及对语法和习惯用法的内置知识。然后,对比微调使用最少的对齐数据来调整这些知识以用于检索任务——避开了限制仅编码器模型的数据稀缺问题。

对于像跨框架代码翻译这样代表性不足的任务,我们使用大模型生成合成数据,并手动验证每个合成示例的质量。我们的训练数据将现有的 MTEB 代码任务训练拆分与改编的公共数据集(包括 CommitPackFT、SWE-Bench、Spider、MBPP 和 CodeSearchNet)相结合。

与 jina-embeddings-v3 和 v4 不同,我们没有使用 LoRA,而是直接进行完整的后训练。对于像我们这样的小模型(494M 和 1.54B 参数),LoRA 的参数效率变得不那么引人注目——当容量有限时,适配器开销实际上会损害性能。我们需要每个参数都参与到向量模型任务中。即使对于多任务场景,特定于任务的指令前缀也比多个 LoRA 适配器更简洁。我们没有切换权重配置,而是简单地添加不同的指令——这更精简,更符合大模型自然处理条件信息的方式。

训练非常高效:两个模型都使用 InfoNCE 损失通过对比学习在 4 个 A100 80GB GPU 上进行训练,0.5B 模型仅用时 8.3 小时,1.5B 变体用时 12 小时。

最后,我们对不同的池化策略进行了基准测试。Last-token pooling 实现了 78.41% 的总体平均值,在所有基准测试类别中始终优于平均池化 (77.20%) 和潜在注意力池化 (78.27%)。这 1.2 个百分点的优势使我们打破了在 jina-embeddings-v2、v3 和 v4 中建立的平均池化传统。随着越来越多的检索模型建立在仅解码器大模型之上,last-token pooling 成为自然的选择——平均池化根本无法很好地与单向注意力机制对齐。虽然平均池化可以工作,并且通常在早期步骤中更容易训练(可能是由于其凸优化环境),但我们的实验始终表明它的性能会停滞在 last-token pooling 所能达到的性能上限之下。

tagGetting Started

这两个模型都可以通过我们的 Search Foundation API 以及包括 sentence-transformers、transformers 和 llama.cpp 在内的流行框架无缝工作

tagVia API

curl http://api.jina.ai/v1/embeddings \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $JINA_API_KEY" \
  -d @- <<EOFEOF
  {
    "model": "jina-code-embeddings-1.5b",
    "input": ["print hello world in python"],
    "task": "nl2code.passage"
  }
EOFEOF

tagVia sentence-transformers

from sentence_transformers import SentenceTransformer

# Load the model (choose 0.5b or 1.5b)
model = SentenceTransformer(
    "jinaai/jina-code-embeddings-1.5b",
    model_kwargs={"torch_dtype": "bfloat16"},
    tokenizer_kwargs={"padding_side": "left"}
)

# Natural language to code
queries = ["print hello world in python", "initialize array of 5 zeros in c++"]
documents = ["print('Hello World!')", "int arr[5] = {0, 0, 0, 0, 0};"]

# Generate embeddings with task-specific prefixes
query_embeddings = model.encode(queries, prompt_name="nl2code_query")
document_embeddings = model.encode(documents, prompt_name="nl2code_document")

# Compute similarity
similarity = model.similarity(query_embeddings, document_embeddings)

tagVia transformers

```python
from transformers import AutoModel, AutoTokenizer
import torch.nn.functional as F

def last_token_pool(last_hidden_states, attention_mask):
    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), sequence_lengths]

tokenizer = AutoTokenizer.from_pretrained('jinaai/jina-code-embeddings-1.5b')
model = AutoModel.from_pretrained('jinaai/jina-code-embeddings-1.5b')

# Apply task-specific prefix
query = "Find the most relevant code snippet given the following query:\nprint hello world"
code = "Candidate code snippet:\nprint('Hello World!')"

# Tokenize and embed
batch_dict = tokenizer([query, code], padding=True, truncation=True, return_tensors="pt")
outputs = model(**batch_dict)
embeddings = last_token_pool(outputs.last_hidden_state, batch_dict['attention_mask'])

tag俄罗斯套娃向量模型截断

这两个模型都使用俄罗斯套娃表示学习进行训练,维度为[64, 128, 256, 512, 896],允许您截断向量模型而无需重新计算:

# Full embeddings: 896d (0.5B) or 1536d (1.5B)
full_embedding = model.encode(text)

# Truncate to smaller dimensions for efficiency
small_embedding = full_embedding[:256]  # Works for both models
tiny_embedding = full_embedding[:128]   # 0.5B supports down to 64d

这种灵活性允许根据您的需求在性能和效率之间进行权衡。

tag结论

jina-code-embeddings证明了有效的代码向量模型不需要大规模。 通过构建代码生成模型并应用有针对性的微调,我们使用参数小于 1.5B 的模型实现了最先进的性能。

来自如此紧凑的模型(0.5B/1.5B)的强大结果验证了我们的论点:正确的基础比参数数量更重要。 生成模型理解代码语义——这种理解直接转移到表示任务。

这与我们在 Jina AI 的更广泛愿景相一致:统一的架构,其中向量模型和生成来自相同的基础,从而突破了搜索基础模型可能实现的范围。

类别:
star
甄选
新闻稿
rss_feed

更多新闻
五月 12, 2026 • 7 分钟的读取量
jina-embeddings-v5-omni:支持文本、图像、音频和视频的向量模型
Han Xiao
二月 19, 2026 • 7 分钟的读取量
jina-embeddings-v5-text:全新的 SOTA 小型多语言向量模型
Han Xiao
Abstract digital artwork in black and white, featuring scattered dots forming letters in a halftone effect. The central lette
十二月 04, 2025 • 7 分钟的读取量
Jina-VLM:小型多语言视觉语言模型
Jina AI
Artistic representation of "Vln" in vibrant, rainbow-like colors on a minimalistic white background, with a focus on color di
搜索底座
读取器
向量模型
重排器
Elastic Inference Service
open_in_new
获取 Jina API 密钥
速率限制
API 状态
公司
关于我们
联系销售
新闻
实习生项目
下载 Jina 标志
open_in_new
下载 Elastic 徽标
open_in_new
条款
安全
条款及条件
隐私
管理 Cookie
Elastic © 2020-2026.