mem0ai/mem0 · error · ValueError

Invalid index_to_id value type: {type(value)}, expected str

Error message

Invalid index_to_id value type: {type(value)}, expected str

What it means

Raised while validating index_to_id entries: a value (the memory id for a FAISS row) is not a str. Ids must be strings to match docstore keys. ValueError raised at load.

Source

Thrown at mem0/vector_stores/faiss.py:116

    if not isinstance(docstore, dict):
        raise ValueError("Invalid docstore format: docstore must be a dict")

    if not isinstance(index_to_id, dict):
        raise ValueError("Invalid docstore format: index_to_id must be a dict")

    # Validate docstore entries
    for key, value in docstore.items():
        if not isinstance(key, str):
            raise ValueError(f"Invalid docstore key type: {type(key)}, expected str")
        if not isinstance(value, dict):
            raise ValueError(f"Invalid docstore value type: {type(value)}, expected dict")

    # Validate index_to_id entries
    for key, value in index_to_id.items():
        if not isinstance(key, int):
            raise ValueError(f"Invalid index_to_id key type: {type(key)}, expected int")
        if not isinstance(value, str):
            raise ValueError(f"Invalid index_to_id value type: {type(value)}, expected str")

    return docstore, index_to_id


class OutputData(BaseModel):
    id: Optional[str]  # memory id
    score: Optional[float]  # distance
    payload: Optional[Dict]  # metadata


class FAISS(VectorStoreBase):
    def __init__(
        self,
        collection_name: str,
        path: Optional[str] = None,
        distance_strategy: str = "euclidean",
        normalize_L2: bool = False,
        embedding_model_dims: int = 1536,

View on GitHub (pinned to 001c235229)

Solutions

  1. Stringify all index_to_id values (and docstore keys to match) in a migration pass
  2. Rebuild the store using mem0's add API, which generates str(uuid4()) ids
  3. Discard and re-index if ids cannot be recovered reliably

Example fix

# before
index_to_id = data[1]  # values may be ints

# after
index_to_id = {k: str(v) for k, v in data[1].items()}
docstore = {str(k): v for k, v in data[0].items()}
Defensive patterns

Strategy: validation

Validate before calling

data[1] = {k: str(v) for k, v in data[1].items()}
data[0] = {str(k): v for k, v in data[0].items()}  # keep both sides consistent

Type guard

def index_to_id_values_are_str(x) -> bool:
    return isinstance(x, dict) and all(isinstance(v, str) for v in x.values())

Prevention

When it happens

Trigger: A persisted index_to_id whose values are ints or uuid objects, e.g. a store built with integer ids or unpickled uuid.UUID values.

Common situations: Custom code that inserted rows with non-string ids; merging stores from different sources; older files created before strict validation existed.

Related errors


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