lobehub/lobehub · error · TRPCError

INTERNAL_SERVER_ERROR

INTERNAL_SERVER_ERROR

Error message

Failed to perform semantic search

What it means

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.

Source

Thrown at apps/server/src/routers/lambda/chunk.ts:178

      // vector failed, surface the original TRPCError so existing chat flows
      // (which only use vector) get the same diagnostics they did before.
      const knowledgeIds = input.knowledgeIds ?? [];
      const vectorRejection = result.rejections?.vector as any | undefined;
      if (vectorRejection && knowledgeIds.length === 0 && result.documents.length === 0) {
        const errorType = vectorRejection?.errorType;
        if (errorType === 'InvalidProviderAPIKey') {
          throw new TRPCError({
            code: 'METHOD_NOT_SUPPORTED',
            message: vectorRejection.message || 'Invalid API key for embedding provider',
          });
        }
        if (errorType === 'ProviderBizError') {
          throw new TRPCError({
            code: 'BAD_REQUEST',
            message: vectorRejection.message || 'Provider service error',
          });
        }
        throw new TRPCError({
          code: 'INTERNAL_SERVER_ERROR',
          message: vectorRejection?.message || errorType || 'Failed to perform semantic search',
        });
      }

      // TODO: need to rerank the chunks
      return {
        chunks: result.chunks,
        documents: result.documents,
        errors: result.errors,
        fileResults: result.fileResults,
        totalResults: result.totalResults,
      };
    }),
});

View on GitHub (pinned to 10f24d7ade)

Solutions

  1. Inspect `vectorRejection.message` / `vectorRejection.errorType` to identify the unmapped rejection and add a dedicated branch for it.
  2. Check the pgvector / vector-store index health and embedding-dimension consistency.
  3. Log the full rejection object server-side until the type is mapped (currently only the message surfaces).
  4. If this is a new rejection type from an upgraded search-service version, update the router's switch to handle it explicitly.

Example fix

// before — unknown rejections fall through opaquely
if (errorType === 'InvalidProviderAPIKey') { ... }
if (errorType === 'ProviderBizError') { ... }
throw new TRPCError({ code: 'INTERNAL_SERVER_ERROR', message: vectorRejection?.message || errorType || 'Failed to perform semantic search' });

// after — log + branch new types
console.error('[chunk:semanticSearchForChat] unmapped vectorRejection', vectorRejection);
if (errorType === 'DimensionMismatch') throw new TRPCError({ code: 'BAD_REQUEST', message: vectorRejection.message });
throw new TRPCError({ code: 'INTERNAL_SERVER_ERROR', cause: vectorRejection, message: vectorRejection?.message || errorType || 'Failed to perform semantic search' });
Defensive patterns

Strategy: try-catch

Type guard

const isSemanticSearchInternal = (e: unknown): boolean =>
  typeof e === 'object' && e !== null &&
  (e as any).data?.code === 'INTERNAL_SERVER_ERROR' &&
  /semantic search/i.test((e as any).message ?? '');

Try / catch

try {
  await trpc.chunk.semanticSearchForChat.mutate({ query, fileIds });
} catch (e) {
  if (isSemanticSearchInternal(e)) { showSearchUnavailable(); return; }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: Version skew between the search service and this router; a vector-store (pgvector) dimension/indexing fault producing an uncategorized rejection.

Related errors


AI-assisted analysis of lobehub/lobehub@10f24d7ade (2026-08-12). Data as JSON: /api/errors/25736569475359a1. Report an issue: GitHub.