mem0ai/mem0 · error · Error
Vector at index ${index} is empty. Expected dimension ${this
Error message
Vector at index ${index} is empty. Expected dimension ${this.embeddingModelDims}. What it means
Before inserting into OpenSearch, each vector is checked for a non-zero length. An empty array means the embedding call returned no components (for example an empty-string input or a broken provider response), and OpenSearch would reject the document with a less clear mapping error, so the store raises this explicit message naming the index position and expected dimension.
Source
Thrown at mem0-ts/src/oss/src/vector_stores/opensearch.ts:216
await this.client.indices.create({
index: "memory_migrations",
body: {
mappings: {
properties: {
user_id: { type: "keyword" },
},
},
},
});
}
private validateVector(vector: number[], index: number): void {
if (!vector) {
throw new Error(`Vector at index ${index} is null or undefined.`);
}
if (vector.length === 0) {
throw new Error(
`Vector at index ${index} is empty. Expected dimension ${this.embeddingModelDims}.`,
);
}
if (vector.length !== this.embeddingModelDims) {
throw new Error(
`Vector at index ${index} has dimension ${vector.length}, but index ` +
`'${this.collectionName}' expects dimension ${this.embeddingModelDims}.`,
);
}
}
async insert(
vectors: number[][],
ids: string[],
payloads: Record<string, any>[],
): Promise<void> {
await this.initialize();
vectors.forEach((vector, index) => this.validateVector(vector, index));View on GitHub (pinned to 001c235229)
Solutions
- Skip or reject empty documents before embedding so providers never receive them.
- Validate embedding responses: if emb.length === 0 throw or retry at the embedding layer.
- Log the failing index from the message and inspect that input document.
Example fix
// before
const embs = docs.map(d => embed(d)); // some empty string -> []
await store.insert(embs, ids, payloads);
// after
const embs = docs.map(d => d.trim() ? embed(d) : null);
if (embs.some(e => !e || e.length === 0)) throw new Error('empty embedding'); Defensive patterns
Strategy: validation
Validate before calling
if (vectors.some((v) => Array.isArray(v) && v.length === 0)) {
throw new Error('Empty embedding vector produced; check embedding inputs');
} Type guard
const isNonEmptyVector = (v: unknown): v is number[] => Array.isArray(v) && v.length > 0;
Prevention
- Skip empty/whitespace documents before embedding
- Assert embedding response length matches the model dimension
- Fail loudly at the embedding layer
When it happens
Trigger: Passing vectors[i] === [] — e.g. an embedding provider returned an empty vector for an empty/whitespace document, or a placeholder was never filled.
Common situations: Embedding empty strings or skipped documents; test fixtures with empty arrays; providers that return [] on rate-limit or content-filter instead of throwing.
Related errors
- Vector at index ${index} is null or undefined.
- Unknown embedder provider: ${providerId}
- Langchain embedder provider requires an initialized Langchai
- Provided Langchain 'instance' in the 'model' field does not
- Invalid memory action: ${memoryAction}
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/fa2bb4d691f8950e.
Report an issue: GitHub.