feat(server): remove context prefetch & integrate context search (#12956)

fix AI-173
This commit is contained in:
DarkSky
2025-06-27 23:45:49 +08:00
committed by GitHub
parent ad306edcf1
commit e6f91cced6
9 changed files with 88 additions and 70 deletions

View File

@@ -197,34 +197,52 @@ export class CopilotContextService implements OnApplicationBootstrap {
async matchWorkspaceAll(
workspaceId: string,
content: string,
topK: number = 5,
topK: number,
signal?: AbortSignal,
threshold: number = 0.5
threshold: number = 0.8,
docIds?: string[],
scopedThreshold: number = 0.85
) {
if (!this.embeddingClient) return [];
const embedding = await this.embeddingClient.getEmbedding(content, signal);
if (!embedding) return [];
const [fileChunks, workspaceChunks] = await Promise.all([
this.models.copilotWorkspace.matchFileEmbedding(
workspaceId,
embedding,
topK * 2,
threshold
),
this.models.copilotContext.matchWorkspaceEmbedding(
embedding,
workspaceId,
topK * 2,
threshold
),
]);
const [fileChunks, workspaceChunks, scopedWorkspaceChunks] =
await Promise.all([
this.models.copilotWorkspace.matchFileEmbedding(
workspaceId,
embedding,
topK * 2,
threshold
),
if (!fileChunks.length && !workspaceChunks.length) return [];
this.models.copilotContext.matchWorkspaceEmbedding(
embedding,
workspaceId,
topK * 2,
threshold
),
docIds
? this.models.copilotContext.matchWorkspaceEmbedding(
embedding,
workspaceId,
topK * 2,
scopedThreshold,
docIds
)
: null,
]);
if (
!fileChunks.length &&
!workspaceChunks.length &&
!scopedWorkspaceChunks?.length
)
return [];
return await this.embeddingClient.reRank(
content,
[...fileChunks, ...workspaceChunks],
[...fileChunks, ...workspaceChunks, ...(scopedWorkspaceChunks || [])],
topK,
signal
);