Skip to content

Commit

Permalink
fix: Add user-friendly message for BGE-M3 users on Google Colab. (#33)
Browse files Browse the repository at this point in the history
Signed-off-by: wxywb <xy.wang@zilliz.com>
  • Loading branch information
wxywb authored Aug 23, 2024
1 parent 66a3d9a commit e82acb9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 11 additions & 2 deletions milvus_model/hybrid/bge_m3.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,20 @@
import numpy as np

from milvus_model.base import BaseEmbeddingFunction
from milvus_model.utils import import_FlagEmbedding
from milvus_model.utils import import_FlagEmbedding, import_datasets
from milvus_model.sparse.utils import stack_sparse_embeddings

import_datasets()
import_FlagEmbedding()
from FlagEmbedding import BGEM3FlagModel

try:
from FlagEmbedding import BGEM3FlagModel
except AttributeError as e:
import sys
if "google.colab" in sys.modules and "ListView" in str(e):
print("\033[91mIt looks like you're running on Google Colab. Please restart the session to resolve this issue.\033[0m")
print("\033[91mFor further details, visit: https://github.com/milvus-io/milvus-model/issues/32.\033[0m")
raise

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
Expand Down
4 changes: 4 additions & 0 deletions milvus_model/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"import_mistralai",
"import_nomic",
"import_instructor",
"import_datasets",
]

import importlib.util
Expand Down Expand Up @@ -79,6 +80,9 @@ def import_nomic():
def import_instructor():
_check_library("InstructorEmbedding", package="InstructorEmbedding")

def import_datasets():
_check_library("datasets", package="datasets")

def _check_library(libname: str, prompt: bool = True, package: Optional[str] = None):
is_avail = False
if importlib.util.find_spec(libname):
Expand Down

0 comments on commit e82acb9

Please sign in to comment.