{"record":{"id":"cdcfd8629f0d934d","repo":"mem0ai/mem0","slug":"unsupported-index-type-self-index-type-must-be","errorCode":null,"errorMessage":"Unsupported index_type: {self.index_type}. Must be 'hnsw' or 'flat'","messagePattern":"Unsupported index_type: (.+?)\\. Must be 'hnsw' or 'flat'","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"mem0/vector_stores/valkey.py","lineNumber":162,"sourceCode":"                \"EF_RUNTIME\",\n                str(self.hnsw_ef_runtime),\n            ]\n        elif self.index_type == \"flat\":\n            vector_config = [\n                \"embedding\",\n                \"VECTOR\",\n                \"FLAT\",\n                \"6\",  # Attribute count: TYPE, FLOAT32, DIM, dims, DISTANCE_METRIC, metric\n                \"TYPE\",\n                \"FLOAT32\",\n                \"DIM\",\n                str(embedding_dims),\n                \"DISTANCE_METRIC\",\n                distance_metric,\n            ]\n        else:\n            # This should never happen due to constructor validation, but be defensive\n            raise ValueError(f\"Unsupported index_type: {self.index_type}. Must be 'hnsw' or 'flat'\")\n\n        # Build the complete command (comma is default separator for TAG fields)\n        cmd = [\n            \"FT.CREATE\",\n            collection_name,\n            \"ON\",\n            \"HASH\",\n            \"PREFIX\",\n            \"1\",\n            prefix,\n            \"SCHEMA\",\n            \"memory_id\",\n            \"TAG\",\n            \"hash\",\n            \"TAG\",\n            \"agent_id\",\n            \"TAG\",\n            \"run_id\",","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/vector_stores/valkey.py#L144-L180","documentation":"A defensive raise inside create_col's FT.CREATE command builder: the if/elif chain over self.index_type has handled 'hnsw' and 'flat', and the constructor already validates those values, so this branch is documented as unreachable. Seeing it at runtime means the object's index_type was mutated after construction or the constructor validation was bypassed (e.g. __new__ + manual attributes, pickling edge cases, or a subclass skipping super().__init__).","triggerScenarios":"Assigning `store.index_type = 'ivf'` after construction then calling create_col; building the object without the normal constructor; a subclass overriding __init__ without calling super(). In normal usage it cannot fire because line 96 already rejected bad values.","commonSituations":"Hot-patching config on a live store instance; tests constructing mock/partial objects; monkeypatching during migration scripts; essentially never in ordinary configuration-driven usage.","solutions":["Do not mutate index_type after init — create a new Valkey instance with the desired index_type instead.","If a subclass skips the parent constructor, call super().__init__(...) so validation runs.","Treat hitting this branch as a code smell signal (bypassed invariant), not a config problem to tune."],"exampleFix":"# before\nstore = Valkey(...)\nstore.index_type = \"ivf\"  # bypasses constructor validation\nstore.create_col(1536)  # defensive ValueError\n\n# after\nstore = Valkey(valkey_url=..., index_type=\"hnsw\", embedding_model_dims=1536)\nstore.create_col(1536)","handlingStrategy":"try-catch","validationCode":"def check_store_invariant(store) -> None:\n    if getattr(store, \"index_type\", None) not in (\"hnsw\", \"flat\"):\n        raise RuntimeError(\"Valkey store index_type mutated after construction; recreate the instance\")","typeGuard":null,"tryCatchPattern":"try:\n    store.create_col(dims)\nexcept ValueError as e:\n    if \"Unsupported index_type\" in str(e):\n        raise RuntimeError(\"Valkey invariant violated: index_type changed post-init; rebuild the store\") from e\n    raise","preventionTips":["Treat store config as immutable after construction — build a new instance to change index_type.","Ensure subclasses call super().__init__ so constructor validation runs.","Avoid pickling/restoring store objects across versions; re-create from config instead."],"tags":["valkey","defensive-code","invariant-violation","vector-store","unreachable-code"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}