OpenBMB/ChatDev · error · ImportError
sentence-transformers is required for LocalEmbedding
Error message
sentence-transformers is required for LocalEmbedding
What it means
LocalEmbedding depends on the sentence-transformers package to load local models. If `from sentence_transformers import SentenceTransformer` fails with ImportError, __init__ converts it into this explicit ImportError telling you to install sentence-transformers.
Source
Thrown at runtime/node/agent/memory/embedding.py:178
# Default to the first chunk
return chunk_embeddings[0]
class LocalEmbedding(EmbeddingBase):
def __init__(self, embedding_config: EmbeddingConfig):
super().__init__(embedding_config)
self.model_path = embedding_config.params.get('model_path')
self.device = embedding_config.params.get('device', 'cpu')
self._fallback_dim = 768 # Default; updated after first successful call
if not self.model_path:
raise ValueError("LocalEmbedding requires model_path parameter")
# Load the local embedding model (e.g., sentence-transformers)
try:
from sentence_transformers import SentenceTransformer
self.model = SentenceTransformer(self.model_path, device=self.device)
except ImportError:
raise ImportError("sentence-transformers is required for LocalEmbedding")
def get_embedding(self, text):
# Preprocess text before encoding
processed_text = self._preprocess_text(text)
if not processed_text:
return [0.0] * self._fallback_dim
try:
embedding = self.model.encode(processed_text, convert_to_tensor=False)
result = embedding.tolist()
self._fallback_dim = len(result)
return result
except Exception as e:
logger.error(f"Error getting local embedding: {e}")
return [0.0] * self._fallback_dim
View on GitHub (pinned to 4fb2db0ea9)
Solutions
- pip install sentence-transformers
- Install the package's embedding extras if provided (e.g. pip install 'package[local-embedding]')
- Confirm you're in the same interpreter/venv the app runs in (pip list | grep sentence)
Example fix
# shell # before: ImportError at agent construction pip install sentence-transformers
Defensive patterns
Strategy: validation
Validate before calling
if embedding_config.provider == 'local':
import importlib.util
if importlib.util.find_spec('sentence_transformers') is None:
raise ConfigError('install sentence-transformers for local embeddings') Prevention
- Add sentence-transformers to deployment requirements
- Probe optional deps at startup
When it happens
Trigger: provider='local' with model_path set, but sentence-transformers (and its torch dependency) not installed in the current environment.
Common situations: Fresh environments with only the base runtime installed; missing the extras (e.g. pip install 'pkg[local-embedding]'); wrong virtualenv/conda env activated; torch present but sentence-transformers missing.
Related errors
- mem0ai is required for Mem0Memory. Install it with: pip inst
- Unsupported embedding model: {model}
- LocalEmbedding requires model_path parameter
AI-assisted analysis of OpenBMB/ChatDev@4fb2db0ea9 (2026-08-27).
Data as JSON: /api/errors/b413e2e563ec7eb6.
Report an issue: GitHub.