{"record":{"id":"1df58a2cc2c69c6b","repo":"mem0ai/mem0","slug":"failed-to-insert-vectors-error-instanceof-error","errorCode":null,"errorMessage":"Failed to insert vectors: ${error instanceof Error ? error.message : String(error)}","messagePattern":"Failed to insert vectors: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/vector_stores/vectorize.ts","lineNumber":84,"sourceCode":"        {\n          method: \"POST\",\n          headers: {\n            \"Content-Type\": \"application/x-ndjson\",\n            Authorization: `Bearer ${this.client?.apiToken}`,\n          },\n          body: ndjsonPayload,\n        },\n      );\n\n      if (!response.ok) {\n        const errorText = await response.text();\n        throw new Error(\n          `Failed to insert vectors: ${response.status} ${errorText}`,\n        );\n      }\n    } catch (error) {\n      console.error(\"Error inserting vectors:\", error);\n      throw new Error(\n        `Failed to insert vectors: ${error instanceof Error ? error.message : String(error)}`,\n      );\n    }\n  }\n\n  async keywordSearch(): Promise<null> {\n    return null;\n  }\n\n  async search(\n    query: number[],\n    topK: number = 5,\n    filters?: SearchFilters,\n  ): Promise<VectorStoreResult[]> {\n    await this.initialize();\n    try {\n      const result = await this.client?.vectorize.indexes.query(\n        this.indexName,","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/vector_stores/vectorize.ts#L66-L102","documentation":"Generic catch wrapper around the Vectorize insert path: any thrown error (including the non-ok HTTP error, network failure, or TypeError while building the request) is logged and rethrown wrapped as 'Failed to insert vectors: <message>'. The inner message identifies the real cause — treat this as the outer envelope of error 313 plus network/serialization failures.","triggerScenarios":"Any exception during memory.add() on Cloudflare Vectorize: DNS/network failure reaching api.cloudflare.com, a fetch TypeError, an expired token producing 401 from the inner throw, or a dimension mismatch surfaced through the inner error.","commonSituations":"Transient network issues in serverless environments; expired or rotated Cloudflare API tokens; intermittent Cloudflare API 5xx responses.","solutions":["Inspect the wrapped message — it contains the underlying cause; apply the matching fix (auth, index name, dimensions).","For transient network/5xx causes, retry the add operation with backoff (idempotent if you control the memory id).","Rotate the API token if the inner message indicates 401/invalid credentials."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"const isTransient = (m: string) => /timeout|ECONNRESET|5\\d\\d/.test(m);\ntry { await memory.add(text); } catch (e) { const m = e instanceof Error ? e.message : String(e); if (m.startsWith('Failed to insert vectors:') && isTransient(m)) await retryWithBackoff(() => memory.add(text), 3); else throw e; }","preventionTips":["Distinguish inner cause before retrying — auth/dimension errors are permanent","Log the wrapped message verbatim for diagnosis","Use idempotent ids for add() so retries are safe"],"tags":["cloudflare","vectorize","insert","error-wrapping"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}