mem0ai/mem0 · error · Error
${context} dimension mismatch. Expected ${this.dimension}, g
Error message
${context} dimension mismatch. Expected ${this.dimension}, got ${vector.length} What it means
Every vector written to or queried against the S3 Vectors index must have exactly this.dimension components (fixed by the embedding model / index creation). assertVectorDimension throws with the failing context (e.g. insert, query) when a vector's length differs, protecting the index from corrupt data and AWS-side rejects.
Source
Thrown at mem0-ts/src/oss/src/vector_stores/s3_vectors.ts:862
private normalizeScore(
distance?: number,
distanceMetric: "cosine" | "euclidean" = this.distanceMetric,
): number | undefined {
if (distance === undefined || distance === null) {
return undefined;
}
if (!Number.isFinite(distance)) {
return undefined;
}
if (distanceMetric === "euclidean") {
return 1 / (1 + distance);
}
return Math.max(0, Math.min(1, 1 - distance));
}
private assertVectorDimension(vector: number[], context: string): void {
if (vector.length !== this.dimension) {
throw new Error(
`${context} dimension mismatch. Expected ${this.dimension}, got ${vector.length}`,
);
}
}
private assertBatchDimensions(vectors: number[][], context: string): void {
for (const vector of vectors) {
this.assertVectorDimension(vector, context);
}
}
private isNotFound(error: any): boolean {
return error?.name === "NotFoundException";
}
private isConflict(error: any): boolean {
return error?.name === "ConflictException";
}View on GitHub (pinned to 001c235229)
Solutions
- Align the embedding model and embeddingModelDims config with the dimension the index was created with, then recreate the collection if the model changed.
- If you supply vectors yourself, verify vector.length === configured dimension before calling add/search.
- Re-index existing memories with the new embedding model into a fresh collection.
Example fix
// before
const memory = new Memory({ vectorStore: { provider: 's3_vectors', config: { embeddingModelDims: 1536 } }, embedder: new OpenAIEmbedding({ model: 'text-embedding-3-large' }) }); // 3072-dim model
// after
const memory = new Memory({ vectorStore: { provider: 's3_vectors', config: { embeddingModelDims: 3072 } }, embedder: new OpenAIEmbedding({ model: 'text-embedding-3-large' }) }); Defensive patterns
Strategy: type-guard
Validate before calling
const expected = storeConfig.embeddingModelDims;
if (vector.length !== expected) throw new Error(`Vector has ${vector.length} dims, index expects ${expected}; re-embed or recreate index`); Type guard
function isCorrectDimension(vector: number[], dims: number): vector is number[] & { length: dims } {
return Array.isArray(vector) && vector.length === dims;
} Try / catch
try { await memory.add(text, { embeddingVector }); } catch (e) { if (e instanceof Error && e.message.includes('dimension mismatch')) { /* re-embed with the configured model or recreate index */ } else throw e; } Prevention
- Pin embeddingModelDims to the model's actual output
- Recreate the collection when switching embedders
- Add a startup assert comparing a sample embedding's length to the config
When it happens
Trigger: Calling add/search with a custom embedding whose dimension differs from the index; switching embedding models (e.g. text-embedding-3-small 1536 -> bge 768) without recreating the S3 Vectors index/collection; mixing manually supplied vectors with model-generated ones.
Common situations: Changing the embedder config after data was already indexed; using embeddingModelDims that doesn't match the actual model output; passing truncated or padded vectors from a custom pipeline.
Related errors
- Unknown embedder provider: ${providerId}
- Azure OpenAI requires both API key and endpoint
- Unsupported FastEmbed model "${config.model}". Supported mod
- HuggingFace embedder requires an inference endpoint. Set `hu
- Langchain embedder provider requires an initialized Langchai
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/3806f9dc397d782d.
Report an issue: GitHub.