Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically start Embeddings indexing #4091

Merged
merged 8 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/shared/src/experimentation/FeatureFlagProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ export enum FeatureFlag {

/** Interactive tutorial, primarily for onboarding */
CodyInteractiveTutorial = 'cody-interactive-tutorial',

/** Automatically start indexing using embeddings. */
CodyEmbeddingsAutoIndexing = 'cody-embeddings-auto-indexing',
}

const ONE_HOUR = 60 * 60 * 1000
Expand Down
2 changes: 1 addition & 1 deletion vscode/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export default defineConfig({
testDir: 'test/e2e',
timeout: 30000,
expect: {
timeout: isWin ? 5000 : 3000,
timeout: isWin ? 5000 : 5000,
},
})
36 changes: 31 additions & 5 deletions vscode/src/local-context/local-embeddings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ export async function createLocalEmbeddingsController(
((await featureFlagProvider.evaluateFeatureFlag(FeatureFlag.CodyUseSourcegraphEmbeddings))
? sourcegraphModelConfig
: openaiModelConfig)
return new LocalEmbeddingsController(context, config, modelConfig)
const autoIndexingEnabled = await featureFlagProvider.evaluateFeatureFlag(
FeatureFlag.CodyEmbeddingsAutoIndexing
)
return new LocalEmbeddingsController(context, config, modelConfig, autoIndexingEnabled)
}

export type LocalEmbeddingsConfig = Pick<
Expand Down Expand Up @@ -129,7 +132,8 @@ export class LocalEmbeddingsController
constructor(
private readonly context: vscode.ExtensionContext,
config: LocalEmbeddingsConfig,
private readonly modelConfig: EmbeddingsModelConfig
private readonly modelConfig: EmbeddingsModelConfig,
private readonly autoIndexingEnabled: boolean
) {
logDebug('LocalEmbeddingsController', 'constructor')
this.disposables.push(this.changeEmitter, this.statusEmitter)
Expand Down Expand Up @@ -161,7 +165,13 @@ export class LocalEmbeddingsController
await this.getService()
const repoUri = vscode.workspace.workspaceFolders?.[0]?.uri
if (repoUri && isFileURI(repoUri)) {
await this.eagerlyLoad(repoUri)
const loadedOk = await this.eagerlyLoad(repoUri)
if (!loadedOk) {
// failed to load the index, let's see if we should start indexing
if (this.canAutoIndex()) {
this.index()
Copy link
Member

@thenamankumar thenamankumar May 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not an expert in this part of the code, so I need someone to verify my concern here.

It might be the case that this.eagerlyLoad will return true, even if there are partial embeddings present for the repo. In that case, we will need check the status and call this.indexRetry.

I see it mentioned in the test plan that you have covered this case but I just wanted to double-check.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@rafax rafax May 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for checking and raising this - the existing treatment for partially indexed repos is that we require user action to continue indexing (screenshot), I tested that that this PR doesn't change that logic, I planned to have a separate PR for "automatic restart" once I understand why we don't automatically re-index in the first place (what comes to mind and what I saw in code is that some of the indexing processes can kill the agent, so automatic re-start could make Cody / agent crashloop?)
Screenshot 2024-05-09 at 09 05 10

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dominiccooney (as the original author of this) - is there a specific reason why we don't automatically re-start indexing after the extension is restarted? Would you be ok with making that change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this PR to restart indexing on extension startup (when no errors occurred in the current run) if we're using Sourcegraph provider and the feature-flag is enabled.

}
}
}
}

Expand Down Expand Up @@ -495,9 +505,20 @@ export class LocalEmbeddingsController
}
this.lastHealth = health
const hasIssue = health.numItemsNeedEmbedding > 0
await vscode.commands.executeCommand('setContext', 'cody.embeddings.hasIssue', hasIssue)
if (hasIssue) {
this.updateIssueStatusBar()
const canRetry = this.canAutoIndex() && !this.lastError
let retrySucceeded = true
if (canRetry) {
try {
await this.indexRetry()
} catch {
retrySucceeded = false
}
}
if (!canRetry || !retrySucceeded) {
await vscode.commands.executeCommand('setContext', 'cody.embeddings.hasIssue', hasIssue)
this.updateIssueStatusBar()
}
}
}

Expand All @@ -514,6 +535,11 @@ export class LocalEmbeddingsController
} is only ${percentDone.toFixed(0)}% complete.${options?.suffix || ''}`
}

// Check if auto-indexing is enabled and if we're using the Sourcegraph provider.
private canAutoIndex(): boolean {
return this.autoIndexingEnabled && this.modelConfig.provider === 'sourcegraph'
}

private updateIssueStatusBar(): void {
this.statusBar?.dispose()
this.statusBar = vscode.window.createStatusBarItem(
Expand Down
5 changes: 5 additions & 0 deletions vscode/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,11 @@ const register = async (
searchViewProvider.initialize()
}

if (localEmbeddings) {
// kick-off embeddings initialization
localEmbeddings.start()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question to reviewers - is this the right place to start this? We start symf indexing in the block above, and the call to .start() takes <1ms in local testing, so this should be fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds acceptable to me.

}

if (config.experimentalSupercompletions) {
disposables.push(new SupercompletionProvider({ statusBar, chat: chatClient }))
}
Expand Down
Loading