{"record":{"id":"a487fc33f84bc4bb","repo":"mastra-ai/mastra","slug":"vectors-array-cannot-be-empty","errorCode":null,"errorMessage":"Vectors array cannot be empty","messagePattern":"Vectors array cannot be empty","errorType":"error_code","errorClass":"MastraError","httpStatus":null,"severity":"error","filePath":"packages/core/src/vector/validation.ts","lineNumber":28,"sourceCode":"\n/**\n * Validates upsert input parameters\n *\n * @param storeName - Name of the vector store (e.g., 'PG', 'CHROMA')\n * @param vectors - Array of vectors to upsert\n * @param metadata - Optional metadata array\n * @param ids - Optional ids array\n * @throws MastraError if validation fails\n */\nexport function validateUpsertInput(\n  storeName: string,\n  vectors: number[][] | undefined | null,\n  metadata?: Record<string, any>[] | null,\n  ids?: string[] | null,\n): void {\n  // Validate vectors array is not empty\n  if (!vectors || vectors.length === 0) {\n    throw new MastraError({\n      id: createVectorErrorId(storeName, 'UPSERT', 'EMPTY_VECTORS'),\n      domain: ErrorDomain.MASTRA_VECTOR,\n      category: ErrorCategory.USER,\n      details: {\n        message: 'Vectors array cannot be empty',\n      },\n    });\n  }\n\n  // Validate metadata length matches vectors length (skip if metadata is empty/not provided)\n  if (metadata && metadata.length > 0 && metadata.length !== vectors.length) {\n    throw new MastraError({\n      id: createVectorErrorId(storeName, 'UPSERT', 'METADATA_LENGTH_MISMATCH'),\n      domain: ErrorDomain.MASTRA_VECTOR,\n      category: ErrorCategory.USER,\n      details: {\n        message: 'Metadata array length must match vectors array length',\n        vectorsLength: vectors.length,","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/vector/validation.ts#L10-L46","documentation":"This error is thrown by validateUpsertInput when a vector store's upsert() receives an empty, null, or undefined vectors array. The library refuses the call because an upsert with no vectors is always a caller mistake and would silently do nothing.","triggerScenarios":"Calling store.upsert({ indexName, vectors: [] }), passing null/undefined vectors, or building the vectors array from a filter/transformation that produced zero results.","commonSituations":"An embedding batch came back empty (e.g. empty input documents list), a variable was initialized as [] and never filled, or query results feeding the upsert were filtered to nothing.","solutions":["Ensure the vectors array contains at least one number[] before calling upsert","Check the code that produces the vectors (embedding call, batch loop) for early-exit or empty-filter bugs","Guard the call site: skip or throw your own clearer error when vectors.length === 0"],"exampleFix":"// before\nawait store.upsert({ indexName: 'docs', vectors: [] });\n// after\nif (vectors.length === 0) throw new Error('No vectors to upsert');\nawait store.upsert({ indexName: 'docs', vectors });","handlingStrategy":"validation","validationCode":"if (!Array.isArray(vectors) || vectors.length === 0) {\n  throw new Error('upsert requires at least one vector');\n}","typeGuard":"function hasVectors(v: unknown): v is number[][] {\n  return Array.isArray(v) && v.length > 0;\n}","tryCatchPattern":"try {\n  await store.upsert({ indexName, vectors });\n} catch (e) {\n  if (e instanceof MastraError && e.id.includes('EMPTY_VECTORS')) {\n    console.warn('Nothing to upsert, skipping');\n    return;\n  }\n  throw e;\n}","preventionTips":["Check vectors.length before every upsert call","Bail out early when the input document list is empty","Log the source of vectors when building batches"],"tags":["validation","vector-store","upsert"],"backgroundTag":"empty-array-argument","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}