{"record":{"id":"f064a661d593e970","repo":"mem0ai/mem0","slug":"failed-to-insert-vectors-response-status-err","errorCode":null,"errorMessage":"Failed to insert vectors: ${response.status} ${errorText}","messagePattern":"Failed to insert vectors: (.+?) (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/vector_stores/vectorize.ts","lineNumber":78,"sourceCode":"      const ndjsonPayload = vectorObjects\n        .map((v) => JSON.stringify(v))\n        .join(\"\\n\");\n\n      const response = await fetch(\n        `https://api.cloudflare.com/client/v4/accounts/${this.accountId}/vectorize/v2/indexes/${this.indexName}/insert`,\n        {\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,","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/vector_stores/vectorize.ts#L60-L96","documentation":"The Cloudflare Vectorize store inserts vectors by POSTing an NDJSON payload to the Cloudflare API. When the HTTP response is not ok, it throws with the status code and response body — common causes are 400 (bad payload/dimension), 401 (bad API token), 404 (unknown index or account_id).","triggerScenarios":"memory.add() / store.insert() with an accountId that doesn't exist, an indexName not created in the Cloudflare dashboard, an API token lacking Vectorize permissions, or vectors whose dimension mismatches the index's dims.","commonSituations":"Index created with dims=768 but OpenAI embeddings (1536) used; wrong account_id copied from dashboard URL; token scoped to a different zone/account; index deleted and recreated under a new name.","solutions":["Read the status + errorText: 401/403 -> fix the API token and its Vectorize permission scope; 404 -> verify accountId and indexName exactly match the dashboard; 400 -> check vector dimensions match the index configuration.","Recreate the Vectorize index with dimensions equal to your embedding model output (e.g. wrangler vectorize create memories --dimensions 1536 --metric cosine).","Confirm this.accountId is the hex account ID, not the account name."],"exampleFix":"# before (index created with wrong dims)\nwrangler vectorize create memories --dimensions 768\n\n# after\nwrangler vectorize create memories --dimensions 1536 --metric cosine","handlingStrategy":"try-catch","validationCode":"if (vectors.some(v => v.length !== indexDims)) throw new Error(`Vector dims must equal index dims (${indexDims})`);\nif (!accountId || !indexName) throw new Error('accountId and indexName are required for Vectorize');","typeGuard":null,"tryCatchPattern":"try { await memory.add(text); } catch (e) { if (e instanceof Error && e.message.startsWith('Failed to insert vectors: ')) { const [status] = e.message.split(' ').slice(3); if (status === '404') fixIndexName(); else if (status === '401') fixToken(); else checkDims(); } else throw e; }","preventionTips":["Create the index with dimensions matching the embedder before first write","Verify accountId (hex) and token scopes in the Cloudflare dashboard","Assert vector length equals index dims before insert"],"tags":["cloudflare","vectorize","http","api","dimensions"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}