mem0ai/mem0 · critical · Error

${context} dimension mismatch. Expected ${this.dimension}, g

Error message

${context} dimension mismatch. Expected ${this.dimension}, got ${vector.length}

What it means

The Neptune Analytics store validates every vector's length against the configured dimension (set at construction from the embedding config) before writing or querying. Neptune vectors are fixed-dimension; a mismatch would produce a hard AWS-side failure, so the client fails fast with the expected/got lengths.

Source

Thrown at mem0-ts/src/oss/src/vector_stores/neptune_analytics.ts:949

        .join(", ")} }`;
    }

    throw new Error(
      `Unsupported Neptune Analytics algorithm value type: ${typeof value}`,
    );
  }

  private serializeAlgorithmKey(key: string): string {
    if (/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) {
      return key;
    }

    return JSON.stringify(key);
  }

  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 normalizeNodeResult(record: NeptuneQueryRecord): VectorStoreResult {
    const node = this.extractNode(record);
    const payload = this.normalizePayload(this.extractPayload(node));

    return {
      id: this.extractId(node, record),
      payload,

View on GitHub (pinned to 001c235229)

Solutions

  1. Use the same embedding model (and thus dimension) for writes and searches, and set that dimension in the vector store config.
  2. If you changed embedding models, create a new Neptune graph/index sized for the new dimension and re-embed existing memories.
  3. Verify with vector.length before insert when ingesting pre-computed embeddings.

Example fix

// before
const store = new NeptuneAnalytics({ dimension: 1536 });
await store.insert([vec386dims], ...); // 384-dim model output

// after
const store = new NeptuneAnalytics({ dimension: 384 });
await store.insert([vec384dims], ...);
Defensive patterns

Strategy: validation

Validate before calling

if (vector.length !== store.dimension) {
  throw new Error(`Embedding dim ${vector.length} != store dim ${store.dimension}`);
}

Type guard

const hasDim = (v: number[], d: number): v is number[] & { length: d } => v.length === d;

Try / catch

catch (e) { if (e.message.includes('dimension mismatch')) { /* reconfigure store dimension or re-embed */ } }

Prevention

When it happens

Trigger: Calling add/insert/update with vectors from an embedding model whose dimension differs from the store's configured dimension (e.g. 384-dim MiniLM vectors into a 1536-dim store), or searching with a query embedded by a different model.

Common situations: Switching embedding providers (OpenAI ada-002 1536 -> text-embedding-3-small also 1536 vs 3-large 3072, or to a local model) without recreating the Neptune vector index; mixing models between write and search paths; stale config after model upgrade.

Related errors


AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15). Data as JSON: /api/errors/d5aa40cfdd1e62d5. Report an issue: GitHub.