mem0ai/mem0 · error · Error
Failed to insert vectors: ${response.status} ${errorText}
Error message
Failed to insert vectors: ${response.status} ${errorText} What it means
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).
Source
Thrown at mem0-ts/src/oss/src/vector_stores/vectorize.ts:78
const ndjsonPayload = vectorObjects
.map((v) => JSON.stringify(v))
.join("\n");
const response = await fetch(
`https://api.cloudflare.com/client/v4/accounts/${this.accountId}/vectorize/v2/indexes/${this.indexName}/insert`,
{
method: "POST",
headers: {
"Content-Type": "application/x-ndjson",
Authorization: `Bearer ${this.client?.apiToken}`,
},
body: ndjsonPayload,
},
);
if (!response.ok) {
const errorText = await response.text();
throw new Error(
`Failed to insert vectors: ${response.status} ${errorText}`,
);
}
} catch (error) {
console.error("Error inserting vectors:", error);
throw new Error(
`Failed to insert vectors: ${error instanceof Error ? error.message : String(error)}`,
);
}
}
async keywordSearch(): Promise<null> {
return null;
}
async search(
query: number[],
topK: number = 5,View on GitHub (pinned to 001c235229)
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.
Example fix
# before (index created with wrong dims) wrangler vectorize create memories --dimensions 768 # after wrangler vectorize create memories --dimensions 1536 --metric cosine
Defensive patterns
Strategy: try-catch
Validate before calling
if (vectors.some(v => v.length !== indexDims)) throw new Error(`Vector dims must equal index dims (${indexDims})`);
if (!accountId || !indexName) throw new Error('accountId and indexName are required for Vectorize'); Try / catch
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; } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Failed to update vector: ${response.status} ${errorText}
- HTTP ${resp.status}: ${detail}
- HTTP error! status: ${response.status}
- Failed to insert vectors: ${error instanceof Error ? error.m
- Failed to search vectors: ${error instanceof Error ? error.m
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/f064a661d593e970.
Report an issue: GitHub.