Skip to main content

Jina

Let's load the Jina Embedding class.

pip install -U langchain-community
import requests
from langchain_community.embeddings import JinaEmbeddings
from numpy import dot
from numpy.linalg import norm
from PIL import Image
API Reference:JinaEmbeddings
text_embeddings = JinaEmbeddings(
jina_api_key="jina_*", model_name="jina-embeddings-v2-base-en"
)

image_embeddings = JinaEmbeddings(jina_api_key="jina_*", model_name="jina-clip-v1")
text = "This is a test document."

image = "https://avatars.githubusercontent.com/u/126733545?v=4"

description = "Logo of a parrot and a chain on green background"

im = Image.open(requests.get(image, stream=True).raw)
print("Image:")
display(im)
query_result = text_embeddings.embed_query(text)
print(query_result)
doc_result = text_embeddings.embed_documents([text])
print(doc_result)
image_result = image_embeddings.embed_images([image])
print(image_result)
description_result = image_embeddings.embed_documents([description])
print(description_result)
cosine_similarity = dot(image_result[0], description_result[0]) / (
norm(image_result[0]) * norm(description_result[0])
)
print(cosine_similarity)

Was this page helpful?


You can leave detailed feedback on GitHub.