From 7a31675e82ab2ae808d76eb837e1be52e8c2217a Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Fri, 14 Feb 2025 16:02:58 -0800 Subject: [PATCH 1/8] docs embed test run --- core/indexing/docs/DocsService.ts | 115 ++++++++++++++++++------------ 1 file changed, 68 insertions(+), 47 deletions(-) diff --git a/core/indexing/docs/DocsService.ts b/core/indexing/docs/DocsService.ts index 2b0a92bf3..ecdf9dd2d 100644 --- a/core/indexing/docs/DocsService.ts +++ b/core/indexing/docs/DocsService.ts @@ -142,6 +142,27 @@ export default class DocsService { this.messenger?.send("indexing/statusUpdate", update); } + // buildDocsStatus( + // docConfig: SiteIndexingConfig, + // status: IndexingStatus["status"], + // description: string, + // progress: number, + // ): IndexingStatus { + // return { + // status, + // description, + // progress, + // type: "docs" as IndexingStatus["type"], + // id: docConfig.startUrl, + // embeddingsProviderId: this.config.embeddingsProvider.embeddingId, + // isReindexing: false, + // title: docConfig.title, + // debugInfo: `max depth: ${docConfig.maxDepth}`, + // icon: docConfig.faviconUrl, + // url: docConfig.startUrl, + // }; + // } + // A way for gui to retrieve initial statuses async initStatuses(): Promise { if (!this.config?.docs) { @@ -211,11 +232,7 @@ export default class DocsService { if (isAborted) { return true; } - // // Handle indexing disabled change mid-indexing - // if (this.config.disableIndexing) { - // this.abort(startUrl); - // return true; - // } + // Handle embeddings provider change mid-indexing if (this.config.embeddingsProvider.embeddingId !== startedWithEmbedder) { this.abort(startUrl); @@ -277,10 +294,6 @@ export default class DocsService { const oldConfig = this.config; this.config = newConfig; // IMPORTANT - need to set up top, other methods below use this without passing it in - // if (this.config.disableIndexing) { - // return; - // } - // No point in indexing if no docs context provider const hasDocsContextProvider = this.hasDocsContextProvider(); if (!hasDocsContextProvider) { @@ -368,25 +381,24 @@ export default class DocsService { siteIndexingConfig: SiteIndexingConfig, forceReindex: boolean = false, ): Promise { - // if (this.config.disableIndexing) { - // console.warn("Attempting to add/index docs when indexing is disabled"); - // return; - // } const { startUrl, useLocalCrawling, maxDepth } = siteIndexingConfig; + // First, if indexing is already in process, don't attempt + // This queue is necessary because indexAndAdd is invoked circularly by config edits + if (this.docsIndexingQueue.has(startUrl)) { + return; + } + const { isPreindexed, provider } = await this.getEmbeddingsProvider(startUrl); if (isPreindexed) { console.warn("Attempted to indexAndAdd pre-indexed doc"); return; } - - // Queue - indexAndAdd is invoked circularly by config edits. This prevents duplicate runs - if (this.docsIndexingQueue.has(startUrl)) { - return; - } - const startedWithEmbedder = provider.embeddingId; + + // Check if doc has been successfully indexed with the given embedder + // Note at this point we know it's not a pre-indexed doc const indexExists = await this.hasMetadata(startUrl); // Build status update - most of it is fixed values @@ -404,22 +416,6 @@ export default class DocsService { url: siteIndexingConfig.startUrl, }; - // Clear current indexes if reIndexing - if (indexExists) { - if (forceReindex) { - await this.deleteIndexes(startUrl); - } else { - this.handleStatusUpdate({ - ...fixedStatus, - progress: 1, - description: "Complete", - status: "complete", - debugInfo: "Already indexed", - }); - return; - } - } - // If not force-reindexing and has failed with same config, don't reattempt if (!forceReindex) { const globalContext = new GlobalContext(); @@ -460,6 +456,36 @@ export default class DocsService { globalContext.update("failedDocs", newFailedDocs); }; + // Do a test run on the embedder + // This particular failure will not mark as a failed config in global context + // Since SiteIndexingConfig is likely to be valid + try { + await provider.embed(["continue-test-run"]); + } catch (e) { + console.error("Failed to test embeddings connection", e); + void this.ide.showToast( + "error", + "Embeddings error: Failed to test embeddings connection. check your embeddings model config", + ); + return; + } + + // Clear current indexes if reIndexing + if (indexExists) { + if (forceReindex) { + await this.deleteIndexes(startUrl); + } else { + this.handleStatusUpdate({ + ...fixedStatus, + progress: 1, + description: "Complete", + status: "complete", + debugInfo: "Already indexed", + }); + return; + } + } + try { this.docsIndexingQueue.add(startUrl); @@ -564,9 +590,10 @@ export default class DocsService { }); try { - const subpathEmbeddings = await provider.embed( - article.chunks.map((c) => c.content), - ); + const subpathEmbeddings = + article.chunks.length > 0 + ? await provider.embed(article.chunks.map((c) => c.content)) + : []; chunks.push(...article.chunks); embeddings.push(...subpathEmbeddings); const toWait = 100 * this.docsIndexingQueue.size + 50; @@ -592,7 +619,6 @@ export default class DocsService { }); void this.ide.showToast("info", `Failed to index ${startUrl}`); - this.docsIndexingQueue.delete(startUrl); markFailedInGlobalContext(); return; } @@ -635,11 +661,6 @@ export default class DocsService { favicon, }); - this.docsIndexingQueue.delete(startUrl); - - if (this.shouldCancel(startUrl, startedWithEmbedder)) { - return; - } this.handleStatusUpdate({ ...fixedStatus, description: "Complete", @@ -916,7 +937,7 @@ export default class DocsService { // Anything found in old config, new config, AND sqlite that doesn't match should be reindexed // TODO if only favicon and title change, only update, don't embed // Otherwise anything found in new config that isn't in sqlite should be added/indexed - const newDocs: SiteIndexingConfig[] = []; + const addedDocs: SiteIndexingConfig[] = []; const changedDocs: SiteIndexingConfig[] = []; for (const doc of newConfigDocs) { const currentIndexedDoc = currentStartUrls.includes(doc.startUrl); @@ -953,14 +974,14 @@ export default class DocsService { } } } else { - newDocs.push(doc); + addedDocs.push(doc); void Telemetry.capture("add_docs_config", { url: doc.startUrl }); } } await Promise.allSettled([ ...changedDocs.map((doc) => this.indexAndAdd(doc, true)), - ...newDocs.map((doc) => this.indexAndAdd(doc)), + ...addedDocs.map((doc) => this.indexAndAdd(doc)), ]); for (const doc of deletedDocs) { From aa9de94df005fc9c235bb57668782da54744cffa Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Fri, 14 Feb 2025 16:04:45 -0800 Subject: [PATCH 2/8] cleanup --- core/indexing/docs/DocsService.ts | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/core/indexing/docs/DocsService.ts b/core/indexing/docs/DocsService.ts index ecdf9dd2d..49a22b144 100644 --- a/core/indexing/docs/DocsService.ts +++ b/core/indexing/docs/DocsService.ts @@ -142,27 +142,6 @@ export default class DocsService { this.messenger?.send("indexing/statusUpdate", update); } - // buildDocsStatus( - // docConfig: SiteIndexingConfig, - // status: IndexingStatus["status"], - // description: string, - // progress: number, - // ): IndexingStatus { - // return { - // status, - // description, - // progress, - // type: "docs" as IndexingStatus["type"], - // id: docConfig.startUrl, - // embeddingsProviderId: this.config.embeddingsProvider.embeddingId, - // isReindexing: false, - // title: docConfig.title, - // debugInfo: `max depth: ${docConfig.maxDepth}`, - // icon: docConfig.faviconUrl, - // url: docConfig.startUrl, - // }; - // } - // A way for gui to retrieve initial statuses async initStatuses(): Promise { if (!this.config?.docs) { From c1b9775855c3414a6f0b4c24d460f7430706df0a Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Fri, 14 Feb 2025 16:06:27 -0800 Subject: [PATCH 3/8] copy change --- core/indexing/docs/DocsService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/indexing/docs/DocsService.ts b/core/indexing/docs/DocsService.ts index 49a22b144..4c080f3fb 100644 --- a/core/indexing/docs/DocsService.ts +++ b/core/indexing/docs/DocsService.ts @@ -444,7 +444,7 @@ export default class DocsService { console.error("Failed to test embeddings connection", e); void this.ide.showToast( "error", - "Embeddings error: Failed to test embeddings connection. check your embeddings model config", + "Failed to test embeddings connection. check your embeddings model configuration", ); return; } From d5df62934c20f297e3bacbd3e1ddaff6dda6c288 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Fri, 14 Feb 2025 17:17:07 -0800 Subject: [PATCH 4/8] reorder --- core/indexing/docs/DocsService.ts | 68 ++++++++++++++++--------------- 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/core/indexing/docs/DocsService.ts b/core/indexing/docs/DocsService.ts index 4c080f3fb..8582fd9de 100644 --- a/core/indexing/docs/DocsService.ts +++ b/core/indexing/docs/DocsService.ts @@ -367,6 +367,7 @@ export default class DocsService { if (this.docsIndexingQueue.has(startUrl)) { return; } + this.docsIndexingQueue.add(startUrl); const { isPreindexed, provider } = await this.getEmbeddingsProvider(startUrl); @@ -416,6 +417,31 @@ export default class DocsService { } } + if (indexExists && !forceReindex) { + this.handleStatusUpdate({ + ...fixedStatus, + progress: 1, + description: "Complete", + status: "complete", + debugInfo: "Already indexed", + }); + return; + } + + // Do a test run on the embedder + // This particular failure will not mark as a failed config in global context + // Since SiteIndexingConfig is likely to be valid + try { + await provider.embed(["continue-test-run"]); + } catch (e) { + console.error("Failed to test embeddings connection", e); + void this.ide.showToast( + "error", + "Failed to test embeddings connection. check your embeddings model configuration", + ); + return; + } + const markFailedInGlobalContext = () => { const globalContext = new GlobalContext(); const failedDocs = globalContext.get("failedDocs") ?? []; @@ -435,39 +461,14 @@ export default class DocsService { globalContext.update("failedDocs", newFailedDocs); }; - // Do a test run on the embedder - // This particular failure will not mark as a failed config in global context - // Since SiteIndexingConfig is likely to be valid - try { - await provider.embed(["continue-test-run"]); - } catch (e) { - console.error("Failed to test embeddings connection", e); - void this.ide.showToast( - "error", - "Failed to test embeddings connection. check your embeddings model configuration", - ); - return; - } - - // Clear current indexes if reIndexing - if (indexExists) { - if (forceReindex) { - await this.deleteIndexes(startUrl); - } else { - this.handleStatusUpdate({ - ...fixedStatus, - progress: 1, - description: "Complete", - status: "complete", - debugInfo: "Already indexed", - }); - return; - } - } - try { this.docsIndexingQueue.add(startUrl); + // Clear current indexes if reIndexing + if (indexExists && forceReindex) { + await this.deleteIndexes(startUrl); + } + this.addToConfig(siteIndexingConfig); this.handleStatusUpdate({ @@ -655,7 +656,11 @@ export default class DocsService { removeFromFailedGlobalContext(); } catch (e) { - let description = `Error getting docs from: ${siteIndexingConfig.startUrl}`; + console.error( + `Error indexing docs at: ${siteIndexingConfig.startUrl}`, + e, + ); + let description = `Error indexing docs at: ${siteIndexingConfig.startUrl}`; if (e instanceof Error) { if ( e.message.includes("github.com") && @@ -664,7 +669,6 @@ export default class DocsService { description = "Github rate limit exceeded"; // This text is used verbatim elsewhere } } - console.error("Error indexing docs", e); this.handleStatusUpdate({ ...fixedStatus, description, From c4f42cefbeb7a086ccd02fa6041c0fe550930080 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Fri, 14 Feb 2025 21:16:55 -0800 Subject: [PATCH 5/8] fix docs stuck at 0 --- core/indexing/docs/DocsService.ts | 3 ++- gui/src/components/indexing/DocsIndexingStatus.tsx | 2 +- gui/src/hooks/useSetup.ts | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/core/indexing/docs/DocsService.ts b/core/indexing/docs/DocsService.ts index 8582fd9de..77e7543d8 100644 --- a/core/indexing/docs/DocsService.ts +++ b/core/indexing/docs/DocsService.ts @@ -157,7 +157,8 @@ export default class DocsService { const currentStatus = this.statuses.get(doc.startUrl); if (currentStatus) { - return currentStatus; + this.handleStatusUpdate(currentStatus); + return; } const sharedStatus = { diff --git a/gui/src/components/indexing/DocsIndexingStatus.tsx b/gui/src/components/indexing/DocsIndexingStatus.tsx index fe64ae2dc..c9d2a9076 100644 --- a/gui/src/components/indexing/DocsIndexingStatus.tsx +++ b/gui/src/components/indexing/DocsIndexingStatus.tsx @@ -87,11 +87,11 @@ function DocsIndexingStatus({ docConfig }: IndexingStatusViewerProps) { const Icon = STATUS_TO_ICON[status?.status]; const showProgressPercentage = progressPercentage !== "100"; + console.log("STatus for " + docConfig.title, status); if (hasDeleted) return null; return (
- {/* {`${status.type} - ${status.id} - ${status.status} - ${status.progress} - ${status.description} - ${status.icon}`} */}
diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts index 582c962ad..142b8de4d 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/useSetup.ts @@ -242,6 +242,7 @@ function useSetup() { }); useWebviewListener("indexing/statusUpdate", async (data) => { + debugger; dispatch(updateIndexingStatus(data)); }); From e81099be8ae7aa27e6d52f0ac5b7ce65744260da Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Fri, 14 Feb 2025 21:35:11 -0800 Subject: [PATCH 6/8] sort docs by indexing status --- .../indexing/DocsIndexingStatuses.tsx | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/gui/src/components/indexing/DocsIndexingStatuses.tsx b/gui/src/components/indexing/DocsIndexingStatuses.tsx index db312aef9..f1e261dfb 100644 --- a/gui/src/components/indexing/DocsIndexingStatuses.tsx +++ b/gui/src/components/indexing/DocsIndexingStatuses.tsx @@ -7,11 +7,15 @@ import { useAppSelector } from "../../redux/hooks"; import { useContext, useMemo } from "react"; import { ExclamationTriangleIcon } from "@heroicons/react/24/outline"; import { IdeMessengerContext } from "../../context/IdeMessenger"; +import { IndexingStatus } from "core"; function DocsIndexingStatuses() { const dispatch = useDispatch(); const config = useAppSelector((store) => store.config.config); const ideMessenger = useContext(IdeMessengerContext); + const indexingStatuses = useAppSelector( + (store) => store.indexing.indexing.statuses, + ); const hasDocsProvider = useMemo(() => { return !!config.contextProviders?.some( @@ -19,15 +23,31 @@ function DocsIndexingStatuses() { ); }, [config]); - const configDocs = useMemo(() => { - return config.docs ?? []; - }, [config]); + // TODO - this might significantly impact performance during indexing + const sortedConfigDocs = useMemo(() => { + const sorter = (status: IndexingStatus["status"]) => { + // TODO - further sorting? + if (status === "indexing" || status === "paused") return 0; + if (status === "failed") return 1; + if (status === "aborted" || status === "pending") return 2; + return 3; + }; + + const docs = [...(config.docs ?? [])]; + docs.sort((a, b) => + sorter(indexingStatuses[b.startUrl]?.status ?? "pending") > + sorter(indexingStatuses[a.startUrl]?.status ?? "pending") + ? -1 + : 1, + ); + return docs; + }, [config, indexingStatuses]); return (

@docs indexes

- {configDocs.length ? ( + {sortedConfigDocs.length ? ( { @@ -41,7 +61,7 @@ function DocsIndexingStatuses() {
{hasDocsProvider ? ( - configDocs.length ? ( + sortedConfigDocs.length ? ( "Manage your documentation sources" ) : ( "No docs yet" @@ -72,7 +92,7 @@ function DocsIndexingStatuses() {
- {configDocs.length === 0 && ( + {sortedConfigDocs.length === 0 && ( { @@ -84,7 +104,7 @@ function DocsIndexingStatuses() { )}
- {configDocs.map((doc) => { + {sortedConfigDocs.map((doc) => { return ; })}
From d710be468ce59078ea390fb016881c77b5894602 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Fri, 14 Feb 2025 21:38:18 -0800 Subject: [PATCH 7/8] cleanup --- core/indexing/docs/DocsService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/indexing/docs/DocsService.ts b/core/indexing/docs/DocsService.ts index 77e7543d8..ba74b3a01 100644 --- a/core/indexing/docs/DocsService.ts +++ b/core/indexing/docs/DocsService.ts @@ -365,10 +365,10 @@ export default class DocsService { // First, if indexing is already in process, don't attempt // This queue is necessary because indexAndAdd is invoked circularly by config edits + // TODO shouldn't really be a gap between adding and checking in queue but probably fine if (this.docsIndexingQueue.has(startUrl)) { return; } - this.docsIndexingQueue.add(startUrl); const { isPreindexed, provider } = await this.getEmbeddingsProvider(startUrl); From 06166cb9b43436f0b816f1f31fdd77e8a7b34d99 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Fri, 14 Feb 2025 21:47:03 -0800 Subject: [PATCH 8/8] cleanup --- gui/src/components/indexing/DocsIndexingStatus.tsx | 1 - gui/src/hooks/useSetup.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/gui/src/components/indexing/DocsIndexingStatus.tsx b/gui/src/components/indexing/DocsIndexingStatus.tsx index c9d2a9076..224d96265 100644 --- a/gui/src/components/indexing/DocsIndexingStatus.tsx +++ b/gui/src/components/indexing/DocsIndexingStatus.tsx @@ -87,7 +87,6 @@ function DocsIndexingStatus({ docConfig }: IndexingStatusViewerProps) { const Icon = STATUS_TO_ICON[status?.status]; const showProgressPercentage = progressPercentage !== "100"; - console.log("STatus for " + docConfig.title, status); if (hasDeleted) return null; return ( diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts index 142b8de4d..582c962ad 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/useSetup.ts @@ -242,7 +242,6 @@ function useSetup() { }); useWebviewListener("indexing/statusUpdate", async (data) => { - debugger; dispatch(updateIndexingStatus(data)); });