mem0ai/mem0 · critical · ImportError
Could not import faiss python package. Please install it wit
Error message
Could not import faiss python package. Please install it with `pip install faiss-gpu` (for CUDA supported GPU) or `pip install faiss-cpu` (depending on Python version).
What it means
ImportError raised at import time when the FAISS C extension cannot be imported. faiss.py first silences SWIG-related DeprecationWarnings, then imports faiss; if the package is absent (or its native .so fails to load), the ImportError is re-raised with guidance to install faiss-cpu or faiss-gpu. The SafeUnpickler machinery further down never runs — this is purely an environment/dependency failure.
Source
Thrown at mem0/vector_stores/faiss.py:23
import uuid
import warnings
from pathlib import Path
from typing import Any, Dict, List, Optional
import numpy as np
from pydantic import BaseModel
try:
# Suppress SWIG deprecation warnings from FAISS
warnings.filterwarnings("ignore", category=DeprecationWarning, message=".*SwigPy.*")
warnings.filterwarnings("ignore", category=DeprecationWarning, message=".*swigvarlink.*")
logging.getLogger("faiss").setLevel(logging.WARNING)
logging.getLogger("faiss.loader").setLevel(logging.WARNING)
import faiss
except ImportError:
raise ImportError(
"Could not import faiss python package. "
"Please install it with `pip install faiss-gpu` (for CUDA supported GPU) "
"or `pip install faiss-cpu` (depending on Python version)."
)
from mem0.vector_stores.base import VectorStoreBase
logger = logging.getLogger(__name__)
class SafeUnpickler(pickle.Unpickler):
"""
Restricted unpickler that only allows safe built-in types.
This prevents arbitrary code execution via pickle deserialization by only
allowing a whitelist of safe types (dict, list, str, int, float, bool, tuple, None).
"""
View on GitHub (pinned to 001c235229)
Solutions
- Install the right flavor: pip install faiss-cpu (no GPU) or pip install faiss-gpu (CUDA machine).
- If import still fails after install, install the missing native runtime (e.g. apt-get install libgomp1) or switch to a manylinux-based image.
- Match the faiss wheel to your Python version (3.9-3.12 supported by mem0).
Example fix
# before from mem0.vector_stores.faiss import FaissDB # ImportError # after # pip install faiss-cpu from mem0.vector_stores.faiss import FaissDB
Defensive patterns
Strategy: validation
Validate before calling
try:
import faiss # noqa: F401
FAISS_OK = True
except ImportError:
FAISS_OK = False
if provider == "faiss" and not FAISS_OK:
raise SystemExit("faiss missing: pip install faiss-cpu (or faiss-gpu)") Prevention
- Install faiss-cpu by default; use faiss-gpu only where CUDA is guaranteed.
- On slim Docker images, install libgomp1 so the faiss native module loads.
- Verify python -c "import faiss" in CI for any job touching the FAISS provider.
When it happens
Trigger: Importing mem0.vector_stores.faiss without faiss installed; a broken install where the wheel's native library fails to load against the system's libgomp/OpenBLAS; installing faiss-gpu on a machine without CUDA and having the import fail.
Common situations: Local experiments defaulting to the FAISS backend on a fresh venv; Alpine/slim Docker images missing OpenMP libraries needed by faiss-cpu; installing faiss-cpu on old Python versions with no matching wheel.
Related errors
- The 'upstash_vector' library is required. Please install it
- The 'boto3' library is required. Please install it using 'pi
- FastEmbed is not installed. Please install it using `pip in
- langchain is not installed. Please install it using `pip ins
- The 'ollama' library is required. Please install it using 'p
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/0bfc4d1dbcab183b.
Report an issue: GitHub.