{"record":{"id":"25736569475359a1","repo":"lobehub/lobehub","slug":"internal-server-error-257365","errorCode":"INTERNAL_SERVER_ERROR","errorMessage":"Failed to perform semantic search","messagePattern":"Failed to perform semantic search","errorType":"exception","errorClass":"TRPCError","httpStatus":500,"severity":"error","filePath":"apps/server/src/routers/lambda/chunk.ts","lineNumber":178,"sourceCode":"      // vector failed, surface the original TRPCError so existing chat flows\n      // (which only use vector) get the same diagnostics they did before.\n      const knowledgeIds = input.knowledgeIds ?? [];\n      const vectorRejection = result.rejections?.vector as any | undefined;\n      if (vectorRejection && knowledgeIds.length === 0 && result.documents.length === 0) {\n        const errorType = vectorRejection?.errorType;\n        if (errorType === 'InvalidProviderAPIKey') {\n          throw new TRPCError({\n            code: 'METHOD_NOT_SUPPORTED',\n            message: vectorRejection.message || 'Invalid API key for embedding provider',\n          });\n        }\n        if (errorType === 'ProviderBizError') {\n          throw new TRPCError({\n            code: 'BAD_REQUEST',\n            message: vectorRejection.message || 'Provider service error',\n          });\n        }\n        throw new TRPCError({\n          code: 'INTERNAL_SERVER_ERROR',\n          message: vectorRejection?.message || errorType || 'Failed to perform semantic search',\n        });\n      }\n\n      // TODO: need to rerank the chunks\n      return {\n        chunks: result.chunks,\n        documents: result.documents,\n        errors: result.errors,\n        fileResults: result.fileResults,\n        totalResults: result.totalResults,\n      };\n    }),\n});\n","sourceCodeStart":160,"sourceCodeEnd":194,"githubUrl":"https://github.com/lobehub/lobehub/blob/10f24d7ade75139093a9373b364f6bc91f3cd7db/apps/server/src/routers/lambda/chunk.ts#L160-L194","documentation":"The fallback error in `semanticSearchForChat`: the vector path rejected with an `errorType` that is neither `InvalidProviderAPIKey` nor `ProviderBizError`. It is the catch-all for unknown/unhandled rejection types from the knowledge-base search service. Mapped to INTERNAL_SERVER_ERROR because the failure mode is unrecognized and may be a server-side defect.","triggerScenarios":"A new rejection type introduced in `KnowledgeBaseSearchService` that the router hasn't been taught to map; an internal exception inside the search service that the service re-wrapped as an opaque rejection.","commonSituations":"Version skew between the search service and this router; a vector-store (pgvector) dimension/indexing fault producing an uncategorized rejection.","solutions":["Inspect `vectorRejection.message` / `vectorRejection.errorType` to identify the unmapped rejection and add a dedicated branch for it.","Check the pgvector / vector-store index health and embedding-dimension consistency.","Log the full rejection object server-side until the type is mapped (currently only the message surfaces).","If this is a new rejection type from an upgraded search-service version, update the router's switch to handle it explicitly."],"exampleFix":"// before — unknown rejections fall through opaquely\nif (errorType === 'InvalidProviderAPIKey') { ... }\nif (errorType === 'ProviderBizError') { ... }\nthrow new TRPCError({ code: 'INTERNAL_SERVER_ERROR', message: vectorRejection?.message || errorType || 'Failed to perform semantic search' });\n\n// after — log + branch new types\nconsole.error('[chunk:semanticSearchForChat] unmapped vectorRejection', vectorRejection);\nif (errorType === 'DimensionMismatch') throw new TRPCError({ code: 'BAD_REQUEST', message: vectorRejection.message });\nthrow new TRPCError({ code: 'INTERNAL_SERVER_ERROR', cause: vectorRejection, message: vectorRejection?.message || errorType || 'Failed to perform semantic search' });","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"const isSemanticSearchInternal = (e: unknown): boolean =>\n  typeof e === 'object' && e !== null &&\n  (e as any).data?.code === 'INTERNAL_SERVER_ERROR' &&\n  /semantic search/i.test((e as any).message ?? '');","tryCatchPattern":"try {\n  await trpc.chunk.semanticSearchForChat.mutate({ query, fileIds });\n} catch (e) {\n  if (isSemanticSearchInternal(e)) { showSearchUnavailable(); return; }\n  throw e;\n}","preventionTips":["Log the full `vectorRejection` server-side to identify unmapped rejection types.","Add an explicit branch in the router for any new rejection errorType the search service emits.","Check pgvector index health and embedding-dimension consistency."],"tags":["trpc","internal-server-error","vector-search","unhandled-rejection","observability"],"backgroundTag":null,"analyzedSha":"10f24d7ade75139093a9373b364f6bc91f3cd7db","analyzedAt":"2026-08-12T11:43:19.543Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}