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

Openai embedding fix to support jina-embeddings-v2 #4642

Merged
merged 11 commits into from
Nov 18, 2023
8 changes: 7 additions & 1 deletion extensions/openai/embeddings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os

import numpy as np
from transformers import AutoModel

from extensions.openai.errors import ServiceUnavailableError
from extensions.openai.utils import debug_msg, float_list_to_base64
Expand Down Expand Up @@ -41,7 +42,12 @@ def load_embedding_model(model: str):
global embeddings_device, embeddings_model
try:
print(f"Try embedding model: {model} on {embeddings_device}")
embeddings_model = SentenceTransformer(model, device=embeddings_device)
if 'jina-embeddings' in model:
embeddings_model = AutoModel.from_pretrained(model, trust_remote_code=True) # trust_remote_code is needed to use the encode method
embeddings_model = embeddings_model.to(embeddings_device)
else:
embeddings_model = SentenceTransformer(model, device=embeddings_device)

print(f"Loaded embedding model: {model}")
except Exception as e:
embeddings_model = None
Expand Down