{"record":{"id":"1c4ffeb48e7518c6","repo":"mem0ai/mem0","slug":"invalid-indextype-config-indextype-must-be-h","errorCode":null,"errorMessage":"Invalid indexType: ${config.indexType}. Must be 'hnsw' or 'flat'","messagePattern":"Invalid indexType: (.+?)\\. Must be 'hnsw' or 'flat'","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/vector_stores/valkey.ts","lineNumber":170,"sourceCode":"  private readonly valkeyUrl: string;\n  private _initPromise?: Promise<void>;\n\n  constructor(config: ValkeyConfig) {\n    this.collectionName = config.collectionName;\n    this.indexPrefix = `mem0:${config.collectionName}`;\n    this.embeddingModelDims = config.embeddingModelDims;\n    this.timezone = config.timezone ?? \"UTC\";\n    this.indexType = (config.indexType ?? \"hnsw\").toLowerCase() as\n      | \"hnsw\"\n      | \"flat\";\n    this.hnswM = config.hnswM ?? 16;\n    this.hnswEfConstruction = config.hnswEfConstruction ?? 200;\n    this.hnswEfRuntime = config.hnswEfRuntime ?? 10;\n    this.clusterMode = config.clusterMode ?? false;\n    this.valkeyUrl = config.valkeyUrl;\n\n    if (this.indexType !== \"hnsw\" && this.indexType !== \"flat\") {\n      throw new Error(\n        `Invalid indexType: ${config.indexType}. Must be 'hnsw' or 'flat'`,\n      );\n    }\n\n    this.initialize().catch((err) => {\n      console.error(\"Failed to initialize Valkey:\", err);\n    });\n  }\n\n  private buildIndexCreateCommand(\n    collectionName: string,\n    embeddingDims: number,\n    distanceMetric: string,\n    prefix: string,\n  ): (string | number)[] {\n    const vectorConfig =\n      this.indexType === \"hnsw\"\n        ? [","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/vector_stores/valkey.ts#L152-L188","documentation":"The Valkey vector store builds RediSearch-style indexes and accepts only two index types: 'hnsw' and 'flat' (case-insensitive after lowering). Any other indexType value in the constructor throws immediately. Note this check runs after lowercasing, so mixed case like 'HNSW' is fine, but 'ivf', 'HNSW ', or typos like 'hsnw' are rejected.","triggerScenarios":"config: { indexType: 'ivfflat' } or any value outside hnsw/flat; trailing whitespace in the value ('flat '); copying config from a pgvector/Milvus setup that uses different index type names.","commonSituations":"Attempting to use a Valkey/RediSearch-unavailable index algorithm; config drift from other vector stores' indexType vocabularies; values sourced from env vars with stray characters.","solutions":["Set indexType to 'hnsw' (default, approximate nearest neighbor) or 'flat' (exact, brute force).","Omit indexType entirely to get the 'hnsw' default.","Trim/normalize env-sourced values before passing them in config."],"exampleFix":"// before\nnew Memory({ vectorStore: { provider: 'valkey', config: { indexType: 'ivf' } } });\n\n// after\nnew Memory({ vectorStore: { provider: 'valkey', config: { indexType: 'hnsw' } } });","handlingStrategy":"type-guard","validationCode":"if (config.indexType && !['hnsw','flat'].includes(config.indexType.toLowerCase().trim())) throw new Error(`indexType '${config.indexType}' invalid — use 'hnsw' or 'flat'`);","typeGuard":"const isValkeyIndexType = (v: unknown): v is 'hnsw' | 'flat' => v === 'hnsw' || v === 'flat';","tryCatchPattern":"try { new Memory({ vectorStore: { provider: 'valkey', config } }); } catch (e) { if (e instanceof Error && e.message.startsWith('Invalid indexType')) { /* fall back to default by omitting indexType */ } else throw e; }","preventionTips":["Omit indexType to accept the hnsw default","Type config.indexType as 'hnsw' | 'flat' in your own config schema","Trim env-sourced values"],"tags":["valkey","config","index","validation"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}