mem0ai/mem0 · critical · Error

embeddingModelDims or dimension is required

Error message

embeddingModelDims or dimension is required

What it means

The S3 Vectors store needs the vector dimension at construction (embeddingModelDims or dimension). A missing, zero, negative, or non-numeric dimension throws, because S3 Vectors indexes are dimension-fixed and every subsequent put/query depends on it.

Source

Thrown at mem0-ts/src/oss/src/vector_stores/s3_vectors.ts:57

  private readonly dimension: number;
  private readonly distanceMetric: "cosine" | "euclidean";
  private client?: S3VectorsClientLike;
  private clientPromise?: Promise<S3VectorsClientLike>;
  private sdkPromise?: Promise<any>;
  private _initPromise?: Promise<void>;
  private cachedUserId?: string;

  constructor(config: S3VectorsConfig) {
    if (!config.vectorBucketName) {
      throw new Error("vectorBucketName is required");
    }
    if (!config.collectionName) {
      throw new Error("collectionName is required");
    }

    const dimension = config.embeddingModelDims ?? config.dimension;
    if (!dimension || dimension < 1) {
      throw new Error("embeddingModelDims or dimension is required");
    }

    this.config = config;
    this.vectorBucketName = config.vectorBucketName;
    this.collectionName = config.collectionName;
    this.dimension = dimension;
    this.distanceMetric = config.distanceMetric || "cosine";

    void this.initialize().catch(console.error);
  }

  /**
   * Lazily import the optional `@aws-sdk/client-s3vectors` peer so consumers
   * who never use the S3 Vectors store don't need it installed.
   */
  private getSdk(): Promise<any> {
    if (!this.sdkPromise) {
      this.sdkPromise = import("@aws-sdk/client-s3vectors").catch(() => {

View on GitHub (pinned to 001c235229)

Solutions

  1. Pass dimension: 1536 (or your model's dimension) explicitly in the store config
  2. Or pass embeddingModelDims so it matches the embedding model actually used for add/search
  3. Ensure the value is a positive integer, not a string or zero

Example fix

// before
const vs = new S3Vectors({ vectorBucketName: 'b', collectionName: 'c' });

// after
const vs = new S3Vectors({
  vectorBucketName: 'b',
  collectionName: 'c',
  dimension: 1536,
});
Defensive patterns

Strategy: validation

Validate before calling

function assertDimension(c: any): void {
  const d = c?.embeddingModelDims ?? c?.dimension;
  if (!d || d < 1) throw new Error('dimension must be a positive integer');
}
assertDimension(config);

Type guard

const isValidDimension = (d: unknown): d is number =>
  typeof d === 'number' && Number.isInteger(d) && d >= 1;

Try / catch

try { const vs = new S3Vectors(config); } catch (e) { if (e instanceof Error && e.message.includes('embeddingModelDims or dimension')) { /* pass correct dims, not retryable */ } throw e; }

Prevention

When it happens

Trigger: Constructing with neither embeddingModelDims nor dimension; passing dimension: 0 or a negative number; passing a string dimension like '1536' that fails the < 1 numeric check via coercion; forgetting to pass the embedding model config from the parent Memory instance.

Common situations: Using the store standalone without the embedding model context that normally supplies embeddingModelDims; switching embedding providers and dropping the dims field; config assembled from multiple sources where the dims key was lost.

Related errors


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