Skip to content
Open
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
2 changes: 1 addition & 1 deletion signalwire/signalwire/search/index_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def _extract_metadata_from_json_content(
def _load_model(self) -> None:
"""Load embedding model (lazy loading)"""
if self.model is None:
if not SentenceTransformer:
if SentenceTransformer is None:
raise ImportError(
"sentence-transformers is required for embedding generation. Install with: pip install sentence-transformers"
)
Expand Down
6 changes: 5 additions & 1 deletion signalwire/signalwire/search/query_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,11 @@ def _get_cached_model(model_name: str | None = None) -> Any:
from sentence_transformers import SentenceTransformer

logger.info(f"Loading sentence transformer model: {model_name}")
model = SentenceTransformer(model_name)
# `Any` because the tag below is a deliberate side channel:
# torch's Module.__setattr__ overloads accept only Tensor/Module, so
# a typed local rejects a str attribute. set_global_model() reads it
# back with getattr. Matches _model_cache's own dict[str, Any].
model: Any = SentenceTransformer(model_name)
# Store the model name for identification
model.model_name = model_name
# Evict oldest entry if cache is full
Expand Down
7 changes: 5 additions & 2 deletions signalwire/signalwire/search/search_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,10 @@ def _load_resources(self) -> None:
f"Loading model {model_name} for collection {collection_name}"
)
try:
model = SentenceTransformer(model_name)
# `Any`: see query_processor._get_cached_model.
# torch's Module.__setattr__ rejects a str attr;
# set_global_model() reads this tag via getattr.
model: Any = SentenceTransformer(model_name)
model.model_name = (
model_name # Store for cache comparison
)
Expand All @@ -408,7 +411,7 @@ def _load_resources(self) -> None:
else:
# SQLite backend - original behavior
# Load model (shared across all indexes)
if self.indexes and SentenceTransformer:
if self.indexes and SentenceTransformer is not None:
# Get model name from first index
sample_index = next(iter(self.indexes.values()))
model_name = self._get_model_name(sample_index)
Expand Down