mem0ai/mem0 · error · ValueError

Vector {vector_id} not found

Error message

Vector {vector_id} not found

What it means

FAISS.update() raises ValueError when the given vector_id has no entry in the docstore — you cannot update a memory the store never held (or that was already deleted). The check happens before any payload merge.

Source

Thrown at mem0/vector_stores/faiss.py:504

    def update(
        self,
        vector_id: str,
        vector: Optional[List[float]] = None,
        payload: Optional[Dict] = None,
    ):
        """
        Update a vector and its payload.

        Args:
            vector_id (str): ID of the vector to update.
            vector (Optional[List[float]], optional): Updated vector. Defaults to None.
            payload (Optional[Dict], optional): Updated payload. Defaults to None.
        """
        if self.index is None:
            raise ValueError("Collection not initialized. Call create_col first.")

        if vector_id not in self.docstore:
            raise ValueError(f"Vector {vector_id} not found")

        current_payload = self.docstore[vector_id].copy()

        if payload is not None:
            self.docstore[vector_id] = payload.copy()
            current_payload = self.docstore[vector_id].copy()

        if vector is not None:
            self.delete(vector_id)
            self.insert([vector], [current_payload], [vector_id])
        else:
            self._save()

        logger.info(f"Updated vector {vector_id} in collection {self.collection_name}")

    def get(self, vector_id: str) -> OutputData:
        """
        Retrieve a vector by ID.

View on GitHub (pinned to 001c235229)

Solutions

  1. Check existence first: vs.get(vector_id) returns None for missing ids
  2. Re-fetch current memory ids (list/search) before updating
  3. Serialize delete/update per memory id, or use a per-id lock in concurrent pipelines

Example fix

# before
vs.update(vector_id, payload=new_payload)  # ValueError: Vector ... not found

# after
if vs.get(vector_id) is not None:
    vs.update(vector_id, payload=new_payload)
else:
    vs.insert([vector], [new_payload], [vector_id])
Defensive patterns

Strategy: type-guard

Validate before calling

if vs.get(vector_id) is None:
    # absent: insert instead of update
    pass

Type guard

def memory_exists(vs, vector_id: str) -> bool:
    return vs.get(vector_id) is not None

Try / catch

try:
    vs.update(vector_id, payload=p)
except ValueError as e:
    if 'not found' in str(e):
        vs.insert([vec], [p], [vector_id])  # upsert fallback
    else:
        raise

Prevention

When it happens

Trigger: Updating an id after it was deleted in the same session (delete rebuilds index_to_id and removes the docstore entry); stale ids cached in application memory; ids from a different collection/user scope.

Common situations: Race between delete and update in concurrent workers; multi-tenant stores where the id exists for another user_id; retrying an update after the record was garbage-collected.

Related errors


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