mem0ai/mem0 · error · Error
Baidu insert requires vectors, ids, and payloads of equal le
Error message
Baidu insert requires vectors, ids, and payloads of equal length (got ${vectors.length}/${ids.length}/${payloads.length}). What it means
The Baidu insert() requires the vectors, ids, and payloads arrays to have identical length because rows are built by zipping them index-by-index. A length mismatch means the caller's data is inconsistent (an id or payload missing for some vector), so it throws with all three lengths rather than producing corrupt rows. This is a precondition check at the store boundary.
Source
Thrown at mem0-ts/src/oss/src/vector_stores/baidu.ts:412
if (!this._initPromise) {
this._initPromise = this.ensureTable().catch((error) => {
this._initPromise = undefined;
throw error;
});
}
return this._initPromise;
}
async insert(
vectors: number[][],
ids: string[],
payloads: Record<string, any>[],
): Promise<void> {
const { client } = await this.ready();
if (vectors.length !== ids.length || vectors.length !== payloads.length) {
throw new Error(
`Baidu insert requires vectors, ids, and payloads of equal length (got ${vectors.length}/${ids.length}/${payloads.length}).`,
);
}
const rows = vectors.map((vector, index) => ({
id: ids[index],
data: memoryData(payloads[index] || {}),
vector,
textLemmatized: lemmatizedText(payloads[index] || {}),
metadata: metadataPayload(payloads[index] || {}),
}));
check(await client.upsert({ ...this.ns, rows }), "upsert");
}
async search(
query: number[],
topK = 5,View on GitHub (pinned to 001c235229)
Solutions
- Build the three arrays from a single source list so lengths cannot diverge.
- When an embedding fails, remove the corresponding id and payload too (or abort the batch).
- Add an assertion before the call: vectors.length === ids.length === payloads.length.
Example fix
// before const ids = all.map(m => m.id); const vectors = embeddings.filter(Boolean); // silently drops failures // after const ok = all.filter((_, i) => embeddings[i] != null); const ids = ok.map(m => m.id); const vectors = ok.map((_, i) => embeddings[i]);
Defensive patterns
Strategy: validation
Validate before calling
function assertInsertArgs(vectors: unknown[][], ids: string[], payloads: Record<string, any>[]) {
if (vectors.length !== ids.length || vectors.length !== payloads.length)
throw new Error(`Length mismatch: ${vectors.length}/${ids.length}/${payloads.length}`);
} Type guard
const isAlignedInsert = (v: unknown[][], ids: string[], p: Record<string, any>[]): boolean => v.length === ids.length && v.length === p.length;
Try / catch
try { await store.insert(vectors, ids, payloads) } catch (e) { if (e instanceof Error && /requires vectors, ids, and payloads of equal length/.test(e.message)) { /* rebuild arrays from one source list and retry */ } throw e; } Prevention
- Derive ids, vectors, and payloads by mapping a single array of items so lengths stay in lockstep.
- Never filter one array independently of the others after generation.
- Add a length assertion in test coverage for batch-building code.
When it happens
Trigger: Calling insert() (or a bulk add path feeding it) with ids shorter than vectors; defaulting payloads to [] when it should be an array of empty objects; upstream code filtering one array but not the others.
Common situations: Custom orchestration code building the three arrays separately; batch generation that skips failed embeddings but keeps all ids; off-by-one bugs in slicing batches.
Related errors
- image_url content part is missing image_url.url
- Baidu Mochow ${action} failed (code ${response.code}): ${res
- Baidu vector store requires a non-empty '${name}' config val
- Invalid filter key: ${key}
- Filter value for ${key} must be str, int, float, or bool, go
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/f368795701c9dc93.
Report an issue: GitHub.