feature-extraction Β· code Β· WASM Β· ~162 MB
Text embedders map sentences into meaning-space. This one does it for code: Jina's v2 base-code model was contrastively trained on 150M+ pairs across 30 programming languages, so an English description β "read a file and parse JSON" β lands right next to the function that implements it, and two functions that do the same job in Python and Go land next to each other even though they share almost no tokens. Type a query, rank a bank of snippets by meaning, and watch keyword search fall apart where semantic search holds up. Nothing leaves your device.
| Model | jinaai/jina-embeddings-v2-base-code (ONNX build in the same repo) |
|---|---|
| Task / pipeline | feature-extraction |
| Architecture | JinaBERT β a BERT encoder with ALiBi positional bias (handles up to 8192 tokens), ~161M params β 768-dimensional embedding |
| Pooling | mask-aware mean pooling, then L2-normalize β query and code are embedded the exact same way (no prefix) |
| Training | Contrastive on 150M+ (NL, code) and (code, code) pairs across 30 languages β an embedding space where meaning, not tokens, decides nearness |
| Quantization | q8 (8-bit) ONNX (model_quantized.onnx) |
| Backend | WebAssembly (runs anywhere; no WebGPU needed) |
| Download | ~162 MB, cached after first load |
| License | Apache-2.0 |
| Web APIs | WebAssembly, Web Workers β all Baseline widely available |
Type a query in plain English (or paste code), then rank the snippet bank below by meaning. The best match rises to the top even when it shares no keywords with your query β that is the whole point of a code embedder. The matrix shows how every snippet relates to every other.
1.00 = identical direction. Bright cells that cross language boundaries are cross-language clones β same job, different syntax.
The encoder emits one 768-number vector per token; mean-pooling (mask-aware) then L2-normalizing collapses that to a single unit vector per snippet, so cosine similarity is a plain dot product. The magic of a code embedder is alignment: the English query and the function that implements it are trained to point the same way. Pick a snippet to see its real vector, and see how strongly the current query aligns with it.
First 96 of 768 dimensions (blue = positive, orange = negative, brighter = larger magnitude):
Grep finds the tokens you typed; a code embedder finds the code you meant. That difference unlocks search and tooling that used to need a hosted service β now it runs in a tab, over a private repo, with nothing uploaded.
How similar are two snippets? One cosine number β and why it stays high across languages.
Natural-language search over your own snippet bank, plus a duplicate-detector that flags near-copies.
Cross-language clone hunt: paste code in one language, find the same algorithm in another.
Retrieve the right snippet by meaning, then a local LLM (TinyLlama) explains what it does.
Feature-extraction with mean pooling β and query and code are embedded identically (no prefix):
import { pipeline } from "@huggingface/transformers";
const extract = await pipeline(
"feature-extraction",
"jinaai/jina-embeddings-v2-base-code",
{ dtype: "q8" },
); // downloads + caches ~162 MB once
// Embed an English query and a code snippet the SAME way:
const out = await extract(
["reverse a string", "def reverse(s):\n return s[::-1]"],
{ pooling: "mean", normalize: true },
);
const [q, code] = out.tolist();
// unit-length vectors β cosine similarity is just the dot product:
const sim = q.reduce((s, x, i) => s + x * code[i], 0); // high β the query describes the code
This page asks the worker for the un-normalized pooled vectors so "See inside" can show the real pre-normalization magnitude, then normalizes them in JS. Inference runs in a Web Worker, so ranking and the matrix never jank the page.