mem0ai/mem0 · error · KeyError

Vector with ID {vector_id} not found

Error message

Vector with ID {vector_id} not found

What it means

KeyError raised in Databricks get(vector_id): the store works around the lack of a direct get API by running an internal index query (query_text=' ' or a zero vector) and filtering, and if that returns an empty data_array it raises KeyError to mimic not-found semantics of other mem0 stores.

Source

Thrown at mem0/vector_stores/databricks.py:700

                "query_type": self.query_type,
                "filters_json": filters_json,
            }
            uses_model_endpoint = (
                self.index_type == VectorIndexType.DELTA_SYNC and self.embedding_model_endpoint_name
            )
            if uses_model_endpoint:
                query_kwargs["query_text"] = " "
            else:
                query_kwargs["query_vector"] = [0.0] * self.embedding_dimension

            results = self.client.vector_search_indexes.query_index(**query_kwargs)

            # Process results
            result_data = results.result if hasattr(results, "result") else results
            data_array = result_data.data_array if hasattr(result_data, "data_array") else []

            if not data_array:
                raise KeyError(f"Vector with ID {vector_id} not found")

            result = data_array[0]
            columns = [col.name for col in results.manifest.columns] if results.manifest and results.manifest.columns else []
            row_data = dict(zip(columns, result))

            # Build payload following the standard schema
            payload = {
                "hash": row_data.get("hash", "unknown"),
                "data": row_data.get("memory", row_data.get("data", "unknown")),
                "created_at": row_data.get("created_at"),
            }

            # Add updated_at if available
            if "updated_at" in row_data:
                payload["updated_at"] = row_data.get("updated_at")

            # Add optional fields
            for field in ["agent_id", "run_id", "user_id"]:

View on GitHub (pinned to 001c235229)

Solutions

  1. Catch KeyError and treat it as 'memory not found' (delete/skip/refresh local state).
  2. Verify the ID exists via list/get_all before acting on cached references.
  3. After delete_all or environment switches, invalidate any locally cached memory IDs.

Example fix

# before
mem = store.get(memory_id)  # KeyError bubbles up

# after
try:
    mem = store.get(memory_id)
except KeyError:
    logger.info("memory %s no longer exists", memory_id)
    mem = None
Defensive patterns

Strategy: try-catch

Validate before calling

def get_or_none(store, memory_id: str):
    try:
        return store.get(memory_id)
    except KeyError:
        return None

Try / catch

try:
    memory = store.get(memory_id)
except KeyError:
    logger.info("memory %s not found (deleted or stale id)", memory_id)
    memory = None
# proceed with memory possibly None

Prevention

When it happens

Trigger: Calling get() with a memory_id that was deleted or never inserted; a stale ID kept in application state after delete_all(); the workaround query legitimately returning zero rows because the ID column value does not match (e.g. type or quoting differences).

Common situations: UI showing cached history entries after memories were removed; retry logic referencing an ID from a previous environment/index; ID normalization differences between insert and lookup.

Related errors


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