fix(server): set empty embedding on empty doc (#12857)

#### PR Dependency Tree


* **PR #12857** 👈

This tree was auto-generated by
[Charcoal](https://github.com/danerwilliams/charcoal)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **Bug Fixes**
- Improved error handling in document embedding jobs to log and skip
errors instead of interrupting the process.
- Enhanced logging with clearer messages about embedding outcomes and
skipped operations.
- Added warnings when documents or summaries are missing during
embedding.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
fengmk2
2025-06-20 10:30:53 +08:00
committed by GitHub
parent dfaf69475b
commit 5623d808bf

View File

@@ -6,7 +6,6 @@ import {
BlobNotFound,
CallMetric,
CopilotContextFileNotSupported,
DocNotFound,
EventBus,
JobQueue,
mapAnyError,
@@ -138,7 +137,7 @@ export class CopilotEmbeddingJob {
if (enableDocEmbedding) {
const toBeEmbedDocIds =
await this.models.copilotWorkspace.findDocsToEmbed(workspaceId);
this.logger.debug(
this.logger.log(
`Trigger embedding for ${toBeEmbedDocIds.length} docs in workspace ${workspaceId}`
);
for (const docId of toBeEmbedDocIds) {
@@ -342,11 +341,16 @@ export class CopilotEmbeddingJob {
workspaceId,
docId
);
this.logger.verbose(
this.logger.log(
`Check if doc ${docId} in workspace ${workspaceId} needs embedding: ${needEmbedding}`
);
if (needEmbedding) {
if (signal.aborted) return;
if (signal.aborted) {
this.logger.log(
`Doc ${docId} in workspace ${workspaceId} is aborted, skipping embedding.`
);
return;
}
const fragment = await this.getDocFragment(workspaceId, docId);
if (fragment) {
// fast fall for empty doc, journal is easily to create a empty doc
@@ -367,12 +371,21 @@ export class CopilotEmbeddingJob {
chunks
);
}
this.logger.log(
`Doc ${docId} in workspace ${workspaceId} has summary, embedding done.`
);
} else {
// for empty doc, insert empty embedding
this.logger.warn(
`Doc ${docId} in workspace ${workspaceId} has no summary, fulfilling empty embedding.`
);
await this.fulfillEmptyEmbedding(workspaceId, docId);
}
} else if (contextId) {
throw new DocNotFound({ spaceId: workspaceId, docId });
this.logger.warn(
`Doc ${docId} in workspace ${workspaceId} has no fragment, fulfilling empty embedding.`
);
await this.fulfillEmptyEmbedding(workspaceId, docId);
}
}
} catch (error: any) {
@@ -394,8 +407,11 @@ export class CopilotEmbeddingJob {
return;
}
// passthrough error to job queue
throw error;
// log error and skip the job
this.logger.error(
`Error embedding doc ${docId} in workspace ${workspaceId}`,
error
);
}
}
}