Files
landing_page/qdrant-landing/content/documentation/embeddings/jina-embeddings.md
T
George 92f8196651 fix and refactor python examples (#770)
* fix: fix points selector bugs, refactor code

* fix: fix and refactor embeddings

* fix: fix and refactor frameworks

* refactor: refactor guides

* fix: fix and refactor aleph-alpha tutorial

* fix: fix and refactor tutorials

* refactoring: refactor quick-start

* fix: address review comments

* fix: replace remaining host
2024-04-03 13:17:45 +02:00

1.7 KiB

title, weight, aliases
title weight aliases
Jina Embeddings 800
/documentation/embeddings/jina-emebddngs/
../integrations/jina-embeddings/

Jina Embeddings

Qdrant can also easily work with Jina embeddings which allow for model input lengths of up to 8192 tokens.

To call their endpoint, all you need is an API key obtainable here. By the way, our friends from Jina AI provided us with a code (QDRANT) that will grant you a 10% discount if you plan to use Jina Embeddings in production.

import qdrant_client
import requests

from qdrant_client.models import Distance, VectorParams, Batch

# Provide Jina API key and choose one of the available models.
# You can get a free trial key here: https://jina.ai/embeddings/
JINA_API_KEY = "jina_xxxxxxxxxxx"
MODEL = "jina-embeddings-v2-base-en"  # or "jina-embeddings-v2-base-en"
EMBEDDING_SIZE = 768  # 512 for small variant

# Get embeddings from the API
url = "https://api.jina.ai/v1/embeddings"

headers = {
    "Content-Type": "application/json",
    "Authorization": f"Bearer {JINA_API_KEY}",
}

data = {
    "input": ["Your text string goes here", "You can send multiple texts"],
    "model": MODEL,
}

response = requests.post(url, headers=headers, json=data)
embeddings = [d["embedding"] for d in response.json()["data"]]


# Index the embeddings into Qdrant
client = qdrant_client.QdrantClient(":memory:")
client.create_collection(
    collection_name="MyCollection",
    vectors_config=VectorParams(size=EMBEDDING_SIZE, distance=Distance.DOT),
)


qdrant_client.upsert(
    collection_name="MyCollection",
    points=Batch(
        ids=list(range(len(embeddings))),
        vectors=embeddings,
    ),
)