{"record":{"id":"fcce6d80e8dd27ad","repo":"mem0ai/mem0","slug":"invalid-index-type-index-type-must-be-hnsw-o","errorCode":null,"errorMessage":"Invalid index_type: {index_type}. Must be 'hnsw' or 'flat'","messagePattern":"Invalid index_type: (.+?)\\. Must be 'hnsw' or 'flat'","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mem0/vector_stores/valkey.py","lineNumber":96,"sourceCode":"            index_type (str, optional): Index type ('hnsw' or 'flat'). Defaults to \"hnsw\".\n            hnsw_m (int, optional): HNSW M parameter (connections per node). Defaults to 16.\n            hnsw_ef_construction (int, optional): HNSW ef_construction parameter. Defaults to 200.\n            hnsw_ef_runtime (int, optional): HNSW ef_runtime parameter. Defaults to 10.\n            cluster_mode (bool, optional): Enable cluster mode for Valkey cluster (CME) deployments. Defaults to False.\n        \"\"\"\n        self.embedding_model_dims = embedding_model_dims\n        self.collection_name = collection_name\n        self.prefix = f\"mem0:{collection_name}\"\n        self.timezone = timezone\n        self.index_type = index_type.lower()\n        self.hnsw_m = hnsw_m\n        self.hnsw_ef_construction = hnsw_ef_construction\n        self.hnsw_ef_runtime = hnsw_ef_runtime\n        self.cluster_mode = cluster_mode\n\n        # Validate index type\n        if self.index_type not in [\"hnsw\", \"flat\"]:\n            raise ValueError(f\"Invalid index_type: {index_type}. Must be 'hnsw' or 'flat'\")\n\n        # Connect to Valkey\n        try:\n            if self.cluster_mode:\n                from valkey.cluster import ValkeyCluster\n\n                self.client = ValkeyCluster.from_url(valkey_url)\n            else:\n                self.client = valkey.from_url(valkey_url)\n            logger.debug(f\"Successfully connected to Valkey at {valkey_url} (cluster_mode={cluster_mode})\")\n        except Exception as e:\n            logger.exception(f\"Failed to connect to Valkey at {valkey_url}: {e}\")\n            raise\n\n        # Create the index schema\n        self._create_index(embedding_model_dims)\n\n    def _build_index_schema(self, collection_name, embedding_dims, distance_metric, prefix):","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/vector_stores/valkey.py#L78-L114","documentation":"Raised in Valkey.__init__ when the normalized index_type (lowercased at assignment) is neither 'hnsw' nor 'flat'. These are the only two algorithms Valkey's FT.CREATE supports for vector fields, so an unknown value cannot map to a 'VECTOR' schema algorithm; failing in the constructor prevents a confusing Redis error at collection-creation time.","triggerScenarios":"`\"index_type\": \"HNSW\"` is fine (lowercased) but `\"index_type\": \"ivf\"`, `\"hnsw3\"`, `\"flat_\"`, or a typo like `\"flAT2\"` raises; also passing an int or None which then explodes at .lower() or the membership check.","commonSituations":"Copy-pasting index algorithm names from other engines (FAISS 'IVF', Milvus 'IVF_FLAT', pgvector 'ivfflat/hnsw'); config drift between environments; YAML quoting issues that turn the value into a bool or number.","solutions":["Set index_type to exactly 'hnsw' (graph index, tunable m/ef_construction/ef_runtime) or 'flat' (brute-force, exact).","Case does not matter ('HNSW' works) but spelling does — remove engine-specific suffixes like '_FLAT' or 'IVF'.","Validate config at load time if it comes from user input or external files."],"exampleFix":"# before\nconfig = {\"vector_store\": {\"provider\": \"valkey\", \"config\": {\"index_type\": \"ivfflat\", ...}}}\n\n# after\nconfig = {\"vector_store\": {\"provider\": \"valkey\", \"config\": {\"index_type\": \"hnsw\", \"hnsw_m\": 16, ...}}}","handlingStrategy":"validation","validationCode":"def valid_index_type(v) -> str:\n    s = str(v).lower()\n    if s not in (\"hnsw\", \"flat\"):\n        raise ValueError(f\"index_type must be 'hnsw' or 'flat', got {v!r}\")\n    return s","typeGuard":"def is_valid_index_type(v) -> bool:\n    return isinstance(v, str) and v.lower() in (\"hnsw\", \"flat\")","tryCatchPattern":"try:\n    store = Valkey(valkey_url=..., index_type=index_type, embedding_model_dims=1536)\nexcept ValueError as e:\n    if \"index_type\" in str(e):\n        raise RuntimeError(f\"Bad Valkey index_type {index_type!r}; use 'hnsw' or 'flat'\") from e\n    raise","preventionTips":["Use only 'hnsw' or 'flat'; other engines' algorithm names (IVF, ivfflat) do not apply to Valkey.","Validate config values from YAML/JSON at load time before constructing clients.","Watch for YAML type coercion — quote the value if in doubt."],"tags":["configuration","valkey","validation","index-type","vector-store"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}