{"record":{"id":"1ccad64f8fbeda77","repo":"mastra-ai/mastra","slug":"bm25-search-requires-bm25-configuration","errorCode":null,"errorMessage":"BM25 search requires BM25 configuration.","messagePattern":"BM25 search requires BM25 configuration\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/workspace/search/search-engine.ts","lineNumber":653,"sourceCode":"   */\n  get bm25Index(): BM25Index | undefined {\n    return this.#bm25Index;\n  }\n\n  // ===========================================================================\n  // Private Methods\n  // ===========================================================================\n\n  /**\n   * Determine the effective search mode\n   */\n  #determineSearchMode(requestedMode?: SearchMode): SearchMode {\n    if (requestedMode) {\n      if (requestedMode === 'vector' && !this.canVector) {\n        throw new Error('Vector search requires vector configuration.');\n      }\n      if (requestedMode === 'bm25' && !this.canBM25) {\n        throw new Error('BM25 search requires BM25 configuration.');\n      }\n      if (requestedMode === 'hybrid' && !this.canHybrid) {\n        throw new Error('Hybrid search requires both vector and BM25 configuration.');\n      }\n      return requestedMode;\n    }\n\n    // Auto-determine based on available configuration\n    if (this.canHybrid) {\n      return 'hybrid';\n    }\n    if (this.canVector) {\n      return 'vector';\n    }\n    if (this.canBM25) {\n      return 'bm25';\n    }\n","sourceCodeStart":635,"sourceCodeEnd":671,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/workspace/search/search-engine.ts#L635-L671","documentation":"SearchEngine was explicitly asked to run a 'bm25' search, but no BM25 index was ever configured on the engine. The engine validates the requested search mode against its available configuration before searching; keyword search requires a BM25 config (or a BM25 index built during indexing), so it throws instead of silently returning empty results.","triggerScenarios":"Calling `searchEngine.search(query, { mode: 'bm25' })` (or a Workspace search API passing mode: 'bm25') on an engine constructed without a BM25SearchConfig — i.e. `canBM25` is false because the internal #bm25Index was never created.","commonSituations":"Constructing SearchEngine with only vectorConfig while later code (often copied from keyword-search examples) requests mode: 'bm25'; switching search modes via a UI/flag that doesn't match the deployment's config; a refactor that dropped the bm25 option from the constructor.","solutions":["Pass a BM25SearchConfig (bm25/tokenizer options) when constructing SearchEngine so a BM25 index is created.","Drop the explicit `mode: 'bm25'` from the search options and let the engine auto-select the mode, or request a mode that matches the configured backend.","Check `engine.canBM25` before requesting bm25 mode and branch to an available mode (e.g. vector)."],"exampleFix":"// before\nawait searchEngine.search('query', { mode: 'bm25' });\n\n// after (either configure BM25)\nconst engine = new SearchEngine({ bm25: {}, vectorConfig: myVectorConfig });\nawait engine.search('query', { mode: 'bm25' });\n\n// ...or search in an available mode\nconst mode = engine.canBM25 ? 'bm25' : 'vector';\nawait searchEngine.search('query', { mode });","handlingStrategy":"validation","validationCode":"if (!engine.canBM25) {\n  throw new Error('This engine is not configured for BM25 search; configure a bm25 config or use another mode.');\n}\nawait engine.search(query, { mode: 'bm25' });","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Gate explicit mode selection on the engine's canBM25/canVector/canHybrid getters.","Derive the search mode from configuration once at startup instead of hardcoding it at call sites.","Only pass `mode` in search options when you constructed the engine yourself and know its backends."],"tags":["search","configuration","bm25","misconfiguration"],"backgroundTag":"search-mode-not-configured","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}