{"record":{"id":"b3496dc5f262cb95","repo":"mem0ai/mem0","slug":"embeddingmodeldims-must-be-a-positive-integer","errorCode":null,"errorMessage":"`embeddingModelDims` must be a positive integer","messagePattern":"`embeddingModelDims` must be a positive integer","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/vector_stores/oracledb.ts","lineNumber":344,"sourceCode":"\n  constructor(config: OracleDBConfig) {\n    if (!config.connectionParams && !config.client) {\n      throw new Error(\n        \"Must provide at least one of `connectionParams` and `client`\",\n      );\n    }\n\n    this.collectionName = quoteIdentifier(config.collectionName || \"mem0\");\n    this.indexName = quoteIdentifier(\n      config.indexName || `${config.collectionName || \"mem0\"}_VEC_IDX`,\n    );\n\n    this.embeddingModelDims = config.embeddingModelDims ?? 1536;\n    if (\n      !Number.isInteger(this.embeddingModelDims) ||\n      this.embeddingModelDims <= 0\n    ) {\n      throw new Error(\"`embeddingModelDims` must be a positive integer\");\n    }\n\n    const distanceMetric = (config.distanceMetric ??\n      \"COSINE\") as string as DistanceMetric;\n    this.distanceMetric = distanceMetric.toUpperCase() as DistanceMetric;\n    if (!DISTANCE_METRICS.includes(this.distanceMetric)) {\n      throw new Error(`Unsupported distance metric: ${config.distanceMetric}`);\n    }\n\n    const indexType = (config.indexType ?? \"HNSW\") as string;\n    this.indexType = indexType.toUpperCase() as IndexType;\n    if (this.indexType !== \"HNSW\" && this.indexType !== \"IVF\") {\n      throw new Error(`Unsupported index type: ${config.indexType}`);\n    }\n\n    this.indexAccuracy = config.indexAccuracy;\n    if (\n      this.indexAccuracy !== undefined &&","sourceCodeStart":326,"sourceCodeEnd":362,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/vector_stores/oracledb.ts#L326-L362","documentation":"embeddingModelDims becomes the vector dimension of the Oracle vector index and column; it must be a positive integer because VECTOR(N) dimensions are a fixed integer. The check uses Number.isInteger, so fractional values, zero, negatives, NaN, Infinity, and non-numbers all fail (defaults to 1536 when omitted).","triggerScenarios":"new OracleDB({ connectionParams, embeddingModelDims: 1536.5 }); embeddingModelDims: 0 or -1; dims read from an env var without parsing (string '768'); dims computed as NaN from undefined arithmetic; passing dims as a string '1536'.","commonSituations":"Switching embedding providers (e.g. OpenAI 1536 → Cohere 1024) and hand-editing the number; reading dimensions from a config/env as a string; arithmetic like 3072/2 producing 1536 vs a typo producing 1536.0-style floats from JSON parsers that keep floats.","solutions":["Set an integer matching your embedding model's output size: 1536 (OpenAI text-embedding-3-small), 1024 (Cohere embed-v3), 768 (many open models).","Parse env values as integers: parseInt(process.env.EMBED_DIMS!, 10) with a Number.isInteger guard.","Check for accidental string values or float arithmetic; wrap with Math.round/parseInt if the source may be fractional.","Omit the option entirely if 1536 is correct — the default applies."],"exampleFix":"// before\nnew OracleDB({ connectionParams, embeddingModelDims: Number(process.env.DIMS) }); // '768' -> 768 ok, '768.5' or undefined -> NaN\n\n// after\nconst dims = parseInt(process.env.DIMS ?? '1536', 10);\nnew OracleDB({ connectionParams, embeddingModelDims: dims });","handlingStrategy":"validation","validationCode":"function parseDims(raw: string | number | undefined, fallback = 1536): number {\n  const n = typeof raw === 'string' ? parseInt(raw, 10) : raw;\n  if (n === undefined) return fallback;\n  if (!Number.isInteger(n) || n <= 0) throw new RangeError(`embeddingModelDims must be a positive integer, got ${String(raw)}`);\n  return n;\n}","typeGuard":"const isPositiveInt = (v: unknown): v is number => typeof v === 'number' && Number.isInteger(v) && v > 0;","tryCatchPattern":"try { new OracleDB(cfg); } catch (e) { if (e instanceof Error && e.message.includes('embeddingModelDims')) { /* correct the dimension to the embedding model's output size */ } else throw e; }","preventionTips":["Keep a MODEL → dims map next to your embedding provider config.","parseInt env-provided dimensions and validate with Number.isInteger.","Never change dims on an existing collection — dimension is fixed at index creation."],"tags":["oracle","config","embeddings","validation","constructor"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}