Using Huggingface Embeddings completely locally


I want to use JinaAI embeddings completely locally (jinaai/jina-embeddings-v2-base-de · Hugging Face) and downloaded all files to my machine (into folder jina_embeddings). However when I am now loading the embeddings, I am getting this message:

I am loading the models like this:

from langchain_community.embeddings import HuggingFaceEmbeddings

embeddings = HuggingFaceEmbeddings(model_name="jina_embeddings",
                                       model_kwargs={'device': 'mps'}, encode_kwargs={'device': 'mps'})

So am I am doing something wrong here? I want to ensure that everything is working locally, without internet conntection if needed.

Hi, if you pass only model name, the embedding will be loaded from remote repo. You must to pass model_name like local address path. Here is a example:

Path to your local model

local_model_path = “/Users/…/model_file

Instantiate HuggingFaceInstructEmbeddings

hf = HuggingFaceInstructEmbeddings(

Thanks, do you know how to pass the trust_remote_code=True parameter here? As for now I always get prompet to trust remote code.

I am getting this error:

ValidationError: 1 validation error for HuggingFaceInstructEmbeddings
  extra fields not permitted

With this code:

from langchain_community.embeddings import HuggingFaceInstructEmbeddings

embeddings = HuggingFaceInstructEmbeddings(model_name="jinaembeddings",trust_remote_code=True,
                                       model_kwargs={'device': 'mps'}, encode_kwargs={'device': 'mps'})

I think it isn’t possible at this moment. There are two opened issues at langchain github about it. But a guy found a work around for the problem by loading the embedding model via Transformers class.
You can see here: Issue: HuggingFaceEmbeddings can not take trust_remote_code argument · Issue #6080 · langchain-ai/langchain · GitHub
Check comment of Nafay-0on Nov 9, 2023.

thanks the workaround works

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.