{"record":{"id":"0bfc4d1dbcab183b","repo":"mem0ai/mem0","slug":"could-not-import-faiss-python-package-please-inst","errorCode":null,"errorMessage":"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).","messagePattern":"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\\)\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"critical","filePath":"mem0/vector_stores/faiss.py","lineNumber":23,"sourceCode":"import uuid\nimport warnings\nfrom pathlib import Path\nfrom typing import Any, Dict, List, Optional\n\nimport numpy as np\nfrom pydantic import BaseModel\n\ntry:\n    # Suppress SWIG deprecation warnings from FAISS\n    warnings.filterwarnings(\"ignore\", category=DeprecationWarning, message=\".*SwigPy.*\")\n    warnings.filterwarnings(\"ignore\", category=DeprecationWarning, message=\".*swigvarlink.*\")\n\n    logging.getLogger(\"faiss\").setLevel(logging.WARNING)\n    logging.getLogger(\"faiss.loader\").setLevel(logging.WARNING)\n\n    import faiss\nexcept ImportError:\n    raise ImportError(\n        \"Could not import faiss python package. \"\n        \"Please install it with `pip install faiss-gpu` (for CUDA supported GPU) \"\n        \"or `pip install faiss-cpu` (depending on Python version).\"\n    )\n\nfrom mem0.vector_stores.base import VectorStoreBase\n\nlogger = logging.getLogger(__name__)\n\n\nclass SafeUnpickler(pickle.Unpickler):\n    \"\"\"\n    Restricted unpickler that only allows safe built-in types.\n\n    This prevents arbitrary code execution via pickle deserialization by only\n    allowing a whitelist of safe types (dict, list, str, int, float, bool, tuple, None).\n    \"\"\"\n","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/vector_stores/faiss.py#L5-L41","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"# before\nfrom mem0.vector_stores.faiss import FaissDB  # ImportError\n\n# after\n# pip install faiss-cpu\nfrom mem0.vector_stores.faiss import FaissDB","handlingStrategy":"validation","validationCode":"try:\n    import faiss  # noqa: F401\n    FAISS_OK = True\nexcept ImportError:\n    FAISS_OK = False\n\nif provider == \"faiss\" and not FAISS_OK:\n    raise SystemExit(\"faiss missing: pip install faiss-cpu (or faiss-gpu)\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["faiss","dependencies","import-error","native-libraries"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}