diff --git a/packages/backend/server/src/core/doc/reader.ts b/packages/backend/server/src/core/doc/reader.ts index f0b13b6a3..50326fcab 100644 --- a/packages/backend/server/src/core/doc/reader.ts +++ b/packages/backend/server/src/core/doc/reader.ts @@ -42,10 +42,10 @@ export abstract class DocReader { protected readonly blobStorage: WorkspaceBlobStorage ) {} - parseDocContent(bin: Uint8Array) { + parseDocContent(bin: Uint8Array, maxSummaryLength = 150) { const doc = new YDoc(); applyUpdate(doc, bin); - return parsePageDoc(doc); + return parsePageDoc(doc, { maxSummaryLength }); } parseWorkspaceContent(bin: Uint8Array) { @@ -85,6 +85,13 @@ export abstract class DocReader { return content; } + async getFullDocContent( + workspaceId: string, + docId: string + ): Promise { + return await this.getDocContentWithoutCache(workspaceId, docId, true); + } + /** * Get workspace content, try to read from database first. * If not exists, read from `getWorkspaceContentWithoutCache()` and save it back to database. @@ -131,7 +138,8 @@ export abstract class DocReader { protected abstract getDocContentWithoutCache( workspaceId: string, - guid: string + guid: string, + fullContent?: boolean ): Promise; protected abstract getWorkspaceContentWithoutCache( @@ -180,13 +188,14 @@ export class DatabaseDocReader extends DocReader { protected override async getDocContentWithoutCache( workspaceId: string, - guid: string + guid: string, + fullContent?: boolean ): Promise { const docRecord = await this.workspace.getDoc(workspaceId, guid); if (!docRecord) { return null; } - return this.parseDocContent(docRecord.bin); + return this.parseDocContent(docRecord.bin, fullContent ? -1 : 150); } protected override async getWorkspaceContentWithoutCache( diff --git a/packages/backend/server/src/core/utils/blocksuite.ts b/packages/backend/server/src/core/utils/blocksuite.ts index 885536435..675590012 100644 --- a/packages/backend/server/src/core/utils/blocksuite.ts +++ b/packages/backend/server/src/core/utils/blocksuite.ts @@ -115,7 +115,9 @@ export function parsePageDoc( continue; } - if (summaryLenNeeded > 0) { + if (summaryLenNeeded === -1) { + content.summary += text.toString(); + } else if (summaryLenNeeded > 0) { content.summary += text.toString(); summaryLenNeeded -= text.length; } else { diff --git a/packages/backend/server/src/plugins/copilot/context/job.ts b/packages/backend/server/src/plugins/copilot/context/job.ts index ff488c3a0..4b4db101b 100644 --- a/packages/backend/server/src/plugins/copilot/context/job.ts +++ b/packages/backend/server/src/plugins/copilot/context/job.ts @@ -159,7 +159,7 @@ export class CopilotContextDocJob implements OnModuleInit { if (!this.supportEmbedding) return; try { - const content = await this.doc.getDocContent(workspaceId, docId); + const content = await this.doc.getFullDocContent(workspaceId, docId); if (content) { // no need to check if embeddings is empty, will throw internally const embeddings = await this.embeddingClient.getFileEmbeddings(