豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit f21049d

Browse files
mjbvzCopilot
andauthored
Clean up a bit more legacy code around workspace chunk search (#4795)
* Clean up a bit more legacy code around workspace chunk search * Update src/platform/workspaceChunkSearch/node/workspaceChunkSearchService.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 111403d commit f21049d

File tree

6 files changed

+20
-95
lines changed

6 files changed

+20
-95
lines changed

src/extension/conversation/vscode-node/feedbackReporter.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,12 @@ export class FeedbackReporter extends Disposable implements IFeedbackReporter {
161161
"rankResultsCount": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "comment": "Count of the results from copilot search ranking." },
162162
"combinedResultsCount": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "comment": "Count of combined results from copilot search." },
163163
"chunkSearchDuration": { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth", "isMeasurement": true, "comment": "Duration of the chunk search" },
164-
"llmFilteringDuration": { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth", "isMeasurement": true, "comment": "Duration of the LLM filtering" },
165-
"strategy": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "Indicates the strategy used for the search." }
164+
"llmFilteringDuration": { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth", "isMeasurement": true, "comment": "Duration of the LLM filtering" }
166165
}
167166
*/
168167
this.telemetryService.sendMSFTTelemetryEvent('copilot.search.feedback', {
169168
kind,
170169
rankResult: SemanticSearchTextSearchProvider.feedBackTelemetry.rankResult,
171-
strategy: SemanticSearchTextSearchProvider.feedBackTelemetry.strategy,
172170
}, {
173171
chunkCount: SemanticSearchTextSearchProvider.feedBackTelemetry.chunkCount,
174172
rankResultsCount: SemanticSearchTextSearchProvider.feedBackTelemetry.rankResultsCount,

src/extension/workspaceSemanticSearch/node/semanticSearchTextSearchProvider.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export interface ISearchFeedbackTelemetry {
4444
llmSelectedCount?: number;
4545
rawLlmRankingResultsCount?: number;
4646
parseResult?: string;
47-
strategy?: string;
47+
4848
llmBestInRerank?: number;
4949
llmWorstInRerank?: number;
5050
}
@@ -170,7 +170,6 @@ export class SemanticSearchTextSearchProvider implements vscode.AITextSearchProv
170170
);
171171
SemanticSearchTextSearchProvider.feedBackTelemetry.chunkSearchDuration = Date.now() - chunkSearchDuration;
172172
SemanticSearchTextSearchProvider.feedBackTelemetry.chunkCount = result.chunks.length;
173-
SemanticSearchTextSearchProvider.feedBackTelemetry.strategy = result.strategy;
174173
this.treeSitterAIKeywords(query, progress, result.chunks.map(chunk => chunk.chunk), token);
175174

176175
const chunkResults = result.chunks.map(c => c.chunk);
@@ -317,15 +316,13 @@ export class SemanticSearchTextSearchProvider implements vscode.AITextSearchProv
317316
"llmSelectedCount": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "comment": "Number of chunks selected by LLM from the initial retrieval." },
318317
"rawLlmRankingResultsCount": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "comment": "Number of raw results returned by the LLM." },
319318
"parseResult": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "Indicates the result of parsing the LLM response." },
320-
"strategy": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "Indicates the strategy used for the search." },
321319
"llmBestInRerank": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "comment": "Best rank (lowest index) among LLM-selected chunks in the reranked results." },
322320
"llmWorstInRerank": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "comment": "Worst rank (highest index) among LLM-selected chunks in the reranked results." }
323321
}
324322
*/
325323
this._telemetryService.sendMSFTTelemetryEvent('copilot.search.request', {
326324
rankResult: SemanticSearchTextSearchProvider.feedBackTelemetry.rankResult,
327325
parseResult: SemanticSearchTextSearchProvider.feedBackTelemetry.parseResult,
328-
strategy: SemanticSearchTextSearchProvider.feedBackTelemetry.strategy,
329326
}, {
330327
chunkCount: SemanticSearchTextSearchProvider.feedBackTelemetry.chunkCount,
331328
rankResultsCount: SemanticSearchTextSearchProvider.feedBackTelemetry.rankResultsCount,

src/platform/workspaceChunkSearch/common/workspaceChunkSearch.ts

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import type * as vscode from 'vscode';
77
import { GlobIncludeOptions } from '../../../util/common/glob';
8-
import { TelemetryCorrelationId } from '../../../util/common/telemetryCorrelationId';
98
import { CancellationToken } from '../../../util/vs/base/common/cancellation';
109
import { FileChunkAndScore } from '../../chunking/common/chunk';
1110
import { Embedding } from '../../embeddings/common/embeddingsComputer';
@@ -22,14 +21,6 @@ export interface WorkspaceChunkQueryWithEmbeddings extends WorkspaceChunkQuery {
2221
resolveQueryEmbeddings(token: CancellationToken): Promise<Embedding>;
2322
}
2423

25-
/**
26-
* Internal ids used to identify strategies in telemetry.
27-
*/
28-
export enum WorkspaceChunkSearchStrategyId {
29-
Embeddings = 'ada',// Do not change value as it's used for telemetry
30-
CodeSearch = 'codesearch',
31-
}
32-
3324
/**
3425
* Sizing hints for the search strategy.
3526
*/
@@ -53,32 +44,3 @@ export type WorkspaceSearchAlert =
5344
| vscode.ChatResponseWarningPart
5445
| vscode.ChatResponseCommandButtonPart
5546
| vscode.ChatResponseMarkdownPart;
56-
57-
export interface IWorkspaceChunkSearchStrategy {
58-
readonly id: WorkspaceChunkSearchStrategyId;
59-
60-
/**
61-
* Invoked before the search is performed.
62-
*
63-
* This can be used to prompt the user or perform other actions.
64-
*
65-
* Unlike time spent in `searchWorkspace`, this method will not count towards timeouts
66-
*/
67-
prepareSearchWorkspace?(
68-
telemetryInfo: TelemetryCorrelationId,
69-
token: CancellationToken,
70-
): Promise<void>;
71-
72-
/**
73-
* Takes search queries and returns the chunks of text that are most semantically similar to any of the queries.
74-
*
75-
* @return Either the result (which may have zero chunks) or undefined if the search could not be performed.
76-
*/
77-
searchWorkspace(
78-
sizing: StrategySearchSizing,
79-
query: WorkspaceChunkQueryWithEmbeddings,
80-
options: WorkspaceChunkSearchOptions,
81-
telemetryInfo: TelemetryCorrelationId,
82-
token: CancellationToken
83-
): Promise<StrategySearchResult | undefined>;
84-
}

src/platform/workspaceChunkSearch/node/codeSearch/codeSearchChunkSearch.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import { isGitHubRemoteRepository } from '../../../remoteRepositories/common/uti
3939
import { IExperimentationService } from '../../../telemetry/common/nullExperimentationService';
4040
import { ITelemetryService } from '../../../telemetry/common/telemetry';
4141
import { IWorkspaceService } from '../../../workspace/common/workspaceService';
42-
import { IWorkspaceChunkSearchStrategy, StrategySearchResult, StrategySearchSizing, WorkspaceChunkQueryWithEmbeddings, WorkspaceChunkSearchOptions, WorkspaceChunkSearchStrategyId } from '../../common/workspaceChunkSearch';
42+
import { StrategySearchResult, StrategySearchSizing, WorkspaceChunkQueryWithEmbeddings, WorkspaceChunkSearchOptions } from '../../common/workspaceChunkSearch';
4343
import { EmbeddingsChunkSearch } from '../embeddingsChunkSearch';
4444

4545
import { WorkspaceChunkEmbeddingsIndex } from '../workspaceChunkEmbeddingsIndex';
@@ -87,9 +87,7 @@ interface AvailableFailureMetadata {
8787
* ChunkSearch strategy that first calls the Github code search API to get a context window of files that are similar to the query.
8888
* Then it uses the embeddings index to find the most similar chunks in the context window.
8989
*/
90-
export class CodeSearchChunkSearch extends Disposable implements IWorkspaceChunkSearchStrategy {
91-
92-
readonly id = WorkspaceChunkSearchStrategyId.CodeSearch;
90+
export class CodeSearchChunkSearch extends Disposable {
9391

9492
/**
9593
* Maximum number of files that have changed from what code search has indexed.
@@ -680,7 +678,7 @@ export class CodeSearchChunkSearch extends Disposable implements IWorkspaceChunk
680678
if (diffArray.length <= embeddingsMaxFiles) {
681679
const batchInfo = new ComputeBatchInfo();
682680
const result = await this._embeddingsChunkSearch.searchSubsetOfFiles(sizing, query, diffArray, subSearchOptions, { info: innerTelemetryInfo, batchInfo }, token);
683-
return { ...result, strategyId: this._embeddingsChunkSearch.id, embeddingsComputeInfo: batchInfo };
681+
return { ...result, strategyId: 'localEmbeddings', embeddingsComputeInfo: batchInfo };
684682
} else {
685683
// No way to search out-of-sync files; caller will use code search results alone and warn the user
686684
this._logService.debug(`CodeSearchChunkSearch.searchLocalDiff: ${diffArray.length} out-of-sync files exceeds threshold (${embeddingsMaxFiles}), skipping local diff search`);

src/platform/workspaceChunkSearch/node/embeddingsChunkSearch.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { ICodeSearchAuthenticationService } from '../../remoteCodeSearch/node/co
1919
import { ISimulationTestContext } from '../../simulationTestContext/common/simulationTestContext';
2020
import { IExperimentationService } from '../../telemetry/common/nullExperimentationService';
2121
import { ITelemetryService } from '../../telemetry/common/telemetry';
22-
import { IWorkspaceChunkSearchStrategy, StrategySearchResult, StrategySearchSizing, WorkspaceChunkQueryWithEmbeddings, WorkspaceChunkSearchOptions, WorkspaceChunkSearchStrategyId } from '../common/workspaceChunkSearch';
22+
import { StrategySearchResult, StrategySearchSizing, WorkspaceChunkQueryWithEmbeddings, WorkspaceChunkSearchOptions } from '../common/workspaceChunkSearch';
2323
import { BuildIndexTriggerReason } from './codeSearch/codeSearchRepo';
2424
import { WorkspaceChunkEmbeddingsIndex } from './workspaceChunkEmbeddingsIndex';
2525
import { IWorkspaceFileIndex } from './workspaceFileIndex';
@@ -41,9 +41,7 @@ export enum LocalEmbeddingsIndexStatus {
4141
*
4242
* This can be costly so it is only available for smaller workspaces.
4343
*/
44-
export class EmbeddingsChunkSearch extends Disposable implements IWorkspaceChunkSearchStrategy {
45-
46-
readonly id = WorkspaceChunkSearchStrategyId.Embeddings;
44+
export class EmbeddingsChunkSearch extends Disposable {
4745

4846
/** Max workspace size that will be automatically indexed. */
4947
private static readonly defaultAutomaticIndexingFileCap = 750;

src/platform/workspaceChunkSearch/node/workspaceChunkSearchService.ts

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { StopWatch } from '../../../util/vs/base/common/stopwatch';
1919
import { IInstantiationService } from '../../../util/vs/platform/instantiation/common/instantiation';
2020
import { ChatResponseProgressPart2, ChatResponseWarningPart } from '../../../vscodeTypes';
2121
import { IAuthenticationService } from '../../authentication/common/authentication';
22-
import { IAuthenticationChatUpgradeService } from '../../authentication/common/authenticationUpgrade';
2322
import { FileChunk, FileChunkAndScore } from '../../chunking/common/chunk';
2423
import { MAX_CHUNK_SIZE_TOKENS } from '../../chunking/node/naiveChunker';
2524
import { distance, Embedding, EmbeddingDistance, Embeddings, EmbeddingType, IEmbeddingsComputer } from '../../embeddings/common/embeddingsComputer';
@@ -29,14 +28,13 @@ import { logExecTime, LogExecTime } from '../../log/common/logExecTime';
2928
import { ILogService } from '../../log/common/logService';
3029
import { IChatEndpoint } from '../../networking/common/networking';
3130
import { ISimulationTestContext } from '../../simulationTestContext/common/simulationTestContext';
32-
import { IExperimentationService } from '../../telemetry/common/nullExperimentationService';
3331
import { ITelemetryService } from '../../telemetry/common/telemetry';
3432
import { getWorkspaceFileDisplayPath, IWorkspaceService } from '../../workspace/common/workspaceService';
3533
import { IGithubAvailableEmbeddingTypesService } from '../common/githubAvailableEmbeddingTypes';
3634
import { IRerankerService } from '../common/rerankerService';
37-
import { StrategySearchResult, StrategySearchSizing, WorkspaceChunkQuery, WorkspaceChunkQueryWithEmbeddings, WorkspaceChunkSearchOptions, WorkspaceChunkSearchStrategyId, WorkspaceSearchAlert } from '../common/workspaceChunkSearch';
35+
import { StrategySearchResult, StrategySearchSizing, WorkspaceChunkQuery, WorkspaceChunkQueryWithEmbeddings, WorkspaceChunkSearchOptions, WorkspaceSearchAlert } from '../common/workspaceChunkSearch';
3836
import { CodeSearchChunkSearch, CodeSearchRemoteIndexState } from './codeSearch/codeSearchChunkSearch';
39-
import { BuildIndexTriggerReason, CodeSearchRepoStatus, TriggerIndexingError } from './codeSearch/codeSearchRepo';
37+
import { BuildIndexTriggerReason, TriggerIndexingError } from './codeSearch/codeSearchRepo';
4038
import { IWorkspaceFileIndex } from './workspaceFileIndex';
4139

4240
const maxEmbeddingSpread = 0.65;
@@ -49,7 +47,6 @@ interface ScoredFileChunk<T extends FileChunk = FileChunk> {
4947
export interface WorkspaceChunkSearchResult {
5048
readonly chunks: readonly FileChunkAndScore[];
5149
readonly alerts?: readonly WorkspaceSearchAlert[];
52-
readonly strategy?: string;
5350
}
5451

5552
export interface WorkspaceChunkSearchSizing {
@@ -88,17 +85,12 @@ export interface IWorkspaceChunkSearchService extends IDisposable {
8885
}
8986

9087

91-
interface StrategySearchOk {
92-
readonly strategy: WorkspaceChunkSearchStrategyId;
93-
readonly result: StrategySearchResult;
94-
}
95-
9688
interface StrategySearchErr {
9789
readonly errorDiagMessage: string;
9890
alerts?: readonly WorkspaceSearchAlert[];
9991
}
10092

101-
type StrategySearchOutcome = Result<StrategySearchOk, StrategySearchErr>;
93+
type StrategySearchOutcome = Result<StrategySearchResult, StrategySearchErr>;
10294

10395
export class WorkspaceChunkSearchService extends Disposable implements IWorkspaceChunkSearchService {
10496
declare readonly _serviceBrand: undefined;
@@ -213,9 +205,7 @@ class WorkspaceChunkSearchServiceImpl extends Disposable implements IWorkspaceCh
213205
constructor(
214206
private readonly _embeddingType: EmbeddingType,
215207
@IInstantiationService instantiationService: IInstantiationService,
216-
@IAuthenticationChatUpgradeService private readonly _authUpgradeService: IAuthenticationChatUpgradeService,
217208
@IEmbeddingsComputer private readonly _embeddingsComputer: IEmbeddingsComputer,
218-
@IExperimentationService private readonly _experimentationService: IExperimentationService,
219209
@IIgnoreService private readonly _ignoreService: IIgnoreService,
220210
@ILogService private readonly _logService: ILogService,
221211
@IRerankerService private readonly _rerankerService: IRerankerService,
@@ -236,14 +226,6 @@ class WorkspaceChunkSearchServiceImpl extends Disposable implements IWorkspaceCh
236226
250
237227
)(() => this._onDidChangeIndexState.fire()));
238228

239-
this._register(this._authUpgradeService.onDidGrantAuthUpgrade(() => {
240-
if (this._experimentationService.getTreatmentVariable<boolean>('copilotchat.workspaceChunkSearch.shouldRemoteIndexOnAuthUpgrade') ?? true) {
241-
void this.triggerRemoteIndexing('auto', () => { }, new TelemetryCorrelationId('onDidGrantAuthUpgrade'), CancellationToken.None).catch(e => {
242-
// noop
243-
});
244-
}
245-
}));
246-
247229
/* __GDPR__
248230
"workspaceChunkSearch.created" : {
249231
"owner": "mjbvz",
@@ -263,12 +245,7 @@ class WorkspaceChunkSearchServiceImpl extends Disposable implements IWorkspaceCh
263245
}
264246

265247
async isAvailable(): Promise<boolean> {
266-
if (this._experimentationService.getTreatmentVariable<boolean>('copilotchat.workspaceChunkSearch.markAllSearchesSlow')) {
267-
return false;
268-
}
269-
270-
const indexState = await this.getIndexState();
271-
return (indexState.remoteIndexState.status === 'loaded' && indexState.remoteIndexState.repos.length > 0 && indexState.remoteIndexState.repos.every(repo => repo.status === CodeSearchRepoStatus.Ready));
248+
return this._codeSearchChunkSearch.isAvailable(new TelemetryCorrelationId('WorkspaceChunkSearchServiceImpl.isAvailable'), false, CancellationToken.None);
272249
}
273250

274251
triggerRemoteIndexing(trigger: BuildIndexTriggerReason, onProgress: (message: string) => void, telemetryInfo: TelemetryCorrelationId, token: CancellationToken): Promise<Result<true, TriggerIndexingError>> {
@@ -325,7 +302,7 @@ class WorkspaceChunkSearchServiceImpl extends Disposable implements IWorkspaceCh
325302
}
326303
*/
327304
this._telemetryService.sendMSFTTelemetryEvent('workspaceChunkSearchStrategy', {
328-
strategy: searchResult.isOk() ? searchResult.val.strategy : 'none',
305+
strategy: searchResult.isOk() ? 'codesearch' : 'none', // For backwards compatibility with existing telemetry only
329306
errorDiagMessage: searchResult.isError() ? searchResult.err.errorDiagMessage : undefined,
330307
embeddingType: this._embeddingType.id,
331308
workspaceSearchSource: telemetryInfo.callTracker.toString(),
@@ -348,9 +325,9 @@ class WorkspaceChunkSearchServiceImpl extends Disposable implements IWorkspaceCh
348325
};
349326
}
350327

351-
this._logService.trace(`WorkspaceChunkSearch.searchFileChunks: found ${searchResult.val.result.chunks.length} chunks using '${searchResult.val.strategy}'`);
328+
this._logService.trace(`WorkspaceChunkSearch.searchFileChunks: found ${searchResult.val.chunks.length} chunks`);
352329

353-
const filteredChunks = await raceCancellationError(this.filterIgnoredChunks(searchResult.val.result.chunks), token);
330+
const filteredChunks = await raceCancellationError(this.filterIgnoredChunks(searchResult.val.chunks), token);
354331
if (this._simulationTestContext.isInSimulationTests) {
355332
if (!filteredChunks.length) {
356333
throw new Error('No chunks returned');
@@ -360,7 +337,7 @@ class WorkspaceChunkSearchServiceImpl extends Disposable implements IWorkspaceCh
360337
const filteredResult = {
361338
...searchResult.val,
362339
result: {
363-
alerts: searchResult.val.result.alerts,
340+
alerts: searchResult.val.alerts,
364341
chunks: filteredChunks,
365342
}
366343
};
@@ -372,7 +349,6 @@ class WorkspaceChunkSearchServiceImpl extends Disposable implements IWorkspaceCh
372349
return {
373350
chunks: reranked.slice(0, this.getMaxChunks(sizing)),
374351
alerts: filteredResult.result.alerts,
375-
strategy: filteredResult.strategy,
376352
};
377353
} catch (e) {
378354
this._logService.error(e, 'Reranker service failed; falling back to local rerank');
@@ -433,17 +409,14 @@ class WorkspaceChunkSearchServiceImpl extends Disposable implements IWorkspaceCh
433409

434410
const result = await raceCancellationError(this._codeSearchChunkSearch.searchWorkspace(sizing, query, options, telemetryInfo, token), token);
435411
if (result) {
436-
return Result.ok<StrategySearchOk>({
437-
strategy: this._codeSearchChunkSearch.id,
438-
result: result,
439-
});
412+
return Result.ok<StrategySearchResult>(result);
440413
}
441414
} catch (e) {
442415
if (isCancellationError(e)) {
443416
throw e;
444417
}
445418

446-
this._logService.error(e, `Error during ${this._codeSearchChunkSearch.id} search`);
419+
this._logService.error(e, `Error during code search chunk search`);
447420
}
448421

449422
return Result.error<StrategySearchErr>({
@@ -477,13 +450,12 @@ class WorkspaceChunkSearchServiceImpl extends Disposable implements IWorkspaceCh
477450
}
478451

479452
@LogExecTime(self => self._logService, 'WorkspaceChunkSearch::rerankResultIfNeeded')
480-
private async rerankResultIfNeeded(query: WorkspaceChunkQueryWithEmbeddings, result: StrategySearchOk, maxResults: number, telemetryInfo: TelemetryCorrelationId, progress: vscode.Progress<vscode.ChatResponsePart> | undefined, token: CancellationToken): Promise<WorkspaceChunkSearchResult> {
481-
const chunks = result.result.chunks;
453+
private async rerankResultIfNeeded(query: WorkspaceChunkQueryWithEmbeddings, result: StrategySearchResult, maxResults: number, telemetryInfo: TelemetryCorrelationId, progress: vscode.Progress<vscode.ChatResponsePart> | undefined, token: CancellationToken): Promise<WorkspaceChunkSearchResult> {
454+
const chunks = result.chunks;
482455
const orderedChunks = await this.rerankChunks(query, chunks, maxResults, telemetryInfo, progress, token);
483456
return {
484457
chunks: orderedChunks,
485-
alerts: result.result.alerts,
486-
strategy: result.strategy,
458+
alerts: result.alerts,
487459
};
488460
}
489461

0 commit comments

Comments
 (0)