File size: 4,227 Bytes
ec9cb9b
 
 
 
 
 
b778da1
ec9cb9b
 
 
 
 
8ee6b79
682d56b
 
c275d09
4c35118
 
3cfa967
4c35118
3cfa967
 
 
4c35118
3cfa967
 
 
 
 
 
 
 
 
 
b05d751
3cfa967
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4c35118
 
 
 
3cfa967
4c35118
3cfa967
 
b778da1
c275d09
b778da1
54b187c
 
3cfa967
54b187c
3cfa967
 
54b187c
3cfa967
 
54b187c
3cfa967
 
 
 
 
 
 
 
54b187c
3cfa967
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
---
license: apache-2.0
language:
- en
- fa
- ar
inference: true
base_model:
- jinaai/jina-embeddings-v3
pipeline_tag: feature-extraction
tags:
- Embedding
library_name: transformers
---

# Jina-embedding-v3


## Overview

This repository uses the original [jinai/jina-embeddings-v3](https://huggingface.co/jinaai/jina-embeddings-v3) embedding model, without modification or fine-tuning.
A versatile sentence embedding model suitable for a wide range of natural language processing tasks
you can find the specific tasks in the *Tasks* section

*The only difference is that you can use HF inference from this page, which is unavailable in the official page of jinaai.*


---

## Inference Access

You can use this model for inference directly from this page using Hugging Face’s serverless inference API. 
This is not possible via the official Jina AI model page. Here’s an example of how to get sentence embeddings using the Hugging Face Inference API:

you can use the function below for inference (it applies mean-pooling and normalization too and returns embeddings ready to store in your vector databases)
```python
from huggingface_hub import InferenceClient
import numpy as np

def get_HF_embeddings(text, api_key, model, mean_pool=True, l2_normalize=True):
    """
    Fetches embeddings from HuggingFace serverless Inference API for a single string or a list of strings.
    Args:
        text (str or list): Input text or list of texts.
        api_key (str): HuggingFace API key.
        model (str): Model repo.
        mean_pool (bool): If True, mean-pool the output.
        l2_normalize (bool): If True, L2 normalize the output.
    Returns:
        np.ndarray: Embedding(s) as numpy array(s).
    """
    client = InferenceClient(api_key=api_key)
    if isinstance(text, str):
        texts = [text]
        single_input = True
    else:
        texts = text
        single_input = False

    result = client.feature_extraction(
        text=texts,
        model=model
    )

    if mean_pool:
        embeddings = [np.mean(r, axis=0) for r in result]
        if l2_normalize:
            embeddings = [
                e / np.linalg.norm(e) if np.linalg.norm(e) > 0 else e for e in embeddings]
    else:
        embeddings = [r for r in result]

    if single_input:
        return embeddings[0]
    return np.array(embeddings)
```

---



## Tasks

- **Extended Sequence Length:** Supports up to 8192 tokens with RoPE positional encoding.
- **Task-Specific Embeddings:** Choose the `task` parameter for different application needs:
    - `retrieval.query` – For query embeddings in asymmetric retrieval  
    - `retrieval.passage` – For passage embeddings in asymmetric retrieval  
    - `separation` – For clustering and re-ranking  
    - `classification` – For classification tasks  
    - `text-matching` – For symmetric similarity tasks (e.g., STS)
- **Matryoshka Embeddings:** Flexible embedding sizes (32, 64, 128, 256, 512, 768, 1024 dimensions).

---

## How to Use

You can use this model with either the `transformers` or the `sentence-transformers` library.  
For **full feature support** (using task-specific LoRA heads and flexible embedding sizes), it is recommended to use the `sentence-transformers` library.

### Using sentence-transformers (Recommended)

```python
from sentence_transformers import SentenceTransformer

model = SentenceTransformer("Sajjad313/jina-embedding-v3", trust_remote_code=True)

# Task-specific usage: Retrieval query embedding
query_embedding = model.encode(
    ["What is the weather like in Berlin today?"],
    task="retrieval.query"
)
```

### Using transformers

```python
from transformers import AutoTokenizer, AutoModel

tokenizer = AutoTokenizer.from_pretrained("jinaai/jina-embeddings-v3")
model = AutoModel.from_pretrained("jinaai/jina-embeddings-v3")

inputs = tokenizer(
    "What is the weather like in Berlin today?",
    return_tensors="pt", padding=True, truncation=True
)
outputs = model(**inputs)
embedding = outputs.last_hidden_state[:, 0]  # CLS token embedding
```
> Note: Using the `transformers` library gives you basic access to the model’s output, but for full task-specific capabilities, use `sentence-transformers`.

---