Jina
Install requirements
pip install -U langchain-community
Import libraries
import requests
from langchain_community.embeddings import JinaEmbeddings
from numpy import dot
from numpy.linalg import norm
from PIL import Image
API Reference:JinaEmbeddings
Embed text and queries with Jina embedding models through JinaAI APIโ
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)
Embed images and queries with Jina CLIP through JinaAI APIโ
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)
Relatedโ
- Embedding model conceptual guide
- Embedding model how-to guides