{"record":{"id":"d550e13231a72abd","repo":"mem0ai/mem0","slug":"failed-to-delete-vector-error-instanceof-error","errorCode":null,"errorMessage":"Failed to delete vector: ${error instanceof Error ? error.message : String(error)}","messagePattern":"Failed to delete vector: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/vector_stores/vectorize.ts","lineNumber":200,"sourceCode":"      }\n    } catch (error) {\n      console.error(\"Error updating vector:\", error);\n      throw new Error(\n        `Failed to update vector: ${error instanceof Error ? error.message : String(error)}`,\n      );\n    }\n  }\n\n  async delete(vectorId: string): Promise<void> {\n    await this.initialize();\n    try {\n      await this.client?.vectorize.indexes.deleteByIds(this.indexName, {\n        account_id: this.accountId,\n        ids: [vectorId],\n      });\n    } catch (error) {\n      console.error(\"Error deleting vector:\", error);\n      throw new Error(\n        `Failed to delete vector: ${error instanceof Error ? error.message : String(error)}`,\n      );\n    }\n  }\n\n  async deleteCol(): Promise<void> {\n    await this.initialize();\n    try {\n      await this.client?.vectorize.indexes.delete(this.indexName, {\n        account_id: this.accountId,\n      });\n    } catch (error) {\n      console.error(\"Error deleting collection:\", error);\n      throw new Error(\n        `Failed to delete collection: ${error instanceof Error ? error.message : String(error)}`,\n      );\n    }\n  }","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/vector_stores/vectorize.ts#L182-L218","documentation":"Catch-all around Cloudflare Vectorize deleteByIds: deleting a vector by id failed and the error is rethrown wrapped as 'Failed to delete vector: <message>'. Missing ids do not error in Vectorize — this throw means the API call failed (auth, wrong index/account, network).","triggerScenarios":"memory.delete(id) with a token lacking delete permission; indexName/accountId mismatch; Cloudflare API or network failure; the index having been purged/recreated.","commonSituations":"Least-privilege tokens missing the delete scope; stale indexName after recreation; transient 5xx.","solutions":["Check the inner message: 401/403 -> grant the token full Vectorize edit permission; 404 -> verify indexName and accountId.","Retry transient network/5xx failures.","If the goal is a full reset, deleteAll/deleteCol recreates state cleanly instead of per-id deletes."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { await memory.delete(id); } catch (e) { const m = e instanceof Error ? e.message : ''; if (m.startsWith('Failed to delete vector:')) { if (isTransientInner(m)) await retryWithBackoff(() => memory.delete(id), 2); else throw new Error(`Vectorize delete failed: ${m}`); } else throw e; }","preventionTips":["Deleting a non-existent id does not throw — only API failures do","Include delete scope in the token","Use deleteAll for full resets instead of looping deletes"],"tags":["cloudflare","vectorize","delete","permissions"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}