feat(oss): make spaCy an optional dependency

Move spacy from core dependencies to optional [nlp] extra.
The system gracefully degrades without spaCy:
- Lemmatization falls back to raw text
- Entity extraction returns empty (no entity boost)
- BM25 keyword search still works on raw text
- Semantic search and additive scoring unaffected

Install with NLP support: pip install mem0ai[nlp]

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Soumil Rathi
2026-04-02 11:04:38 -07:00
co-authored by Claude Opus 4.6
parent 70c62ea54f
commit 9c9b3d54e2
3 changed files with 17 additions and 3 deletions
+7
View File
@@ -90,6 +90,13 @@ Install the sdk via pip:
pip install mem0ai
```
For enhanced hybrid search with BM25 keyword matching and entity extraction, install with NLP support:
```bash
pip install mem0ai[nlp]
python -m spacy download en_core_web_sm
```
Install sdk via npm:
```bash
npm install mem0ai
+7 -2
View File
@@ -19,8 +19,13 @@ _lock = threading.Lock()
def _ensure_model_available():
"""Download en_core_web_sm if not already installed. Does not load the model."""
import spacy
"""Download en_core_web_sm if spaCy is installed but model is missing."""
try:
import spacy
except ImportError:
raise ImportError(
"spaCy is not installed. Install it with: pip install mem0ai[nlp]"
)
if not spacy.util.is_package("en_core_web_sm"):
logger.info("Downloading spaCy model en_core_web_sm...")
+3 -1
View File
@@ -21,10 +21,12 @@ dependencies = [
"pytz>=2024.1",
"sqlalchemy>=2.0.31",
"protobuf>=5.29.0,<6.0.0",
"spacy>=3.7.0",
]
[project.optional-dependencies]
nlp = [
"spacy>=3.7.0",
]
graph = [
"langchain-neo4j>=0.4.0",
"langchain-aws>=0.2.23",