{"record":{"id":"7eeff765829ecb7f","repo":"mastra-ai/mastra","slug":"indexname-is-required-got-indexname-7eeff7","errorCode":null,"errorMessage":"indexName is required, got: ${indexName}","messagePattern":"indexName is required, got: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/rag/src/tools/vector-query.ts","lineNumber":54,"sourceCode":"      // The `context` parameter from `createTool` is loosely typed and the\n      // generated tool types don't always surface `tracingContext`. The cast\n      // is intentional: when `context` or `tracingContext` is undefined,\n      // `createObservabilityContext` falls back to `noOpTracingContext`, so\n      // downstream span creation safely no-ops.\n      const { requestContext, mastra, tracingContext } = (context as any) || {};\n      const observabilityContext = createObservabilityContext(tracingContext);\n      const indexName: string = requestContext?.get('indexName') ?? options.indexName;\n      const vectorStoreName: string =\n        'vectorStore' in options ? storeName : (requestContext?.get('vectorStoreName') ?? storeName);\n      const includeVectors: boolean = requestContext?.get('includeVectors') ?? options.includeVectors ?? false;\n      const includeSources: boolean = requestContext?.get('includeSources') ?? options.includeSources ?? true;\n      const reranker: RerankConfig | undefined = requestContext?.get('reranker') ?? options.reranker;\n      const databaseConfig = requestContext?.get('databaseConfig') ?? options.databaseConfig;\n      const model: MastraEmbeddingModel<string> = requestContext?.get('model') ?? options.model;\n      const providerOptions: ProviderOptions['providerOptions'] =\n        requestContext?.get('providerOptions') ?? options.providerOptions;\n\n      if (!indexName) throw new Error(`indexName is required, got: ${indexName}`);\n      if (!vectorStoreName) throw new Error(`vectorStoreName is required, got: ${vectorStoreName}`); // won't fire\n\n      const topK: number = requestContext?.get('topK') ?? (inputData.topK as number) ?? 10;\n      const filter: unknown = requestContext?.get('filter') ?? inputData.filter;\n      const queryText = inputData.queryText;\n      const enableFilter = !!requestContext?.get('filter') || (options.enableFilter ?? false);\n\n      const logger = mastra?.getLogger();\n      if (logger) {\n        logger.debug('[VectorQueryTool] execute called with:', { queryText, topK, filter, databaseConfig });\n      }\n      try {\n        const topKValue = coerceTopK(topK);\n\n        const vectorStore = await resolveVectorStore(options, { requestContext, mastra, vectorStoreName });\n        if (!vectorStore) {\n          if (logger) {\n            logger.error('Vector store not found', { vectorStore: vectorStoreName });","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/rag/src/tools/vector-query.ts#L36-L72","documentation":"createVectorQueryTool's execute resolves indexName from requestContext or options; when it is empty/undefined the tool throws this error with the received value. Without an index name the vector query has nothing to search.","triggerScenarios":"Creating the tool without an indexName option and executing without requestContext.get('indexName'); passing indexName: '' or a variable that is undefined.","commonSituations":"Building the tool in a factory where indexName is injected later but used earlier; typo'd option key (idxName); server setups where RequestContext is expected to provide the index but doesn't.","solutions":["Pass indexName explicitly: createVectorQueryTool({ vectorStore, indexName: 'my-index', model })","Ensure requestContext middleware sets 'indexName' when relying on per-request configuration","Confirm the index actually exists in the vector store under that exact name"],"exampleFix":"// before\nconst tool = createVectorQueryTool({ vectorStore, model });\n// after\nconst tool = createVectorQueryTool({ vectorStore, indexName: 'my-index', model });","handlingStrategy":"validation","validationCode":"const indexName = requestContext?.get('indexName') ?? options.indexName;\nif (!indexName) throw new Error('createVectorQueryTool: indexName must be provided');","typeGuard":"const hasIndexName = (o: unknown): o is { indexName: string } => typeof o === 'object' && o !== null && typeof (o as any).indexName === 'string' && (o as any).indexName.length > 0;","tryCatchPattern":"try { return await tool.execute(ctx); } catch (e) { if (e.message.startsWith('indexName is required')) { /* set indexName and re-run */ } else throw e; }","preventionTips":["Set indexName at tool construction, not only via request context","Assert index existence right after creating it in setup scripts","Type tool option objects so indexName is required, not optional"],"tags":["configuration","validation","tool","vector-search"],"backgroundTag":"missing-required-parameter","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}