{"record":{"id":"0017a4ee64e2d79f","repo":"mastra-ai/mastra","slug":"invalid-request-index-indexname-and-positive-dime","errorCode":null,"errorMessage":"Invalid request index, indexName and positive dimension number are required.","messagePattern":"Invalid request index, indexName and positive dimension number are required\\.","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"packages/server/src/server/handlers/vector.ts","lineNumber":94,"sourceCode":"    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) {\n  try {\n    if (!indexName || typeof dimension !== 'number' || dimension <= 0) {\n      throw new HTTPException(400, {\n        message: 'Invalid request index, indexName and positive dimension number are required.',\n      });\n    }\n\n    if (metric && !['cosine', 'euclidean', 'dotproduct'].includes(metric)) {\n      throw new HTTPException(400, { message: 'Invalid metric. Must be one of: cosine, euclidean, dotproduct' });\n    }\n\n    const vector = getVector(mastra, vectorName);\n    await vector.createIndex({ indexName, dimension, metric });\n    return { success: true };\n  } catch (error) {\n    return handleError(error, 'Error creating index');\n  }\n}\n\n// Query vectors\nexport async function queryVectors({","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/vector.ts#L76-L112","documentation":"This HTTP 400 error is thrown by the createIndex server handler in packages/server/src/server/handlers/vector.ts when the request body fails basic validation. The Mastra server validates that an indexName is present (truthy) and that dimension is a positive number before delegating to the underlying vector store's createIndex. It exists to fail fast with a clear message instead of an opaque error deep inside the vector store adapter.","triggerScenarios":"POSTing to the create-index route with a body missing indexName, omitting dimension, sending dimension as a string (e.g. \"1536\"), sending dimension as 0 or a negative number, or sending a non-numeric value like null/NaN.","commonSituations":"Clients serializing query params instead of a JSON body; dimension taken from an untyped config/env var that comes through as a string; template-built requests where indexName is an empty string from an unset variable; copying an older API example where dimension was optional.","solutions":["Ensure the request body includes indexName as a non-empty string.","Send dimension as a JSON number (not a string) greater than 0, e.g. 1536.","If dimension comes from config/env, coerce with Number() and validate before sending.","Verify you are hitting the correct route with a JSON content-type body."],"exampleFix":"// before\nawait fetch('/api/vectors/my-store/indexes', { method: 'POST', body: JSON.stringify({ dimension: '1536' }) });\n// after\nawait fetch('/api/vectors/my-store/indexes', { method: 'POST', body: JSON.stringify({ indexName: 'my_index', dimension: 1536, metric: 'cosine' }) });","handlingStrategy":"validation","validationCode":"function assertCreateIndexRequest(body) {\n  const { indexName, dimension } = body ?? {};\n  if (typeof indexName !== 'string' || indexName.length === 0) throw new TypeError('indexName is required');\n  if (typeof dimension !== 'number' || !Number.isFinite(dimension) || dimension <= 0) throw new TypeError('dimension must be a positive number');\n  return body;\n}","typeGuard":"function isValidDimension(d) { return typeof d === 'number' && Number.isFinite(d) && Number.isInteger(d) && d > 0; }","tryCatchPattern":"try {\n  await client.createIndex({ indexName, dimension });\n} catch (e) {\n  if (e.status === 400 && /Invalid request index/.test(e.message)) {\n    console.error('createIndex payload rejected:', { indexName, dimension });\n  }\n  throw e;\n}","preventionTips":["Coerce config-driven dimensions with Number() and validate > 0 before the call.","Validate the full request body against a zod schema at the client boundary.","Never send dimension as a string from forms/JSON configs.","Log the exact request body when a 400 occurs."],"tags":["http-400","validation","vector","rest-api"],"backgroundTag":"schema-validation-failed","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}