{"record":{"id":"bb212fa66003b702","repo":"mastra-ai/mastra","slug":"invalid-request-query-indexname-and-queryvector-a","errorCode":null,"errorMessage":"Invalid request query. indexName and queryVector array are required.","messagePattern":"Invalid request query\\. indexName and queryVector array are required\\.","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"packages/server/src/server/handlers/vector.ts","lineNumber":123,"sourceCode":"    return { success: true };\n  } catch (error) {\n    return handleError(error, 'Error creating index');\n  }\n}\n\n// Query vectors\nexport async function queryVectors({\n  mastra,\n  vectorName,\n  indexName,\n  queryVector,\n  topK,\n  filter,\n  includeVector,\n}: Pick<VectorContext, 'mastra' | 'vectorName'> & QueryRequest) {\n  try {\n    if (!indexName || !queryVector || !Array.isArray(queryVector)) {\n      throw new HTTPException(400, { message: 'Invalid request query. indexName and queryVector array are required.' });\n    }\n\n    const vector = getVector(mastra, vectorName);\n    const results: QueryResult[] = await vector.query({ indexName, queryVector, topK, filter, includeVector });\n    return results;\n  } catch (error) {\n    return handleError(error, 'Error querying vectors');\n  }\n}\n\n// List indexes\nexport async function listIndexes({ mastra, vectorName }: Pick<VectorContext, 'mastra' | 'vectorName'>) {\n  try {\n    const vector = getVector(mastra, vectorName);\n\n    const indexes = await vector.listIndexes();\n    return indexes.filter(Boolean);\n  } catch (error) {","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/vector.ts#L105-L141","documentation":"This HTTP 400 error is thrown by the queryVectors handler when the request lacks an indexName or a queryVector, or when queryVector is present but is not an array. The handler validates these two required fields before calling the vector store's query. It prevents confusing downstream errors like 'cannot read length of undefined' inside the store adapter.","triggerScenarios":"POSTing to the query route with a body missing indexName; omitting queryVector; sending queryVector as an object or a comma-separated string instead of a JSON array; sending queryVector: null.","commonSituations":"Generating embeddings asynchronously and passing undefined because the embedding call failed silently; sending the embedding as {values: [...]} because code was copied from a different provider SDK; forgetting that indexName is a body field, not a URL path param on this route.","solutions":["Include indexName in the request body.","Pass queryVector as a plain JSON array of numbers, e.g. [0.1, 0.2, ...].","Confirm the embedding generation step succeeded and actually returned an array before querying.","Match the embedding dimension to the index dimension to avoid the next error you'd hit."],"exampleFix":"// before\nconst results = await query({ indexName: 'docs', queryVector: embedding?.values });\n// after\nif (!Array.isArray(embedding?.values)) throw new Error('embedding not ready');\nconst results = await query({ indexName: 'docs', queryVector: embedding.values });","handlingStrategy":"validation","validationCode":"function assertQueryRequest(body) {\n  const { indexName, queryVector } = body ?? {};\n  if (typeof indexName !== 'string' || indexName.length === 0) throw new TypeError('indexName is required');\n  if (!Array.isArray(queryVector) || queryVector.length === 0 || queryVector.some(n => typeof n !== 'number')) throw new TypeError('queryVector must be a non-empty array of numbers');\n  return body;\n}","typeGuard":"function isNumberArray(v) { return Array.isArray(v) && v.length > 0 && v.every(n => typeof n === 'number' && Number.isFinite(n)); }","tryCatchPattern":"try {\n  return await client.query({ indexName, queryVector, topK });\n} catch (e) {\n  if (e.status === 400 && /Invalid request query/.test(e.message)) {\n    console.error('query rejected — check indexName and that queryVector is a number[]');\n  }\n  throw e;\n}","preventionTips":["Await embedding generation and check the result is an array before querying.","Send queryVector as a flat number[], not {values:[...]} or a string.","Keep embedding dimension consistent with the index dimension.","Validate request bodies with a schema before sending."],"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-30T03:17:51.788Z"}