feat(server): improve rerank performance (#12775)

fix AI-183
This commit is contained in:
DarkSky
2025-06-12 13:31:01 +08:00
committed by GitHub
parent 2d17c265ca
commit ed56f076ed
5 changed files with 75 additions and 36 deletions

View File

@@ -158,14 +158,15 @@ export class CopilotContextService implements OnApplicationBootstrap {
const embedding = await this.embeddingClient.getEmbedding(content, signal);
if (!embedding) return [];
const chunks = await this.models.copilotWorkspace.matchFileEmbedding(
const fileChunks = await this.models.copilotWorkspace.matchFileEmbedding(
workspaceId,
embedding,
topK * 2,
threshold
);
if (!fileChunks.length) return [];
return this.embeddingClient.reRank(content, chunks, topK, signal);
return this.embeddingClient.reRank(content, fileChunks, topK, signal);
}
async matchWorkspaceDocs(
@@ -179,14 +180,16 @@ export class CopilotContextService implements OnApplicationBootstrap {
const embedding = await this.embeddingClient.getEmbedding(content, signal);
if (!embedding) return [];
const workspace = await this.models.copilotContext.matchWorkspaceEmbedding(
embedding,
workspaceId,
topK * 2,
threshold
);
const workspaceChunks =
await this.models.copilotContext.matchWorkspaceEmbedding(
embedding,
workspaceId,
topK * 2,
threshold
);
if (!workspaceChunks.length) return [];
return this.embeddingClient.reRank(content, workspace, topK);
return this.embeddingClient.reRank(content, workspaceChunks, topK, signal);
}
@OnEvent('workspace.doc.embed.failed')