Skip to content

Commit

Permalink
new: update fastembed, add fastembed-gpu, add type alias for onnx pro…
Browse files Browse the repository at this point in the history
…viders
  • Loading branch information
joein committed May 2, 2024
1 parent 2b86a09 commit bfa9bd0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ grpcio-tools = ">=1.41.0"
urllib3 = ">=1.26.14,<3"
portalocker = "^2.7.0"
fastembed = [
{ version = "0.2.6", optional = true, python = "<3.13" }
{ version = "0.2.7", optional = true, python = "<3.13" }
]
onnxruntime-gpu = [
{ version = "^1.17.0", optional = true, python = "<3.13" }
fastembed-gpu = [
{ version = "0.2.7", optional = true, python = "<3.13" }
]

[tool.poetry.group.dev.dependencies]
Expand Down Expand Up @@ -61,7 +61,7 @@ types-protobuf = "^4.21.0.5"

[tool.poetry.extras]
fastembed = ["fastembed"]
fastembed-gpu = ["fastembed", "onnxruntime-gpu"]
fastembed-gpu = ["fastembed-gpu"]

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
10 changes: 6 additions & 4 deletions qdrant_client/async_qdrant_fastembed.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@

try:
from fastembed import SparseTextEmbedding, TextEmbedding
from fastembed.common import OnnxProvider
except ImportError:
TextEmbedding = None
SparseTextEmbedding = None
OnnxProvider = None
SUPPORTED_EMBEDDING_MODELS: Dict[str, Tuple[int, models.Distance]] = (
{
model["model"]: (model["dim"], models.Distance.COSINE)
Expand Down Expand Up @@ -73,7 +75,7 @@ def set_model(
max_length: Optional[int] = None,
cache_dir: Optional[str] = None,
threads: Optional[int] = None,
providers: Optional[Sequence[Union[str, Tuple[str, Dict[Any, Any]]]]] = None,
providers: Optional[Sequence["OnnxProvider"]] = None,
**kwargs: Any,
) -> None:
"""
Expand Down Expand Up @@ -115,7 +117,7 @@ def set_sparse_model(
embedding_model_name: Optional[str],
cache_dir: Optional[str] = None,
threads: Optional[int] = None,
providers: Optional[Sequence[Union[str, Tuple[str, Dict[Any, Any]]]]] = None,
providers: Optional[Sequence["OnnxProvider"]] = None,
) -> None:
"""
Set sparse embedding model to use for hybrid search over documents in combination with dense embeddings.
Expand Down Expand Up @@ -168,7 +170,7 @@ def _get_or_init_model(
model_name: str,
cache_dir: Optional[str] = None,
threads: Optional[int] = None,
providers: Optional[Sequence[Union[str, Tuple[str, Dict[Any, Any]]]]] = None,
providers: Optional[Sequence["OnnxProvider"]] = None,
**kwargs: Any,
) -> "TextEmbedding":
if model_name in cls.embedding_models:
Expand All @@ -193,7 +195,7 @@ def _get_or_init_sparse_model(
model_name: str,
cache_dir: Optional[str] = None,
threads: Optional[int] = None,
providers: Optional[Sequence[Union[str, Tuple[str, Dict[Any, Any]]]]] = None,
providers: Optional[Sequence["OnnxProvider"]] = None,
**kwargs: Any,
) -> "SparseTextEmbedding":
if model_name in cls.sparse_embedding_models:
Expand Down
11 changes: 7 additions & 4 deletions qdrant_client/qdrant_fastembed.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@

try:
from fastembed import SparseTextEmbedding, TextEmbedding
from fastembed.common import OnnxProvider
except ImportError:
TextEmbedding = None
SparseTextEmbedding = None
OnnxProvider = None


SUPPORTED_EMBEDDING_MODELS: Dict[str, Tuple[int, models.Distance]] = (
{
Expand Down Expand Up @@ -67,7 +70,7 @@ def set_model(
max_length: Optional[int] = None,
cache_dir: Optional[str] = None,
threads: Optional[int] = None,
providers: Optional[Sequence[Union[str, Tuple[str, Dict[Any, Any]]]]] = None,
providers: Optional[Sequence["OnnxProvider"]] = None,
**kwargs: Any,
) -> None:
"""
Expand Down Expand Up @@ -112,7 +115,7 @@ def set_sparse_model(
embedding_model_name: Optional[str],
cache_dir: Optional[str] = None,
threads: Optional[int] = None,
providers: Optional[Sequence[Union[str, Tuple[str, Dict[Any, Any]]]]] = None,
providers: Optional[Sequence["OnnxProvider"]] = None,
) -> None:
"""
Set sparse embedding model to use for hybrid search over documents in combination with dense embeddings.
Expand Down Expand Up @@ -170,7 +173,7 @@ def _get_or_init_model(
model_name: str,
cache_dir: Optional[str] = None,
threads: Optional[int] = None,
providers: Optional[Sequence[Union[str, Tuple[str, Dict[Any, Any]]]]] = None,
providers: Optional[Sequence["OnnxProvider"]] = None,
**kwargs: Any,
) -> "TextEmbedding":
if model_name in cls.embedding_models:
Expand Down Expand Up @@ -198,7 +201,7 @@ def _get_or_init_sparse_model(
model_name: str,
cache_dir: Optional[str] = None,
threads: Optional[int] = None,
providers: Optional[Sequence[Union[str, Tuple[str, Dict[Any, Any]]]]] = None,
providers: Optional[Sequence["OnnxProvider"]] = None,
**kwargs: Any,
) -> "SparseTextEmbedding":
if model_name in cls.sparse_embedding_models:
Expand Down

0 comments on commit bfa9bd0

Please sign in to comment.