{"record":{"id":"8d22f520a1f948cc","repo":"immich-app/immich","slug":"could-not-retrieve-dimension-size-of-column-column-in-table","errorCode":null,"errorMessage":"Could not retrieve dimension size of column '${column}' in table '${table}', assuming 512","messagePattern":"Could not retrieve dimension size of column '(.+?)' in table '(.+?)', assuming 512","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"server/src/repositories/database.repository.ts","lineNumber":314,"sourceCode":"    const { rows } = await sql<{ dimsize: number }>`\n      SELECT atttypmod as dimsize\n      FROM pg_attribute f\n        JOIN pg_class c ON c.oid = f.attrelid\n      WHERE c.relkind = 'r'::char\n        AND f.attnum > 0\n        AND c.relname = ${table}::text\n        AND f.attname = ${column}::text\n    `.execute(this.db);\n\n    const dimSize = rows[0]?.dimsize;\n    if (\n      !z\n        .int()\n        .min(1)\n        .max(2 ** 16)\n        .safeParse(dimSize).success\n    ) {\n      this.logger.warn(`Could not retrieve dimension size of column '${column}' in table '${table}', assuming 512`);\n      return 512;\n    }\n    return dimSize;\n  }\n\n  async setDimensionSize(dimSize: number): Promise<void> {\n    if (\n      !z\n        .int()\n        .min(1)\n        .max(2 ** 16)\n        .safeParse(dimSize).success\n    ) {\n      throw new Error(`Invalid CLIP dimension size: ${dimSize}`);\n    }\n\n    // this is done in two transactions to handle concurrent writes\n    await this.db.transaction().execute(async (trx) => {","sourceCodeStart":296,"sourceCodeEnd":332,"githubUrl":"https://github.com/immich-app/immich/blob/e55ac299a4ec7cb372e35dbf2c6c05ee9ce77f6c/server/src/repositories/database.repository.ts#L296-L332","documentation":"getDimensionSize reads the embedding column's dimension from the database (e.g. via pgvector's typmod or a constraint). If the value cannot be retrieved or fails validation (must be an integer 1..65536), the code logs this warning and assumes a dimension of 512. A wrong assumption here can cause dimension mismatches during embedding operations.","triggerScenarios":"Querying the dimension of a column in smart_search/face_search returns null, or a value outside 1..2**16 — e.g. the embedding column is still real[] without a dim constraint, or the pgvector column attribute could not be parsed.","commonSituations":"Fresh table where embedding was added as plain real[] (see reindex path); migrations not fully applied; querying a non-vector column; broken pgvector installation.","solutions":["Run migrations and the vector-extension reindex flow so the embedding column has the proper dim_size_constraint","Check the constraint: SELECT conname, pg_get_constraintdef(oid) FROM pg_constraint WHERE conrelid = 'smart_search'::regclass;","Set the dimension explicitly via the admin settings (which calls setDimensionSize) matching your CLIP model (512 for ViT-B-32)","Verify pgvector extension is installed: CREATE EXTENSION IF NOT EXISTS vectors;"],"exampleFix":"// before (column without dimension)\nembedding real[]\n// after\nALTER TABLE smart_search ADD CONSTRAINT dim_size_constraint CHECK (array_length(embedding::real[], 1) = 512);\n-- or let migrations define embedding vector(512)","handlingStrategy":"fallback","validationCode":"const { rows } = await sql`\n  SELECT atttypmod AS dim FROM pg_attribute\n  WHERE attrelid = 'smart_search'::regclass AND attname = 'embedding'`.execute(db);\nconst dim = Number(rows[0]?.dim);\nif (!Number.isInteger(dim) || dim < 1 || dim > 65536) {\n  throw new Error('Embedding dimension unknown — run migrations / set vector dimension explicitly');\n}","typeGuard":"function isValidDim(v: unknown): v is number {\n  return typeof v === 'number' && Number.isInteger(v) && v >= 1 && v <= 65536;\n}","tryCatchPattern":"try {\n  const dim = await db.getDimensionSize('smart_search', 'embedding');\n  assert(dim === expectedModelDim, `dimension ${dim} != model dim ${expectedModelDim}`);\n} catch (err) {\n  logger.error('Dimension unavailable or mismatched; do not embed until fixed');\n}","preventionTips":["Match CLIP model dimension (512) with the DB column dimension before embedding","Run migrations after every upgrade so dim constraints exist","Check dim_size_constraint when dimension warnings appear","Install/verify pgvector extension before first boot"],"tags":["database","postgres","vector-index","dimension"],"backgroundTag":"value-out-of-range","analyzedSha":"e55ac299a4ec7cb372e35dbf2c6c05ee9ce77f6c","analyzedAt":"2026-09-15T07:20:19.675Z","contentChangedAt":"2026-09-15T07:20:19.675Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}