mem0ai/mem0 · error · Error
Invalid indexType: ${config.indexType}. Must be 'hnsw' or 'f
Error message
Invalid indexType: ${config.indexType}. Must be 'hnsw' or 'flat' What it means
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.
Source
Thrown at mem0-ts/src/oss/src/vector_stores/valkey.ts:170
private readonly valkeyUrl: string;
private _initPromise?: Promise<void>;
constructor(config: ValkeyConfig) {
this.collectionName = config.collectionName;
this.indexPrefix = `mem0:${config.collectionName}`;
this.embeddingModelDims = config.embeddingModelDims;
this.timezone = config.timezone ?? "UTC";
this.indexType = (config.indexType ?? "hnsw").toLowerCase() as
| "hnsw"
| "flat";
this.hnswM = config.hnswM ?? 16;
this.hnswEfConstruction = config.hnswEfConstruction ?? 200;
this.hnswEfRuntime = config.hnswEfRuntime ?? 10;
this.clusterMode = config.clusterMode ?? false;
this.valkeyUrl = config.valkeyUrl;
if (this.indexType !== "hnsw" && this.indexType !== "flat") {
throw new Error(
`Invalid indexType: ${config.indexType}. Must be 'hnsw' or 'flat'`,
);
}
this.initialize().catch((err) => {
console.error("Failed to initialize Valkey:", err);
});
}
private buildIndexCreateCommand(
collectionName: string,
embeddingDims: number,
distanceMetric: string,
prefix: string,
): (string | number)[] {
const vectorConfig =
this.indexType === "hnsw"
? [View on GitHub (pinned to 001c235229)
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.
Example fix
// before
new Memory({ vectorStore: { provider: 'valkey', config: { indexType: 'ivf' } } });
// after
new Memory({ vectorStore: { provider: 'valkey', config: { indexType: 'hnsw' } } }); Defensive patterns
Strategy: type-guard
Validate before calling
if (config.indexType && !['hnsw','flat'].includes(config.indexType.toLowerCase().trim())) throw new Error(`indexType '${config.indexType}' invalid — use 'hnsw' or 'flat'`); Type guard
const isValkeyIndexType = (v: unknown): v is 'hnsw' | 'flat' => v === 'hnsw' || v === 'flat';
Try / catch
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; } Prevention
- Omit indexType to accept the hnsw default
- Type config.indexType as 'hnsw' | 'flat' in your own config schema
- Trim env-sourced values
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Unsupported index type: ${config.indexType}
- `indexAccuracy` must be an integer between 1 and 100
- Unsupported ${this.indexType} index parameter '${key}'. Allo
- Index parameter '${key}' must be an integer between ${range[
- Extra fields not allowed: {', '.join(extra_fields)}. Please
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/1c4ffeb48e7518c6.
Report an issue: GitHub.