mem0ai/mem0 · error · Error
Insert failed for document ${result.key}: ${result.errorMess
Error message
Insert failed for document ${result.key}: ${result.errorMessage} What it means
After uploadDocuments() on the Azure AI Search index, the insert path iterates response.results and throws for the first document whose result.succeeded is false, embedding the document key and the service's errorMessage. Azure AI Search returns per-document partial success inside a 200 response, so this is the only place a failed row is detected. Typical causes are index schema mismatches, oversized vectors, or throttling reported per document.
Source
Thrown at mem0-ts/src/oss/src/vector_stores/azure_ai_search.ts:296
vectors: number[][],
ids: string[],
payloads: Record<string, any>[],
): Promise<void> {
await this.initialize();
console.log(
`Inserting ${vectors.length} vectors into index ${this.indexName}`,
);
const documents = vectors.map((vector, idx) =>
this.generateDocument(vector, payloads[idx] || {}, ids[idx]),
);
const response = await this.searchClient.uploadDocuments(documents);
// Check for errors
for (const result of response.results) {
if (!result.succeeded) {
throw new Error(
`Insert failed for document ${result.key}: ${result.errorMessage}`,
);
}
}
}
/**
* Sanitize filter keys to remove non-alphanumeric characters
*/
private sanitizeKey(key: string): string {
return key.replace(/[^\w]/g, "");
}
/**
* Build OData filter expression from SearchFilters
*/
private buildFilterExpression(filters: SearchFilters): string {
const filterConditions: string[] = [];View on GitHub (pinned to 001c235229)
Solutions
- Read result.errorMessage in the thrown text: a dimension mismatch means recreate the index with the new embedding dimension (update embeddingModelDims config to match the index).
- Ensure the index schema matches the documents generateDocument() emits (id, vector, payload fields, user_id/run_id/agent_id).
- Retry the insert after transient throttling; reduce batch size for bulk loads.
Example fix
// before
vectorStore: { provider: 'azure_ai_search', config: { embeddingModelDims: 1536 } } // index built for 3072
// after
vectorStore: { provider: 'azure_ai_search', config: { embeddingModelDims: 3072 } } Defensive patterns
Strategy: retry
Try / catch
try {
await memory.add(text, { userId });
} catch (e) {
const m = e instanceof Error ? e.message : '';
if (/Insert failed for document/.test(m)) {
if (/dimension|vector/i.test(m)) throw new Error('Index dimension mismatch — recreate index or fix embeddingModelDims');
await backoffRetry(() => memory.add(text, { userId }), 3); // throttling/transient
} else throw e;
} Prevention
- Set embeddingModelDims to the index's actual vector dimension before first insert.
- Smoke-test one insert after creating or recreating an index.
- Keep batch sizes moderate to avoid per-document throttling on low tiers.
When it happens
Trigger: insert() with a vector whose dimension does not match the index's vector field configuration; payload fields that do not fit the index schema; document too large; 503/throttling surfaced on an individual document.
Common situations: Switching embedding models without recreating the index; index created manually with different field names than generateDocument produces; hitting Azure partition throttles during bulk loads.
Related errors
- Delete failed for document ${vectorId}: ${result.errorMessag
- Update failed for document ${vectorId}: ${result.errorMessag
- Insert failed for document {doc.get('id')}: {doc}
- Update failed for document {vector_id}: {doc}
- Baidu Mochow table '${label}' exists but is missing the id/d
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/5f3628f8c3f19780.
Report an issue: GitHub.