{"record":{"id":"59fefdcc750aeb11","repo":"mem0ai/mem0","slug":"invalid-memory-action-memory-action","errorCode":null,"errorMessage":"Invalid memory action: {memory_action}","messagePattern":"Invalid memory action: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mem0/embeddings/vertexai.py","lineNumber":57,"sourceCode":"                    \"Google application credentials JSON is not provided. Please provide a valid JSON path or set the 'GOOGLE_APPLICATION_CREDENTIALS' environment variable.\"\n                )\n\n        self.model = TextEmbeddingModel.from_pretrained(self.config.model)\n\n    def embed(self, text, memory_action: Optional[Literal[\"add\", \"search\", \"update\"]] = None):\n        \"\"\"\n        Get the embedding for the given text using Vertex AI.\n\n        Args:\n            text (str): The text to embed.\n            memory_action (optional): The type of embedding to use. Must be one of \"add\", \"search\", or \"update\". Defaults to None.\n        Returns:\n            list: The embedding vector.\n        \"\"\"\n        embedding_type = \"SEMANTIC_SIMILARITY\"\n        if memory_action is not None:\n            if memory_action not in self.embedding_types:\n                raise ValueError(f\"Invalid memory action: {memory_action}\")\n\n            embedding_type = self.embedding_types[memory_action]\n\n        text_input = TextEmbeddingInput(text=text, task_type=embedding_type)\n        embeddings = self.model.get_embeddings(texts=[text_input], output_dimensionality=self.config.embedding_dims)\n\n        return embeddings[0].values\n\n    def embed_batch(self, texts, memory_action=\"add\"):\n        if not texts:\n            return []\n        embedding_type = \"SEMANTIC_SIMILARITY\"\n        if memory_action is not None:\n            if memory_action not in self.embedding_types:\n                raise ValueError(f\"Invalid memory action: {memory_action}\")\n            embedding_type = self.embedding_types[memory_action]\n        all_embeddings = []\n        for i in range(0, len(texts), 250):","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/embeddings/vertexai.py#L39-L75","documentation":"Raised by VertexAIEmbedding.embed when memory_action is a value not in the class's embedding_types mapping (which maps mem0 actions like 'add'/'search' to Vertex task types such as RETRIEVAL_DOCUMENT/QUESTION_ANSWERING). Passing None is allowed (defaults to SEMANTIC_SIMILARITY); any other unknown string is rejected before the API call.","triggerScenarios":"Calling embed(text, memory_action=\"delete\") or a custom string; a mem0-internal caller passing a new action type this provider never mapped; user code invoking the embedder directly with an arbitrary label.","commonSituations":"Direct use of VertexAIEmbedding outside Memory; version skew where a newer mem0 passes an action this provider version does not know; typos in the action string.","solutions":["Pass only None or the actions defined in the provider's embedding_types mapping (add, search, update)","Upgrade mem0 so the provider's mapping matches the actions used by the memory layer","If you call embed() directly for generic embedding, omit memory_action entirely"],"exampleFix":"// before\nvec = embedder.embed(\"hello\", memory_action=\"index\")  # ValueError\n\n# after\nvec = embedder.embed(\"hello\", memory_action=\"add\")\n# or omit: vec = embedder.embed(\"hello\")","handlingStrategy":"validation","validationCode":"VALID_ACTIONS = {None, \"add\", \"search\", \"update\"}  # provider's embedding_types keys\nassert memory_action in VALID_ACTIONS, f\"unsupported memory_action: {memory_action!r}\"","typeGuard":"from typing import Optional\n\nVALID_ACTIONS = {\"add\", \"search\", \"update\"}\n\ndef is_valid_action(a) -> bool:\n    return a is None or a in VALID_ACTIONS","tryCatchPattern":"try:\n    vec = embedder.embed(text, memory_action=action)\nexcept ValueError as e:\n    if \"Invalid memory action\" in str(e):\n        vec = embedder.embed(text)  # fall back to default task type\n    else:\n        raise","preventionTips":["Treat memory_action as an enum, not free text","Let Memory handle the action; pass None when calling embed directly","Upgrade mem0 core and providers together so action vocabularies match"],"tags":["python","vertexai","embeddings","validation","mem0"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}