{"record":{"id":"de839ff65bb1a523","repo":"mem0ai/mem0","slug":"invalid-distance-strategy-must-be-one-of-euclid","errorCode":null,"errorMessage":"Invalid distance_strategy. Must be one of: 'euclidean', 'inner_product', 'cosine'","messagePattern":"Invalid distance_strategy\\. Must be one of: 'euclidean', 'inner_product', 'cosine'","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mem0/configs/vector_stores/faiss.py","lineNumber":22,"sourceCode":"\n\nclass FAISSConfig(BaseModel):\n    collection_name: str = Field(\"mem0\", description=\"Default name for the collection\")\n    path: Optional[str] = Field(None, description=\"Path to store FAISS index and metadata\")\n    distance_strategy: str = Field(\n        \"euclidean\", description=\"Distance strategy to use. Options: 'euclidean', 'inner_product', 'cosine'\"\n    )\n    normalize_L2: bool = Field(\n        False, description=\"Whether to normalize L2 vectors (only applicable for euclidean distance)\"\n    )\n    embedding_model_dims: int = Field(1536, description=\"Dimension of the embedding vector\")\n\n    @model_validator(mode=\"before\")\n    @classmethod\n    def validate_distance_strategy(cls, values: Dict[str, Any]) -> Dict[str, Any]:\n        distance_strategy = values.get(\"distance_strategy\")\n        if distance_strategy and distance_strategy not in [\"euclidean\", \"inner_product\", \"cosine\"]:\n            raise ValueError(\"Invalid distance_strategy. Must be one of: 'euclidean', 'inner_product', 'cosine'\")\n        return values\n\n    @model_validator(mode=\"before\")\n    @classmethod\n    def validate_extra_fields(cls, values: Dict[str, Any]) -> Dict[str, Any]:\n        allowed_fields = set(cls.model_fields.keys())\n        input_fields = set(values.keys())\n        extra_fields = input_fields - allowed_fields\n        if extra_fields:\n            raise ValueError(\n                f\"Extra fields not allowed: {', '.join(extra_fields)}. Please input only the following fields: {', '.join(allowed_fields)}\"\n            )\n        return values\n\n    model_config = ConfigDict(arbitrary_types_allowed=True)\n","sourceCodeStart":4,"sourceCodeEnd":38,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/configs/vector_stores/faiss.py#L4-L38","documentation":"Raised by the Faiss vector store config when distance_strategy is set to a value outside the supported set. FAISS indexes in mem0 support exactly 'euclidean' (L2), 'inner_product', and 'cosine'; any other string fails validation at config construction, before any index is built.","triggerScenarios":"Passing distance_strategy values like 'l2', 'dot', 'IP', 'manhattan', or 'EUCLIDEAN' (case-sensitive check) to FaissConfig. Empty/None is allowed and falls back to the default.","commonSituations":"Using FAISS-native or other-library metric names ('IP', 'L2', 'cs') instead of mem0's names; uppercase variants copied from docs of a different library; renaming of the option's accepted values across mem0 versions.","solutions":["Use one of the exact lowercase values: 'euclidean', 'inner_product', or 'cosine'","For dot-product similarity use 'inner_product'; for L2 use 'euclidean' — not the FAISS abbreviations","Omit distance_strategy to keep the 'euclidean' default if unsure","Keep the mapping from your metric vocabulary to mem0's in one constant in your codebase"],"exampleFix":"# before\nFaissConfig(distance_strategy=\"L2\")\n\n# after\nFaissConfig(distance_strategy=\"euclidean\")","handlingStrategy":"validation","validationCode":"FAISS_STRATEGIES = {\"euclidean\", \"inner_product\", \"cosine\"}\ndef validate_faiss_strategy(cfg: dict) -> None:\n    s = cfg.get(\"distance_strategy\")\n    if s is not None and s not in FAISS_STRATEGIES:\n        raise RuntimeError(f\"distance_strategy must be one of {sorted(FAISS_STRATEGIES)}, got {s!r}\")","typeGuard":"def faiss_strategy_valid(cfg: dict) -> bool:\n    s = cfg.get(\"distance_strategy\")\n    return s is None or s in {\"euclidean\", \"inner_product\", \"cosine\"}","tryCatchPattern":"from pydantic import ValidationError\ntry:\n    FaissConfig(**cfg)\nexcept ValidationError as e:\n    if \"Invalid distance_strategy\" in str(e):\n        # map to euclidean/inner_product/cosine, then retry\n        ...","preventionTips":["Use mem0's exact lowercase names, not FAISS abbreviations (L2/IP)","Define one constants mapping from your metric vocabulary to mem0's","Omit the field if the default euclidean is acceptable"],"tags":["pydantic","configuration","vector-store","faiss","enum-validation"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}