{"record":{"id":"c3e828a0bf41c485","repo":"mastra-ai/mastra","slug":"invalid-request-index-indexname-and-vectors-array","errorCode":null,"errorMessage":"Invalid request index. indexName and vectors array are required.","messagePattern":"Invalid request index\\. indexName and vectors array are required\\.","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"packages/server/src/server/handlers/vector.ts","lineNumber":73,"sourceCode":"  if (!vector) {\n    throw new HTTPException(404, { message: `Vector store ${vectorName} not found` });\n  }\n\n  return vector;\n}\n\n// Upsert vectors\nexport async function upsertVectors({\n  mastra,\n  vectorName,\n  indexName,\n  vectors,\n  metadata,\n  ids,\n}: VectorContext & UpsertRequest) {\n  try {\n    if (!indexName || !vectors || !Array.isArray(vectors)) {\n      throw new HTTPException(400, { message: 'Invalid request index. indexName and vectors array are required.' });\n    }\n\n    const vector = getVector(mastra, vectorName);\n    const result = await vector.upsert({ indexName, vectors, metadata, ids });\n    return { ids: result };\n  } catch (error) {\n    return handleError(error, 'Error upserting vectors');\n  }\n}\n\n// Create index\nexport async function createIndex({\n  mastra,\n  vectorName,\n  indexName,\n  dimension,\n  metric,\n}: Pick<VectorContext, 'mastra' | 'vectorName'> & CreateIndexRequest) {","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/vector.ts#L55-L91","documentation":"HTTP 400 thrown by upsertVectors: the request body must include indexName and a vectors array. If either is missing or vectors is not an array, the upsert is rejected before touching the vector store.","triggerScenarios":"POST to the vector upsert route with body missing indexName, missing vectors, or vectors being an object/string instead of an array of embedding vectors.","commonSituations":"Client sending { indexName, vector: [...] } (singular key typo); passing a single vector instead of an array of vectors; JSON serialization dropping the array; forgetting the body entirely.","solutions":["Send a JSON body with both indexName (string) and vectors (array of number[]).","Wrap a single embedding in an array: vectors: [embedding].","Validate the payload shape client-side before the request."],"exampleFix":"// before\nawait client.upsert({ indexName: 'docs', vectors: embedding })\n// after\nawait client.upsert({ indexName: 'docs', vectors: [embedding], metadata: [{ id: 'doc-1' }] })","handlingStrategy":"validation","validationCode":"function assertUpsertBody(body: unknown): asserts body is { indexName: string; vectors: number[][] } {\n  const b = body as any;\n  if (!b || typeof b.indexName !== 'string' || !Array.isArray(b.vectors) || b.vectors.some(v => !Array.isArray(v))) {\n    throw new Error('upsert requires indexName and vectors: number[][]');\n  }\n}","typeGuard":"function isValidUpsert(b: unknown): b is { indexName: string; vectors: number[][] } {\n  const x = b as any;\n  return !!x && typeof x.indexName === 'string' && Array.isArray(x.vectors) && x.vectors.every((v: unknown) => Array.isArray(v));\n}","tryCatchPattern":"try {\n  await upsert(body);\n} catch (e) {\n  if (isHttpException(e, 400) && e.message.includes('indexName and vectors array are required')) {\n    throw new RequestShapeError('Wrap single embeddings in an array and include indexName');\n  }\n  throw e;\n}","preventionTips":["Use the client SDK's typed upsert method instead of hand-rolled fetch calls.","Remember the API takes an array of embeddings, not a single vector.","Validate request bodies against the API schema in tests."],"tags":["http-400","request-body","vector","validation"],"backgroundTag":"invalid-request-body","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}