mem0ai/mem0 · error · Error
`embeddingModelDims` must be a positive integer
Error message
`embeddingModelDims` must be a positive integer
What it means
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).
Source
Thrown at mem0-ts/src/oss/src/vector_stores/oracledb.ts:344
constructor(config: OracleDBConfig) {
if (!config.connectionParams && !config.client) {
throw new Error(
"Must provide at least one of `connectionParams` and `client`",
);
}
this.collectionName = quoteIdentifier(config.collectionName || "mem0");
this.indexName = quoteIdentifier(
config.indexName || `${config.collectionName || "mem0"}_VEC_IDX`,
);
this.embeddingModelDims = config.embeddingModelDims ?? 1536;
if (
!Number.isInteger(this.embeddingModelDims) ||
this.embeddingModelDims <= 0
) {
throw new Error("`embeddingModelDims` must be a positive integer");
}
const distanceMetric = (config.distanceMetric ??
"COSINE") as string as DistanceMetric;
this.distanceMetric = distanceMetric.toUpperCase() as DistanceMetric;
if (!DISTANCE_METRICS.includes(this.distanceMetric)) {
throw new Error(`Unsupported distance metric: ${config.distanceMetric}`);
}
const indexType = (config.indexType ?? "HNSW") as string;
this.indexType = indexType.toUpperCase() as IndexType;
if (this.indexType !== "HNSW" && this.indexType !== "IVF") {
throw new Error(`Unsupported index type: ${config.indexType}`);
}
this.indexAccuracy = config.indexAccuracy;
if (
this.indexAccuracy !== undefined &&View on GitHub (pinned to 001c235229)
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.
Example fix
// before
new OracleDB({ connectionParams, embeddingModelDims: Number(process.env.DIMS) }); // '768' -> 768 ok, '768.5' or undefined -> NaN
// after
const dims = parseInt(process.env.DIMS ?? '1536', 10);
new OracleDB({ connectionParams, embeddingModelDims: dims }); Defensive patterns
Strategy: validation
Validate before calling
function parseDims(raw: string | number | undefined, fallback = 1536): number {
const n = typeof raw === 'string' ? parseInt(raw, 10) : raw;
if (n === undefined) return fallback;
if (!Number.isInteger(n) || n <= 0) throw new RangeError(`embeddingModelDims must be a positive integer, got ${String(raw)}`);
return n;
} Type guard
const isPositiveInt = (v: unknown): v is number => typeof v === 'number' && Number.isInteger(v) && v > 0;
Try / catch
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; } Prevention
- 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.
When it happens
Trigger: 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'.
Common situations: 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.
Related errors
- Must provide at least one of `connectionParams` and `client`
- Unsupported distance metric: ${config.distanceMetric}
- Unsupported index type: ${config.indexType}
- `indexAccuracy` must be an integer between 1 and 100
- Unknown embedder provider: ${providerId}
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/b3496dc5f262cb95.
Report an issue: GitHub.