jina-embedding-v3 / README.md
Sajjad313's picture b05d751 verified
metadata
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 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)

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)

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

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.