{"record":{"id":"5f3628f8c3f19780","repo":"mem0ai/mem0","slug":"insert-failed-for-document-result-key-result","errorCode":null,"errorMessage":"Insert failed for document ${result.key}: ${result.errorMessage}","messagePattern":"Insert failed for document (.+?): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/vector_stores/azure_ai_search.ts","lineNumber":296,"sourceCode":"    vectors: number[][],\n    ids: string[],\n    payloads: Record<string, any>[],\n  ): Promise<void> {\n    await this.initialize();\n    console.log(\n      `Inserting ${vectors.length} vectors into index ${this.indexName}`,\n    );\n\n    const documents = vectors.map((vector, idx) =>\n      this.generateDocument(vector, payloads[idx] || {}, ids[idx]),\n    );\n\n    const response = await this.searchClient.uploadDocuments(documents);\n\n    // Check for errors\n    for (const result of response.results) {\n      if (!result.succeeded) {\n        throw new Error(\n          `Insert failed for document ${result.key}: ${result.errorMessage}`,\n        );\n      }\n    }\n  }\n\n  /**\n   * Sanitize filter keys to remove non-alphanumeric characters\n   */\n  private sanitizeKey(key: string): string {\n    return key.replace(/[^\\w]/g, \"\");\n  }\n\n  /**\n   * Build OData filter expression from SearchFilters\n   */\n  private buildFilterExpression(filters: SearchFilters): string {\n    const filterConditions: string[] = [];","sourceCodeStart":278,"sourceCodeEnd":314,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/vector_stores/azure_ai_search.ts#L278-L314","documentation":"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.","triggerScenarios":"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.","commonSituations":"Switching embedding models without recreating the index; index created manually with different field names than generateDocument produces; hitting Azure partition throttles during bulk loads.","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."],"exampleFix":"// before\nvectorStore: { provider: 'azure_ai_search', config: { embeddingModelDims: 1536 } } // index built for 3072\n// after\nvectorStore: { provider: 'azure_ai_search', config: { embeddingModelDims: 3072 } }","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await memory.add(text, { userId });\n} catch (e) {\n  const m = e instanceof Error ? e.message : '';\n  if (/Insert failed for document/.test(m)) {\n    if (/dimension|vector/i.test(m)) throw new Error('Index dimension mismatch — recreate index or fix embeddingModelDims');\n    await backoffRetry(() => memory.add(text, { userId }), 3); // throttling/transient\n  } else throw e;\n}","preventionTips":["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."],"tags":["azure","vector-store","partial-failure","schema-mismatch"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}