Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: support jina-embeddings via sentence-transformers #1278

Closed
kno10 opened this issue Nov 11, 2023 · 8 comments · Fixed by #1308
Closed

Feat: support jina-embeddings via sentence-transformers #1278

kno10 opened this issue Nov 11, 2023 · 8 comments · Fixed by #1308
Assignees
Labels
enhancement New feature or request

Comments

@kno10
Copy link
Contributor

kno10 commented Nov 11, 2023

Jina Embeddings are a promising current model for embeddings used in RAG.
https://huggingface.co/jinaai/jina-embeddings-v2-base-en
While they are available via huggingface transformers, the current localai backend will not load them:

"could not load model (no success): Unexpected err=ValueError('The repository for /root/.cache/torch/sentence_transformers/jinaai_jina-embeddings-v2-base-en/ contains custom code which must be executed to correctlyload the model. You can inspect the repository content at https://hf.co//root/.cache/torch/sentence_transformers/jinaai_jina-embeddings-v2-base-en/.\\nPlease pass the argument 'trust_remote_code=True' to allow custom code to be run.'), type(err)=\u003cclass 'ValueError'\u003e","type":""}}

As little work may be necessary as allowing to pass this option to the constructor.

@kno10 kno10 added the enhancement New feature or request label Nov 11, 2023
@mudler
Copy link
Owner

mudler commented Nov 11, 2023

this is covered by #1250

@localai-bot
Copy link
Contributor

⚠️⚠️⚠️⚠️⚠️

Hi! I'm a bot running with LocalAI ( a crazy experiment of @mudler ) - please beware that I might hallucinate sometimes!

but.... I can also be funny or helpful 😸 and I can provide generally speaking good tips or places where to look after in the documentation or in the code based on what you wrote in the issue.

Don't engage in conversation with me,
I don't support (yet) replying!

⚠️⚠️⚠️⚠️⚠️

Thank you for bringing this up! We will add support for Jina embeddings in a future release of LocalAI. In the meantime, you can use the huggingface transformers library to load and use Jina embeddings in your code. Here's an example usage:

import torch
from transformers import jinaai_jina_embeddings, AutoTokenizer
# Load the Jina embeddings model
model = jinaai_jina_embeddings('jina-embeddings-v2-base-en', 'tokenizer')
# Use the tokenizer to generate embeddings for some text
inputs = ['The food was delicious and the waiter was friendly']
embeddings = model(inputs)
print(embeddings)

This code will load the Jina embeddings model and use it to generate embeddings for the input text. You can then use these embeddings in your RAG model as needed.

Sources:

@mudler mudler reopened this Nov 19, 2023
@mudler
Copy link
Owner

mudler commented Nov 19, 2023

Still not ready

@mudler mudler linked a pull request Nov 20, 2023 that will close this issue
@kno10
Copy link
Contributor Author

kno10 commented Nov 25, 2023

I still get the error

{"error":{"code":500,"message":"could not load model (no success): Unexpected err=ValueError('The
repository for /root/.cache/torch/sentence_transformers/jinaai_jina-embeddings-v2-base-en/ contains
custom code which must be executed to correctly load the model. You can inspect the repository
content at https://hf.co//root/.cache/torch/sentence_transformers/jinaai_jina-embeddings-v2-base-en/.\\n
Please pass the argument `trust_remote_code=True`
to allow custom code to be run.'), type(err)=\u003cclass 'ValueError'\u003e","type":""}}

with master-cublas-cuda12 sha256:6ac4da5208e7

It would be best to allow specifying the revision and code_revision, i.e., the git commit of the model repository.

@kno10
Copy link
Contributor Author

kno10 commented Nov 25, 2023

I noticed the following:

  • feat(transformers): add embeddings with Automodel #1308 added trust_remote_code to the transformers backend only, but not the sentencetransformers, but the pull request description mentioned renaming huggingface-embeddings to sentencetransformers
  • I tried transformers, but that fails loading with ImportError: cannot import name 'AutoModel' from partially initialized module 'transformers' (most likely due to a circular import) (/build/backend/python/transformers/transformers.py)
    which likely is caused because the backend is in a file named transformers.py, trying to import from the huggingface package of the same name (hence circular import).

@kno10
Copy link
Contributor Author

kno10 commented Nov 26, 2023

Thank you, it now works with the fixed transformers backend. While it was not loaded into the GPU, the CPU performance seems to be well usable for my current purpose.

@FrankDaze
Copy link

@kno10 could you describe how you got it to work? I pulled the latest cuda12 master image and made a rebuild. My yml file looks like this:

name: jina_de
backend: sentencetransformers
embeddings: true
parameters:
  model: Xenova/jina-embeddings-v2-base-de

@Ar9av
Copy link

Ar9av commented Aug 29, 2024

Any updates on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants