{"record":{"id":"ca9bac4947b3c8a6","repo":"mem0ai/mem0","slug":"filter-value-for-key-must-be-str-int-float-o","errorCode":null,"errorMessage":"Filter value for ${key} must be str, int, float, or bool, got ${Array.isArray(value) ? \"array\" : typeof value}","messagePattern":"Filter value for (.+?) must be str, int, float, or bool, got (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/vector_stores/baidu.ts","lineNumber":279,"sourceCode":"  private buildFilter(filters: SearchFilters): string {\n    const conditions: string[] = [];\n\n    for (const [key, value] of Object.entries(filters)) {\n      if (!SAFE_FILTER_KEY.test(key)) {\n        throw new Error(`Invalid filter key: ${key}`);\n      }\n\n      if (typeof value === \"string\") {\n        conditions.push(`metadata[\"${key}\"] = \"${escapeFilterString(value)}\"`);\n        continue;\n      }\n\n      if (typeof value === \"number\" || typeof value === \"boolean\") {\n        conditions.push(`metadata[\"${key}\"] = ${value}`);\n        continue;\n      }\n\n      throw new Error(\n        `Filter value for ${key} must be str, int, float, or bool, got ${Array.isArray(value) ? \"array\" : typeof value}`,\n      );\n    }\n\n    return conditions.join(\" AND \");\n  }\n\n  private filterOf(filters?: SearchFilters): string | undefined {\n    return filters && Object.keys(filters).length > 0\n      ? this.buildFilter(filters)\n      : undefined;\n  }\n\n  private async pollTable(\n    client: MochowClient,\n    settled: (response: DescTableResponse) => boolean,\n    what: string,\n  ): Promise<void> {","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/vector_stores/baidu.ts#L261-L297","documentation":"buildFilter only renders string, number, and boolean filter values into the Mochow predicate string; any other type (array, object, null, undefined) reaches the final throw, naming the key and reporting 'array' for arrays or the JS typeof otherwise. Mochow's filter DSL as used here has no operator for containment, so array filters are unsupported rather than silently ignored.","triggerScenarios":"memory.search('q', { user_id: ['u1', 'u2'] }) (IN-filter); filters { run_id: null } or { agent_id: { $in: [...] } } (Mongo-style syntax leaking through).","commonSituations":"Porting filters from a store that supports arrays (Qdrant match-any); forgetting that null/undefined values should be omitted from the filter object entirely.","solutions":["Replace array filters with a single scalar value, or issue one search per array element and merge results.","Strip null/undefined entries from the filter object before calling search().","Keep SearchFilters values to string | number | boolean by design."],"exampleFix":"// before\nconst filters = { user_id: ['u1', 'u2'], run_id: null };\n// after\nconst filters = { user_id: 'u1' };\n// or merge searches per element","handlingStrategy":"type-guard","validationCode":"function normalizeFilters(f: Record<string, unknown> = {}) {\n  const out: Record<string, string | number | boolean> = {};\n  for (const [k, v] of Object.entries(f)) {\n    if (v == null) continue;               // drop null/undefined\n    if (['string','number','boolean'].includes(typeof v)) out[k] = v as any;\n    else if (Array.isArray(v)) v.forEach(x => { if (x != null) out[k] = x as any; }); // last-wins; or fan out\n    else throw new Error(`Unsupported filter value for ${k}`);\n  }\n  return out;\n}","typeGuard":"type ScalarFilterValue = string | number | boolean;\nconst isScalarFilterValue = (v: unknown): v is ScalarFilterValue =>\n  ['string','number','boolean'].includes(typeof v);","tryCatchPattern":"try { await memory.search(q, filters) } catch (e) { if (e instanceof Error && /Filter value for .* must be str, int, float, or bool/.test(e.message)) { return memory.search(q, normalizeFilters(filters)); } throw e; }","preventionTips":["Type SearchFilters values as string | number | boolean in your own code.","Strip null/undefined and expand arrays into per-value searches before calling search()."],"tags":["baidu","filters","type-error","search","validation"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}