mem0ai/mem0 · warning · ValueError

Unsupported index_type: {self.index_type}. Must be 'hnsw' or

Error message

Unsupported index_type: {self.index_type}. Must be 'hnsw' or 'flat'

What it means

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__).

Source

Thrown at mem0/vector_stores/valkey.py:162

                "EF_RUNTIME",
                str(self.hnsw_ef_runtime),
            ]
        elif self.index_type == "flat":
            vector_config = [
                "embedding",
                "VECTOR",
                "FLAT",
                "6",  # Attribute count: TYPE, FLOAT32, DIM, dims, DISTANCE_METRIC, metric
                "TYPE",
                "FLOAT32",
                "DIM",
                str(embedding_dims),
                "DISTANCE_METRIC",
                distance_metric,
            ]
        else:
            # This should never happen due to constructor validation, but be defensive
            raise ValueError(f"Unsupported index_type: {self.index_type}. Must be 'hnsw' or 'flat'")

        # Build the complete command (comma is default separator for TAG fields)
        cmd = [
            "FT.CREATE",
            collection_name,
            "ON",
            "HASH",
            "PREFIX",
            "1",
            prefix,
            "SCHEMA",
            "memory_id",
            "TAG",
            "hash",
            "TAG",
            "agent_id",
            "TAG",
            "run_id",

View on GitHub (pinned to 001c235229)

Solutions

  1. Do not mutate index_type after init — create a new Valkey instance with the desired index_type instead.
  2. If a subclass skips the parent constructor, call super().__init__(...) so validation runs.
  3. Treat hitting this branch as a code smell signal (bypassed invariant), not a config problem to tune.

Example fix

# before
store = Valkey(...)
store.index_type = "ivf"  # bypasses constructor validation
store.create_col(1536)  # defensive ValueError

# after
store = Valkey(valkey_url=..., index_type="hnsw", embedding_model_dims=1536)
store.create_col(1536)
Defensive patterns

Strategy: try-catch

Validate before calling

def check_store_invariant(store) -> None:
    if getattr(store, "index_type", None) not in ("hnsw", "flat"):
        raise RuntimeError("Valkey store index_type mutated after construction; recreate the instance")

Try / catch

try:
    store.create_col(dims)
except ValueError as e:
    if "Unsupported index_type" in str(e):
        raise RuntimeError("Valkey invariant violated: index_type changed post-init; rebuild the store") from e
    raise

Prevention

When it happens

Trigger: 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.

Common situations: Hot-patching config on a live store instance; tests constructing mock/partial objects; monkeypatching during migration scripts; essentially never in ordinary configuration-driven usage.

Related errors


AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15). Data as JSON: /api/errors/cdcfd8629f0d934d. Report an issue: GitHub.