Class Introduction
Function
Uses cn_clip to start a model locally and provides the embedding function for images and texts. The class inherits the langchain_core.embeddings.Embeddings API.
cn_clip uses torch.load to load the weight file. Ensure that the weight file is secure and reliable to prevent security issues such as command injection during weight loading.
Prototype
from mx_rag.embedding.local import ImageEmbedding ImageEmbedding(model_name, model_path, dev_id)
Parameters
Return Value
ImageEmbedding object.
Example
import sys
from paddle.base import libpaddle
from mx_rag.document.loader import ImageLoader
from mx_rag.embedding.local import ImageEmbedding
embed = ImageEmbedding.create(model_name="ViT-B-16", model_path="/data/chinese-clip-vit-base-patch16")
print(embed.embed_documents(['abc', 'bcd']))
print(embed.embed_query('abc'))
loader = ImageLoader("image path")
docs = loader.load()
if len(docs) < 1:
print("load image failed")
sys.exit(1)
print(embed.embed_images([docs[0].page_content]))
Parent topic: ImageEmbedding