
jina-clip-v2 is a general-purpose multilingual multimodal embedding model for text & images.jina-clip-v1 and our recently released jina-embeddings-v3, jina-clip-v2 features several significant improvements:jina-embeddings-v3 (currently the best multilingual embeddings under 1B parameters on MTEB).jina-embeddings-v3 for the text tower, jina-clip-v2 supports 89 languages for multilingual-image retrieval, showing up to 4% improvement compared to nllb-clip-large-siglip on multilingual image retrieval tasks.jina-clip-v2 combines two powerful encoders:Jina-XLM-RoBERTa (the backbone of jina-embeddings-v3) andEVA02-L14 (an efficient vision Transformer developed by BAAI).| FEATURE | TEXT ENCODER | IMAGE ENCODER |
|---|---|---|
| Base Model | Jina-XLM-RoBERTa | EVA02-L |
| Parameters | 561M | 304M |
| Input Specification | 8,192 tokens (max) | 512×512 pixels |
| Min Output Dimensions | 64 | 64 |
| Max Output Dimensions | 1,024 | 1,024 |
| Layers | 24 | 24 |
| Attention Mechanism | FlashAttention2 | xFormers |
| Pooling Strategy | Mean pooling | CLS pooling |
| Additional Features | 89 languages supported | Patch size 14x14 |
jina-clip-v2, we're taking these capabilities to the next level, breaking down language barriers to deliver more accurate cross-modal understanding and retrieval. We're confident this release delivers a promise in making multimodal search and retrieval both more powerful and more accessible to developers worldwide.torch.bfloat16
precision by default. It is highly recommended to install
FlashAttention
and xFormers
to make use of their efficient attention mechanism implementations.1curl https://api.jina.ai/v1/embeddings \
2 -H "Content-Type: application/json" \
3 -H "Authorization: Bearer [JINA_AI_API_TOKEN]" \
4 -d @- <<EOFEOF
5 {
6 "model": "jina-clip-v2",
7 "dimensions": 1024,
8 "task": "retrieval.query",
9 "normalized": true,
10 "embedding_type": "float",
11 "input": [
12 {
13 "text": "غروب جميل على الشاطئ"
14 },
15 {
16 "text": "海滩上美丽的日落"
17 },
18 {
19 "text": "A beautiful sunset over the beach"
20 },
21 {
22 "text": "Un beau coucher de soleil sur la plage"
23 },
24 {
25 "text": "Ein wunderschöner Sonnenuntergang am Strand"
26 },
27 {
28 "text": "Ένα όμορφο ηλιοβασίλεμα πάνω από την παραλία"
29 },
30 {
31 "text": "समुद्र तट पर एक खूबसूरत सूर्यास्त"
32 },
33 {
34 "text": "Un bellissimo tramonto sulla spiaggia"
35 },
36 {
37 "text": "浜辺に沈む美しい夕日"
38 },
39 {
40 "text": "해변 위로 아름다운 일몰"
41 },
42 {
43 "image": "https://i.ibb.co/nQNGqL0/beach1.jpg"
44 },
45 {
46 "image": "https://i.ibb.co/r5w8hG8/beach2.jpg"
47 }
48 ]
49 }
50EOFEOF1# !pip install transformers einops timm pillow
2from transformers import AutoModel
3
4# Initialize the model
5model = AutoModel.from_pretrained('jinaai/jina-clip-v2', trust_remote_code=True)
6
7# Corpus
8sentences = [
9 'غروب جميل على الشاطئ', # Arabic
10 '海滩上美丽的日落', # Chinese
11 'Un beau coucher de soleil sur la plage', # French
12 'Ein wunderschöner Sonnenuntergang am Strand', # German
13 'Ένα όμορφο ηλιοβασίλεμα πάνω από την παραλία', # Greek
14 'समुद्र तट पर एक खूबसूरत सूर्यास्त', # Hindi
15 'Un bellissimo tramonto sulla spiaggia', # Italian
16 '浜辺に沈む美しい夕日', # Japanese
17 '해변 위로 아름다운 일몰', # Korean
18]
19
20# Public image URLs or PIL Images
21image_urls = ['https://i.ibb.co/nQNGqL0/beach1.jpg', 'https://i.ibb.co/r5w8hG8/beach2.jpg']
22
23# Choose a matryoshka dimension, set to None to get the full 1024-dim vectors
24truncate_dim = 512
25
26# Encode text and images
27text_embeddings = model.encode_text(sentences, truncate_dim=truncate_dim)
28image_embeddings = model.encode_image(
29 image_urls, truncate_dim=truncate_dim
30) # also accepts PIL.Image.Image, local filenames, dataURI
31
32# Encode query text
33query = 'beautiful sunset over the beach' # English
34query_embeddings = model.encode_text(
35 query, task='retrieval.query', truncate_dim=truncate_dim
36)
37
38# Text to Image
39print('En -> Img: ' + str(query_embeddings @ image_embeddings[0].T))
40# Image to Image
41print('Img -> Img: ' + str(image_embeddings[0] @ image_embeddings[1].T))
42# Text to Text
43print('En -> Ar: ' + str(query_embeddings @ text_embeddings[0].T))
44print('En -> Zh: ' + str(query_embeddings @ text_embeddings[1].T))
45print('En -> Fr: ' + str(query_embeddings @ text_embeddings[2].T))
46print('En -> De: ' + str(query_embeddings @ text_embeddings[3].T))
47print('En -> Gr: ' + str(query_embeddings @ text_embeddings[4].T))
48print('En -> Hi: ' + str(query_embeddings @ text_embeddings[5].T))
49print('En -> It: ' + str(query_embeddings @ text_embeddings[6].T))
50print('En -> Jp: ' + str(query_embeddings @ text_embeddings[7].T))
51print('En -> Ko: ' + str(query_embeddings @ text_embeddings[8].T))1# !pip install sentence-transformers einops timm pillow
2from sentence_transformers import SentenceTransformer
3
4# Choose a matryoshka dimension
5truncate_dim = 512
6
7# Initialize the model
8model = SentenceTransformer(
9 'jinaai/jina-clip-v2', trust_remote_code=True, truncate_dim=truncate_dim
10)
11
12# Corpus
13sentences = [
14 'غروب جميل على الشاطئ', # Arabic
15 '海滩上美丽的日落', # Chinese
16 'Un beau coucher de soleil sur la plage', # French
17 'Ein wunderschöner Sonnenuntergang am Strand', # German
18 'Ένα όμορφο ηλιοβασίλεμα πάνω από την παραλία', # Greek
19 'समुद्र तट पर एक खूबसूरत सूर्यास्त', # Hindi
20 'Un bellissimo tramonto sulla spiaggia', # Italian
21 '浜辺に沈む美しい夕日', # Japanese
22 '해변 위로 아름다운 일몰', # Korean
23]
24
25# Public image URLs or PIL Images
26image_urls = ['https://i.ibb.co/nQNGqL0/beach1.jpg', 'https://i.ibb.co/r5w8hG8/beach2.jpg']
27
28# Encode text and images
29text_embeddings = model.encode(sentences, normalize_embeddings=True)
30image_embeddings = model.encode(
31 image_urls, normalize_embeddings=True
32) # also accepts PIL.Image.Image, local filenames, dataURI
33
34# Encode query text
35query = 'beautiful sunset over the beach' # English
36query_embeddings = model.encode(
37 query, prompt_name='retrieval.query', normalize_embeddings=True
38) [!NOTE] JinaCLIP was added in Transformers.js v3.1.0, so make sure you're using a compatible version! See the release notes for more information.
npm i @huggingface/transformersjinaai/jina-clip-v2:1import { AutoModel, AutoProcessor, RawImage, matmul } from "@huggingface/transformers";
2
3// Load processor and model
4const model_id = "jinaai/jina-clip-v2";
5const processor = await AutoProcessor.from_pretrained(model_id);
6const model = await AutoModel.from_pretrained(model_id, { dtype: "q4" /* e.g., "fp16", "q8", or "q4" */ });
7
8// Prepare inputs
9const urls = ["https://i.ibb.co/nQNGqL0/beach1.jpg", "https://i.ibb.co/r5w8hG8/beach2.jpg"];
10const images = await Promise.all(urls.map(url => RawImage.read(url)));
11const sentences = [
12 "غروب جميل على الشاطئ", // Arabic
13 "海滩上美丽的日落", // Chinese
14 "Un beau coucher de soleil sur la plage", // French
15 "Ein wunderschöner Sonnenuntergang am Strand", // German
16 "Ένα όμορφο ηλιοβασίλεμα πάνω από την παραλία", // Greek
17 "समुद्र तट पर एक खूबसूरत सूर्यास्त", // Hindi
18 "Un bellissimo tramonto sulla spiaggia", // Italian
19 "浜辺に沈む美しい夕日", // Japanese
20 "해변 위로 아름다운 일몰", // Korean
21];
22
23// Encode text and images
24const inputs = await processor(sentences, images, { padding: true, truncation: true });
25const { l2norm_text_embeddings, l2norm_image_embeddings } = await model(inputs);
26
27// Encode query (text-only)
28const query_prefix = "Represent the query for retrieving evidence documents: ";
29const query_inputs = await processor(query_prefix + "beautiful sunset over the beach");
30const { l2norm_text_embeddings: query_embeddings } = await model(query_inputs);
31
32// Compute text-image similarity scores
33const text_to_image_scores = await matmul(query_embeddings, l2norm_image_embeddings.transpose(1, 0));
34console.log("text-image similarity scores", text_to_image_scores.tolist()[0]); // [0.29530206322669983, 0.3183615803718567]
35
36// Compute image-image similarity scores
37const image_to_image_score = await matmul(l2norm_image_embeddings[0], l2norm_image_embeddings[1]);
38console.log("image-image similarity score", image_to_image_score.item()); // 0.9344457387924194
39
40// Compute text-text similarity scores
41const text_to_text_scores = await matmul(query_embeddings, l2norm_text_embeddings.transpose(1, 0));
42console.log("text-text similarity scores", text_to_text_scores.tolist()[0]); // [0.5566609501838684, 0.7028406858444214, 0.582255482673645, 0.6648036241531372, 0.5462006330490112, 0.6791588068008423, 0.6192430257797241, 0.6258729100227356, 0.6453716158866882]1# !pip install transformers onnxruntime pillow
2import onnxruntime as ort
3from transformers import AutoImageProcessor, AutoTokenizer
4
5# Load tokenizer and image processor using transformers
6tokenizer = AutoTokenizer.from_pretrained('jinaai/jina-clip-v2', trust_remote_code=True)
7image_processor = AutoImageProcessor.from_pretrained(
8 'jinaai/jina-clip-v2', trust_remote_code=True
9)
10
11# Corpus
12sentences = [
13 'غروب جميل على الشاطئ', # Arabic
14 '海滩上美丽的日落', # Chinese
15 'Un beau coucher de soleil sur la plage', # French
16 'Ein wunderschöner Sonnenuntergang am Strand', # German
17 'Ένα όμορφο ηλιοβασίλεμα πάνω από την παραλία', # Greek
18 'समुद्र तट पर एक खूबसूरत सूर्यास्त', # Hindi
19 'Un bellissimo tramonto sulla spiaggia', # Italian
20 '浜辺に沈む美しい夕日', # Japanese
21 '해변 위로 아름다운 일몰', # Korean
22]
23
24# Public image URLs or PIL Images
25image_urls = ['https://i.ibb.co/nQNGqL0/beach1.jpg', 'https://i.ibb.co/r5w8hG8/beach2.jpg']
26
27# Tokenize input texts and transform input images
28input_ids = tokenizer(sentences, return_tensors='np')['input_ids']
29pixel_values = image_processor(image_urls)['pixel_values']
30
31# Start an ONNX Runtime Session
32session = ort.InferenceSession('jina-clip-v2/onnx/model.onnx')
33
34# Run inference
35output = session.run(None, {'input_ids': input_ids, 'pixel_values': pixel_values})
36
37# Keep the normalised embeddings, first 2 outputs are un-normalized
38_, _, text_embeddings, image_embeddings = outputjina-clip-v2 useful in your research, please cite the following paper:1@misc{koukounas2024jinaclipv2multilingualmultimodalembeddings,
2 title={jina-clip-v2: Multilingual Multimodal Embeddings for Text and Images},
3 author={Andreas Koukounas and Georgios Mastrapas and Bo Wang and Mohammad Kalim Akram and Sedigheh Eslami and Michael Günther and Isabelle Mohr and Saba Sturua and Scott Martens and Nan Wang and Han Xiao},
4 year={2024},
5 eprint={2412.08802},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL},
8 url={https://arxiv.org/abs/2412.08802},
9}