From 2d892fab7dd641fd06edc3e064ff2c79af61b215 Mon Sep 17 00:00:00 2001 From: Nate Sesti <33237525+sestinj@users.noreply.github.com> Date: Tue, 2 Jul 2024 18:31:26 -0700 Subject: [PATCH] Nate/indexing fixes (#1642) * fix pausing of indexing * don't send empty array to openai embeddings * catch embeddings errors without stopping entire indexing process --- core/core.ts | 10 +++++----- core/indexing/LanceDbIndex.ts | 18 ++++++++++++++---- .../embeddings/OpenAIEmbeddingsProvider.ts | 4 ++++ core/indexing/indexCodebase.ts | 3 ++- .../components/loaders/IndexingProgressBar.tsx | 2 +- 5 files changed, 26 insertions(+), 11 deletions(-) diff --git a/core/core.ts b/core/core.ts index 043ce86d2..9dcfc13ea 100644 --- a/core/core.ts +++ b/core/core.ts @@ -40,6 +40,9 @@ export class Core { indexingState: IndexingProgressUpdate; private globalContext = new GlobalContext(); private docsService = DocsService.getInstance(); + private readonly indexingPauseToken = new PauseToken( + this.globalContext.get("indexingPaused") === true, + ); private abortedMessageIds: Set = new Set(); @@ -79,9 +82,6 @@ export class Core { ); // Codebase Indexer and ContinueServerClient depend on IdeSettings - const indexingPauseToken = new PauseToken( - this.globalContext.get("indexingPaused") === true, - ); let codebaseIndexerResolve: (_: any) => void | undefined; this.codebaseIndexerPromise = new Promise( async (resolve) => (codebaseIndexerResolve = resolve), @@ -103,7 +103,7 @@ export class Core { new CodebaseIndexer( this.configHandler, this.ide, - new PauseToken(false), + this.indexingPauseToken, continueServerClient, ), ); @@ -569,7 +569,7 @@ export class Core { }); on("index/setPaused", (msg) => { new GlobalContext().update("indexingPaused", msg.data); - indexingPauseToken.paused = msg.data; + this.indexingPauseToken.paused = msg.data; }); on("index/indexingProgressBarInitialized", async (msg) => { // Triggered when progress bar is initialized. diff --git a/core/indexing/LanceDbIndex.ts b/core/indexing/LanceDbIndex.ts index c94e5f407..faa9461c6 100644 --- a/core/indexing/LanceDbIndex.ts +++ b/core/indexing/LanceDbIndex.ts @@ -105,10 +105,20 @@ export class LanceDbIndex implements CodebaseIndex { continue; } - // Calculate embeddings - const embeddings = await this.embeddingsProvider.embed( - chunks.map((c) => c.content), - ); + let embeddings: number[][]; + try { + // Calculate embeddings + embeddings = await this.embeddingsProvider.embed( + chunks.map((c) => c.content), + ); + } catch (e) { + // Rather than fail the entire indexing process, we'll just skip this file + // so that it may be picked up on the next indexing attempt + console.warn( + `Failed to generate embedding for ${chunks[0]?.filepath} with provider: ${this.embeddingsProvider.id}: ${e}`, + ); + continue; + } if (embeddings.some((emb) => emb === undefined)) { throw new Error( diff --git a/core/indexing/embeddings/OpenAIEmbeddingsProvider.ts b/core/indexing/embeddings/OpenAIEmbeddingsProvider.ts index bd7cb8665..01a85ee5e 100644 --- a/core/indexing/embeddings/OpenAIEmbeddingsProvider.ts +++ b/core/indexing/embeddings/OpenAIEmbeddingsProvider.ts @@ -47,6 +47,10 @@ class OpenAIEmbeddingsProvider extends BaseEmbeddingsProvider { return ( await Promise.all( batchedChunks.map(async (batch) => { + if (batch.length === 0) { + return []; + } + const fetchWithBackoff = () => withExponentialBackoff(() => this.fetch(this._getEndpoint(), { diff --git a/core/indexing/indexCodebase.ts b/core/indexing/indexCodebase.ts index b63c0a3cc..d34f7b90a 100644 --- a/core/indexing/indexCodebase.ts +++ b/core/indexing/indexCodebase.ts @@ -149,7 +149,8 @@ export class CodebaseIndexer { progress = (completedDirs + (completedRelativeExpectedTime + - indexProgress * codebaseIndex.relativeExpectedTime) / + Math.min(1.0, indexProgress) * + codebaseIndex.relativeExpectedTime) / totalRelativeExpectedTime) / workspaceDirs.length; yield { diff --git a/gui/src/components/loaders/IndexingProgressBar.tsx b/gui/src/components/loaders/IndexingProgressBar.tsx index 254510f90..1142913a5 100644 --- a/gui/src/components/loaders/IndexingProgressBar.tsx +++ b/gui/src/components/loaders/IndexingProgressBar.tsx @@ -183,7 +183,7 @@ const IndexingProgressBar = ({ }} > - Click to resume indexing ({Math.trunc(indexingState.progress * 100)} + Indexing paused ({Math.trunc(indexingState.progress * 100)} %)