fix(vector_stores): point fastembed-missing warning at mem0ai[extras] (#5622)
This commit is contained in:
@@ -98,7 +98,10 @@ class Qdrant(VectorStoreBase):
|
||||
self._bm25_encoder = SparseTextEmbedding(model_name="Qdrant/bm25")
|
||||
logger.info("BM25 encoder loaded (fastembed Qdrant/bm25)")
|
||||
except ImportError:
|
||||
logger.warning("fastembed not installed — BM25 keyword search disabled. Install with: pip install fastembed")
|
||||
logger.warning(
|
||||
"fastembed not installed - BM25 keyword search disabled. "
|
||||
'Install it with: pip install "mem0ai[extras]"'
|
||||
)
|
||||
self._bm25_encoder = False # sentinel: tried and failed
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to load BM25 encoder: {e}")
|
||||
|
||||
@@ -1025,3 +1025,19 @@ class TestQdrantDatetimeRangeFilters(unittest.TestCase):
|
||||
types = {type(c.range) for c in result.must}
|
||||
self.assertIn(DatetimeRange, types)
|
||||
self.assertIn(Range, types)
|
||||
|
||||
def test_missing_fastembed_warns_with_extras_install_hint(self):
|
||||
"""When fastembed is missing, the BM25 warning must point at the mem0 optional group
|
||||
that actually provides it (`mem0ai[extras]`), not the bare `fastembed` package -
|
||||
fastembed is declared under [extras], so that is the discoverable install path."""
|
||||
self.qdrant._bm25_encoder = None
|
||||
# Setting the module to None in sys.modules makes `from fastembed import ...` raise ImportError.
|
||||
with patch.dict("sys.modules", {"fastembed": None}):
|
||||
with self.assertLogs("mem0.vector_stores.qdrant", level="WARNING") as cm:
|
||||
result = self.qdrant._get_bm25_encoder()
|
||||
self.assertIsNone(result) # encoder unavailable -> None
|
||||
self.assertIs(self.qdrant._bm25_encoder, False) # sentinel: tried and failed, do not retry
|
||||
joined = "\n".join(cm.output)
|
||||
self.assertIn("mem0ai[extras]", joined) # points at the right install
|
||||
self.assertNotIn("pip install fastembed", joined) # not the bare package
|
||||
self.assertNotIn("\u2014", joined) # no em-dash
|
||||
|
||||
Reference in New Issue
Block a user