{"record":{"id":"34bec14e585b33eb","repo":"mem0ai/mem0","slug":"databricks-vector-store-only-accepts-finite-number","errorCode":null,"errorMessage":"Databricks vector store only accepts finite numbers.","messagePattern":"Databricks vector store only accepts finite numbers\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/vector_stores/databricks.ts","lineNumber":140,"sourceCode":"// against lemmatized text. Same contract as baidu.ts / pgvector.ts.\nfunction lemmatizedText(payload: Record<string, any>): string {\n  const data = typeof payload.data === \"string\" ? payload.data : \"\";\n  return typeof payload.textLemmatized === \"string\" &&\n    payload.textLemmatized.length > 0\n    ? payload.textLemmatized\n    : data;\n}\n\nfunction formatSqlValue(value: any): string {\n  if (value === null || value === undefined) {\n    return \"NULL\";\n  }\n  if (typeof value === \"boolean\") {\n    return value ? \"TRUE\" : \"FALSE\";\n  }\n  if (typeof value === \"number\") {\n    if (!Number.isFinite(value)) {\n      throw new Error(\"Databricks vector store only accepts finite numbers.\");\n    }\n    return String(value);\n  }\n  if (Array.isArray(value)) {\n    return `array(${value.map((entry) => formatSqlValue(entry)).join(\", \")})`;\n  }\n  const json =\n    typeof value === \"string\" ? value : JSON.stringify(value ?? {}) || \"{}\";\n  // Databricks/Spark SQL treats backslash as an escape char in string literals,\n  // so a trailing \"\\\" would consume the closing quote (breaking out of the\n  // literal) and any backslash would be dropped on write. Escape backslashes\n  // before doubling quotes so the literal is injection-safe and round-trips.\n  const escaped = json.replace(/\\\\/g, \"\\\\\\\\\").replace(/'/g, \"''\");\n  return `'${escaped}'`;\n}\n\nfunction extractRowValue(row: Record<string, any>, keys: string[]): any {\n  for (const key of keys) {","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/vector_stores/databricks.ts#L122-L158","documentation":"formatSqlValue() serializes values into SQL literals for Databricks writes. NaN and Infinity are valid JS numbers but have no SQL numeric literal, so writing them would produce broken or dangerous SQL. They are rejected with this error before the statement is built.","triggerScenarios":"A memory payload or metadata field containing NaN/Infinity — e.g. a score computed as 1/0, parseFloat('abc') producing NaN, or JSON like {\"score\": Infinity} surviving a JSON.parse round-trip — reaching add()/update() on the Databricks store.","commonSituations":"Aggregated metrics (divisions by zero) stored alongside memories; numeric fields parsed from freeform user input; data pipelines that don't sanitize floats before persistence.","solutions":["Sanitize numeric fields before saving: replace non-finite numbers with null or omit the field","Fix the upstream computation producing NaN/Infinity (guard divide-by-zero, validate parseFloat results)"],"exampleFix":"// before\nawait memory.add('result', { metadata: { ratio: num / denom } }); // denom may be 0\n\n// after\nconst ratio = Number.isFinite(num / denom) ? num / denom : null;\nawait memory.add('result', { metadata: { ratio } });","handlingStrategy":"validation","validationCode":"function sanitizeNumbers(value: any): any {\n  if (typeof value === 'number' && !Number.isFinite(value)) return null;\n  if (Array.isArray(value)) return value.map(sanitizeNumbers);\n  if (value && typeof value === 'object') {\n    return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, sanitizeNumbers(v)]));\n  }\n  return value;\n}\nawait memory.add(text, { metadata: sanitizeNumbers(metadata) });","typeGuard":"const isFiniteNumber = (v: unknown): v is number => typeof v === 'number' && Number.isFinite(v);","tryCatchPattern":null,"preventionTips":["Validate numeric metadata fields at the API boundary before persistence","Guard divisions and parseFloat results upstream"],"tags":["databricks","validation","data-quality","typescript"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}