BUG: fix ImportError when optional dependency FlagEmbedding is not installed #2649
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#2540 introduces
FlagEmbedding
package to support sparse vector for bge-m3. However,FlagEmbedding
is an optional dependency for embedding model (but required for rerank):inference/setup.cfg
Lines 184 to 187 in 70a0081
In the case
FlagEmbedding
is not installed, anImportError
will be raised even if embedding models only based onsentence-transformers
are used, due to the logic related toBGEM3FlagModel
. This PR fixes this problem.By the way, maybe adding
FlagEmbedding
to required dependency for embedding is not suitable now until upstream solve the dependency, since it requirestransformers==4.44.2
(https://github.com/FlagOpen/FlagEmbedding/blob/master/setup.py#L18) and will make models like Qwen2-VL unusable (https://huggingface.co/Qwen/Qwen2-VL-7B-Instruct/discussions/5).