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

new: add local_files_only propagation to fastembed mixin #746

Closed
wants to merge 2 commits into from
Closed
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
7 changes: 7 additions & 0 deletions qdrant_client/async_qdrant_fastembed.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class AsyncQdrantFastembedMixin(AsyncQdrantBase):
def __init__(self, **kwargs: Any):
self._embedding_model_name: Optional[str] = None
self._sparse_embedding_model_name: Optional[str] = None
self.local_files_only = kwargs.get("local_files_only", False)
try:
from fastembed import SparseTextEmbedding, TextEmbedding

Expand Down Expand Up @@ -117,11 +118,13 @@ def set_model(
DeprecationWarning,
stacklevel=2,
)
local_files_only = kwargs.pop("local_files_only", self.local_files_only)
self._get_or_init_model(
model_name=embedding_model_name,
cache_dir=cache_dir,
threads=threads,
providers=providers,
local_files_only=local_files_only,
**kwargs,
)
self._embedding_model_name = embedding_model_name
Expand All @@ -132,6 +135,7 @@ def set_sparse_model(
cache_dir: Optional[str] = None,
threads: Optional[int] = None,
providers: Optional[Sequence["OnnxProvider"]] = None,
**kwargs: Any,
) -> None:
"""
Set sparse embedding model to use for hybrid search over documents in combination with dense embeddings.
Expand All @@ -152,12 +156,15 @@ def set_sparse_model(
Returns:
None
"""
local_files_only = kwargs.pop("local_files_only", self.local_files_only)
if embedding_model_name is not None:
self._get_or_init_sparse_model(
model_name=embedding_model_name,
cache_dir=cache_dir,
threads=threads,
providers=providers,
local_files_only=local_files_only,
**kwargs,
)
self._sparse_embedding_model_name = embedding_model_name

Expand Down
7 changes: 7 additions & 0 deletions qdrant_client/qdrant_fastembed.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class QdrantFastembedMixin(QdrantBase):
def __init__(self, **kwargs: Any):
self._embedding_model_name: Optional[str] = None
self._sparse_embedding_model_name: Optional[str] = None
self.local_files_only = kwargs.get("local_files_only", False)
try:
from fastembed import SparseTextEmbedding, TextEmbedding

Expand Down Expand Up @@ -119,11 +120,13 @@ def set_model(
stacklevel=2,
)

local_files_only = kwargs.pop("local_files_only", self.local_files_only)
self._get_or_init_model(
model_name=embedding_model_name,
cache_dir=cache_dir,
threads=threads,
providers=providers,
local_files_only=local_files_only,
**kwargs,
)
self._embedding_model_name = embedding_model_name
Expand All @@ -134,6 +137,7 @@ def set_sparse_model(
cache_dir: Optional[str] = None,
threads: Optional[int] = None,
providers: Optional[Sequence["OnnxProvider"]] = None,
**kwargs: Any,
) -> None:
"""
Set sparse embedding model to use for hybrid search over documents in combination with dense embeddings.
Expand All @@ -154,12 +158,15 @@ def set_sparse_model(
Returns:
None
"""
local_files_only = kwargs.pop("local_files_only", self.local_files_only)
if embedding_model_name is not None:
self._get_or_init_sparse_model(
model_name=embedding_model_name,
cache_dir=cache_dir,
threads=threads,
providers=providers,
local_files_only=local_files_only,
**kwargs,
)
self._sparse_embedding_model_name = embedding_model_name

Expand Down
20 changes: 20 additions & 0 deletions tests/test_fastembed.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,23 @@ def test_idf_models():

# the only sparse model without IDF is SPLADE, however it's too large for tests, so we don't test how non-idf
# models work


def test_local_files_only():
local_client = QdrantClient(":memory:")

if not local_client._FASTEMBED_INSTALLED:
pytest.skip("FastEmbed is not installed, skipping")

model_name = "sentence-transformers/all-MiniLM-L6-v2"
sparse_model_name = "Qdrant/bm42-all-minilm-l6-v2-attentions"

local_client.set_model(model_name)
local_client.set_sparse_model(sparse_model_name)

local_client.close()
local_client = QdrantClient(":memory:", local_files_only=True)
local_client.set_model(model_name)
local_client.set_sparse_model(sparse_model_name)
local_client.add("test_collection", **DOCS_EXAMPLE)
assert local_client.count("test_collection").count == 2
Loading