{"record":{"id":"f8549e1745e4efb8","repo":"mem0ai/mem0","slug":"embeddingmodeldims-or-dimension-is-required","errorCode":null,"errorMessage":"embeddingModelDims or dimension is required","messagePattern":"embeddingModelDims or dimension is required","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"mem0-ts/src/oss/src/vector_stores/s3_vectors.ts","lineNumber":57,"sourceCode":"  private readonly dimension: number;\n  private readonly distanceMetric: \"cosine\" | \"euclidean\";\n  private client?: S3VectorsClientLike;\n  private clientPromise?: Promise<S3VectorsClientLike>;\n  private sdkPromise?: Promise<any>;\n  private _initPromise?: Promise<void>;\n  private cachedUserId?: string;\n\n  constructor(config: S3VectorsConfig) {\n    if (!config.vectorBucketName) {\n      throw new Error(\"vectorBucketName is required\");\n    }\n    if (!config.collectionName) {\n      throw new Error(\"collectionName is required\");\n    }\n\n    const dimension = config.embeddingModelDims ?? config.dimension;\n    if (!dimension || dimension < 1) {\n      throw new Error(\"embeddingModelDims or dimension is required\");\n    }\n\n    this.config = config;\n    this.vectorBucketName = config.vectorBucketName;\n    this.collectionName = config.collectionName;\n    this.dimension = dimension;\n    this.distanceMetric = config.distanceMetric || \"cosine\";\n\n    void this.initialize().catch(console.error);\n  }\n\n  /**\n   * Lazily import the optional `@aws-sdk/client-s3vectors` peer so consumers\n   * who never use the S3 Vectors store don't need it installed.\n   */\n  private getSdk(): Promise<any> {\n    if (!this.sdkPromise) {\n      this.sdkPromise = import(\"@aws-sdk/client-s3vectors\").catch(() => {","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/vector_stores/s3_vectors.ts#L39-L75","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass dimension: 1536 (or your model's dimension) explicitly in the store config","Or pass embeddingModelDims so it matches the embedding model actually used for add/search","Ensure the value is a positive integer, not a string or zero"],"exampleFix":"// before\nconst vs = new S3Vectors({ vectorBucketName: 'b', collectionName: 'c' });\n\n// after\nconst vs = new S3Vectors({\n  vectorBucketName: 'b',\n  collectionName: 'c',\n  dimension: 1536,\n});","handlingStrategy":"validation","validationCode":"function assertDimension(c: any): void {\n  const d = c?.embeddingModelDims ?? c?.dimension;\n  if (!d || d < 1) throw new Error('dimension must be a positive integer');\n}\nassertDimension(config);","typeGuard":"const isValidDimension = (d: unknown): d is number =>\n  typeof d === 'number' && Number.isInteger(d) && d >= 1;","tryCatchPattern":"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; }","preventionTips":["Pass dimension from the embedding provider config, not hand-typed literals scattered in code","Record the dimension alongside the model name in one config constant","Validate that dimension is a positive integer in config loading"],"tags":["s3-vectors","aws","embedding-dimension","configuration","typescript"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}