Our new LangChain Academy Course Deep Research with LangGraph is now live! Enroll for free.
Our new LangChain Academy Course Deep Research with LangGraph is now live! Enroll for free.
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
text_embeddings = JinaEmbeddings(
jina_api_key="jina_*", model_name="jina-embeddings-v2-base-en"
)
text = "This is a test document."
query_result = text_embeddings.embed_query(text)
print(query_result)
doc_result = text_embeddings.embed_documents([text])
print(doc_result)
multimodal_embeddings = JinaEmbeddings(jina_api_key="jina_*", model_name="jina-clip-v1")
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)
image_result = multimodal_embeddings.embed_images([image])
print(image_result)
description_result = multimodal_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)