Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion fastembed/image/onnx_embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,12 @@ def __init__(

self.model_description = self._get_model_description(model_name)
self.cache_dir = str(define_cache_dir(cache_dir))
self._specific_model_path = specific_model_path
self._model_dir = self.download_model(
self.model_description,
self.cache_dir,
local_files_only=self._local_files_only,
specific_model_path=specific_model_path,
specific_model_path=self._specific_model_path,
)

if not self.lazy_load:
Expand Down Expand Up @@ -177,6 +178,8 @@ def embed(
providers=self.providers,
cuda=self.cuda,
device_ids=self.device_ids,
local_files_only=self._local_files_only,
specific_model_path=self._specific_model_path,
**kwargs,
)

Expand Down
4 changes: 4 additions & 0 deletions fastembed/image/onnx_image_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ def _embed_images(
providers: Optional[Sequence[OnnxProvider]] = None,
cuda: bool = False,
device_ids: Optional[list[int]] = None,
local_files_only: bool = False,
specific_model_path: Optional[str] = None,
**kwargs: Any,
) -> Iterable[T]:
is_small = False
Expand All @@ -123,6 +125,8 @@ def _embed_images(
"model_name": model_name,
"cache_dir": cache_dir,
"providers": providers,
"local_files_only": local_files_only,
"specific_model_path": specific_model_path,
**kwargs,
}

Expand Down
5 changes: 4 additions & 1 deletion fastembed/late_interaction/colbert.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,12 @@ def __init__(
self.model_description = self._get_model_description(model_name)
self.cache_dir = str(define_cache_dir(cache_dir))

self._specific_model_path = specific_model_path
self._model_dir = self.download_model(
self.model_description,
self.cache_dir,
local_files_only=self._local_files_only,
specific_model_path=specific_model_path,
specific_model_path=self._specific_model_path,
)
self.mask_token_id: Optional[int] = None
self.pad_token_id: Optional[int] = None
Expand Down Expand Up @@ -233,6 +234,8 @@ def embed(
providers=self.providers,
cuda=self.cuda,
device_ids=self.device_ids,
local_files_only=self._local_files_only,
specific_model_path=self._specific_model_path,
**kwargs,
)

Expand Down
2 changes: 1 addition & 1 deletion fastembed/late_interaction/token_embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
)
from fastembed.text.onnx_embedding import OnnxTextEmbedding
from fastembed.text.onnx_text_model import TextEmbeddingWorker
import numpy as np


supported_token_embeddings_models = [
DenseModelDescription(
Expand Down
7 changes: 6 additions & 1 deletion fastembed/late_interaction_multimodal/colpali.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,12 @@ def __init__(
self.model_description = self._get_model_description(model_name)
self.cache_dir = str(define_cache_dir(cache_dir))

self._specific_model_path = specific_model_path
self._model_dir = self.download_model(
self.model_description,
self.cache_dir,
local_files_only=self._local_files_only,
specific_model_path=specific_model_path,
specific_model_path=self._specific_model_path,
)
self.mask_token_id = None
self.pad_token_id = None
Expand Down Expand Up @@ -235,6 +236,8 @@ def embed_text(
providers=self.providers,
cuda=self.cuda,
device_ids=self.device_ids,
local_files_only=self._local_files_only,
specific_model_path=self._specific_model_path,
**kwargs,
)

Expand Down Expand Up @@ -268,6 +271,8 @@ def embed_image(
providers=self.providers,
cuda=self.cuda,
device_ids=self.device_ids,
local_files_only=self._local_files_only,
specific_model_path=self._specific_model_path,
**kwargs,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ def _embed_documents(
providers: Optional[Sequence[OnnxProvider]] = None,
cuda: bool = False,
device_ids: Optional[list[int]] = None,
local_files_only: bool = False,
specific_model_path: Optional[str] = None,
**kwargs: Any,
) -> Iterable[T]:
is_small = False
Expand All @@ -146,6 +148,8 @@ def _embed_documents(
"model_name": model_name,
"cache_dir": cache_dir,
"providers": providers,
"local_files_only": local_files_only,
"specific_model_path": specific_model_path,
**kwargs,
}

Expand Down Expand Up @@ -183,6 +187,8 @@ def _embed_images(
providers: Optional[Sequence[OnnxProvider]] = None,
cuda: bool = False,
device_ids: Optional[list[int]] = None,
local_files_only: bool = False,
specific_model_path: Optional[str] = None,
**kwargs: Any,
) -> Iterable[T]:
is_small = False
Expand All @@ -209,6 +215,8 @@ def _embed_images(
"model_name": model_name,
"cache_dir": cache_dir,
"providers": providers,
"local_files_only": local_files_only,
"specific_model_path": specific_model_path,
**kwargs,
}

Expand Down
5 changes: 4 additions & 1 deletion fastembed/rerank/cross_encoder/onnx_text_cross_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,12 @@ def __init__(

self.model_description = self._get_model_description(model_name)
self.cache_dir = str(define_cache_dir(cache_dir))
self._specific_model_path = specific_model_path
self._model_dir = self.download_model(
self.model_description,
self.cache_dir,
local_files_only=self._local_files_only,
specific_model_path=specific_model_path,
specific_model_path=self._specific_model_path,
)

if not self.lazy_load:
Expand Down Expand Up @@ -189,6 +190,8 @@ def rerank_pairs(
providers=self.providers,
cuda=self.cuda,
device_ids=self.device_ids,
local_files_only=self._local_files_only,
specific_model_path=self._specific_model_path,
**kwargs,
)

Expand Down
4 changes: 4 additions & 0 deletions fastembed/rerank/cross_encoder/onnx_text_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ def _rerank_pairs(
providers: Optional[Sequence[OnnxProvider]] = None,
cuda: bool = False,
device_ids: Optional[list[int]] = None,
local_files_only: bool = False,
specific_model_path: Optional[str] = None,
**kwargs: Any,
) -> Iterable[float]:
is_small = False
Expand All @@ -120,6 +122,8 @@ def _rerank_pairs(
"model_name": model_name,
"cache_dir": cache_dir,
"providers": providers,
"local_files_only": local_files_only,
"specific_model_path": specific_model_path,
**kwargs,
}

Expand Down
9 changes: 8 additions & 1 deletion fastembed/sparse/bm25.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,12 @@ def __init__(
model_description = self._get_model_description(model_name)
self.cache_dir = str(define_cache_dir(cache_dir))

self._specific_model_path = specific_model_path
self._model_dir = self.download_model(
model_description,
self.cache_dir,
local_files_only=self._local_files_only,
specific_model_path=specific_model_path,
specific_model_path=self._specific_model_path,
)

self.token_max_length = token_max_length
Expand Down Expand Up @@ -160,6 +161,8 @@ def _embed_documents(
documents: Union[str, Iterable[str]],
batch_size: int = 256,
parallel: Optional[int] = None,
local_files_only: bool = False,
specific_model_path: Optional[str] = None,
) -> Iterable[SparseEmbedding]:
is_small = False

Expand Down Expand Up @@ -188,6 +191,8 @@ def _embed_documents(
"language": self.language,
"token_max_length": self.token_max_length,
"disable_stemmer": self.disable_stemmer,
"local_files_only": local_files_only,
"specific_model_path": specific_model_path,
}
pool = ParallelWorkerPool(
num_workers=parallel or 1,
Expand Down Expand Up @@ -226,6 +231,8 @@ def embed(
documents=documents,
batch_size=batch_size,
parallel=parallel,
local_files_only=self._local_files_only,
specific_model_path=self._specific_model_path,
)

def _stem(self, tokens: list[str]) -> list[str]:
Expand Down
5 changes: 4 additions & 1 deletion fastembed/sparse/bm42.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,12 @@ def __init__(
self.model_description = self._get_model_description(model_name)
self.cache_dir = str(define_cache_dir(cache_dir))

self._specific_model_path = specific_model_path
self._model_dir = self.download_model(
self.model_description,
self.cache_dir,
local_files_only=self._local_files_only,
specific_model_path=specific_model_path,
specific_model_path=self._specific_model_path,
)

self.invert_vocab: dict[int, str] = {}
Expand Down Expand Up @@ -301,6 +302,8 @@ def embed(
cuda=self.cuda,
device_ids=self.device_ids,
alpha=self.alpha,
local_files_only=self._local_files_only,
specific_model_path=self._specific_model_path,
)

@classmethod
Expand Down
9 changes: 8 additions & 1 deletion fastembed/sparse/minicoil.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,12 @@ def __init__(

self.model_description = self._get_model_description(model_name)
self.cache_dir = str(define_cache_dir(cache_dir))
self._specific_model_path = specific_model_path
self._model_dir = self.download_model(
self.model_description,
self.cache_dir,
local_files_only=self._local_files_only,
specific_model_path=specific_model_path,
specific_model_path=self._specific_model_path,
)

if not self.lazy_load:
Expand Down Expand Up @@ -211,6 +212,9 @@ def embed(
b=self.b,
avg_len=self.avg_len,
is_query=False,
local_files_only=self._local_files_only,
specific_model_path=self._specific_model_path,
**kwargs,
)

def query_embed(
Expand All @@ -230,6 +234,9 @@ def query_embed(
b=self.b,
avg_len=self.avg_len,
is_query=True,
local_files_only=self._local_files_only,
specific_model_path=self._specific_model_path,
**kwargs,
)

@classmethod
Expand Down
5 changes: 4 additions & 1 deletion fastembed/sparse/splade_pp.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,12 @@ def __init__(
self.model_description = self._get_model_description(model_name)
self.cache_dir = str(define_cache_dir(cache_dir))

self._specific_model_path = specific_model_path
self._model_dir = self.download_model(
self.model_description,
self.cache_dir,
local_files_only=self._local_files_only,
specific_model_path=specific_model_path,
specific_model_path=self._specific_model_path,
)

if not self.lazy_load:
Expand Down Expand Up @@ -165,6 +166,8 @@ def embed(
providers=self.providers,
cuda=self.cuda,
device_ids=self.device_ids,
local_files_only=self._local_files_only,
specific_model_path=self._specific_model_path,
**kwargs,
)

Expand Down
5 changes: 4 additions & 1 deletion fastembed/text/onnx_embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,12 @@ def __init__(

self.model_description = self._get_model_description(model_name)
self.cache_dir = str(define_cache_dir(cache_dir))
self._specific_model_path = specific_model_path
self._model_dir = self.download_model(
self.model_description,
self.cache_dir,
local_files_only=self._local_files_only,
specific_model_path=specific_model_path,
specific_model_path=self._specific_model_path,
)

if not self.lazy_load:
Expand Down Expand Up @@ -288,6 +289,8 @@ def embed(
providers=self.providers,
cuda=self.cuda,
device_ids=self.device_ids,
local_files_only=self._local_files_only,
specific_model_path=self._specific_model_path,
**kwargs,
)

Expand Down
4 changes: 4 additions & 0 deletions fastembed/text/onnx_text_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ def _embed_documents(
providers: Optional[Sequence[OnnxProvider]] = None,
cuda: bool = False,
device_ids: Optional[list[int]] = None,
local_files_only: bool = False,
specific_model_path: Optional[str] = None,
**kwargs: Any,
) -> Iterable[T]:
is_small = False
Expand Down Expand Up @@ -136,6 +138,8 @@ def _embed_documents(
"model_name": model_name,
"cache_dir": cache_dir,
"providers": providers,
"local_files_only": local_files_only,
"specific_model_path": specific_model_path,
**kwargs,
}

Expand Down