From e0079a43721f6002ff59e2eaa79dc8768a6f66f5 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Mon, 22 Jul 2024 13:22:31 -0700 Subject: [PATCH] feat: allow JetBrains users to index docs (#1797) * feat: allow JetBrains users to index docs * update docs service * update global context * throw error popup on jetbrains + transformers * update toast notifications * update typings * fix tsc errors --- core/context/index.ts | 1 + core/context/providers/DocsContextProvider.ts | 195 ++++++++++++------ core/control-plane/TeamAnalytics.ts | 1 + core/core.ts | 149 ++++++++++--- core/index.d.ts | 7 +- core/indexing/docs/DocsService.ts | 76 ++++--- core/indexing/docs/crawl.ts | 5 +- core/indexing/docs/preIndexedDocs.ts | 108 +++++----- core/util/GlobalContext.ts | 8 + gui/src/components/dialogs/AddDocsDialog.tsx | 1 + 10 files changed, 369 insertions(+), 182 deletions(-) diff --git a/core/context/index.ts b/core/context/index.ts index 6e98fa456..7ad48f112 100644 --- a/core/context/index.ts +++ b/core/context/index.ts @@ -6,6 +6,7 @@ import type { IContextProvider, LoadSubmenuItemsArgs, } from "../index.js"; + export abstract class BaseContextProvider implements IContextProvider { options: { [key: string]: any }; diff --git a/core/context/providers/DocsContextProvider.ts b/core/context/providers/DocsContextProvider.ts index c48b5a1fd..c79ee4885 100644 --- a/core/context/providers/DocsContextProvider.ts +++ b/core/context/providers/DocsContextProvider.ts @@ -1,15 +1,16 @@ -import fetch from "node-fetch"; import { + Chunk, ContextItem, ContextProviderDescription, ContextProviderExtras, ContextSubmenuItem, + EmbeddingsProvider, LoadSubmenuItemsArgs, - SiteIndexingConfig, + Reranker, } from "../../index.js"; import { DocsService } from "../../indexing/docs/DocsService.js"; -import configs from "../../indexing/docs/preIndexedDocs.js"; -import TransformersJsEmbeddingsProvider from "../../indexing/embeddings/TransformersJsEmbeddingsProvider.js"; +import preIndexedDocs from "../../indexing/docs/preIndexedDocs.js"; +import { Telemetry } from "../../util/posthog.js"; import { BaseContextProvider } from "../index.js"; class DocsContextProvider extends BaseContextProvider { @@ -21,6 +22,7 @@ class DocsContextProvider extends BaseContextProvider { description: "Type to search docs", type: "submenu", }; + private docsService: DocsService; constructor(options: any) { @@ -28,18 +30,96 @@ class DocsContextProvider extends BaseContextProvider { this.docsService = DocsService.getInstance(); } + private async _rerankChunks( + chunks: Chunk[], + reranker: NonNullable, + fullInput: ContextProviderExtras["fullInput"], + ) { + let chunksCopy = [...chunks]; + + try { + const scores = await reranker.rerank(fullInput, chunksCopy); + + chunksCopy.sort( + (a, b) => scores[chunksCopy.indexOf(b)] - scores[chunksCopy.indexOf(a)], + ); + + chunksCopy = chunksCopy.splice( + 0, + this.options?.nFinal ?? DocsContextProvider.DEFAULT_N_FINAL, + ); + } catch (e) { + console.warn(`Failed to rerank docs results: ${e}`); + + chunksCopy = chunksCopy.splice( + 0, + this.options?.nFinal ?? DocsContextProvider.DEFAULT_N_FINAL, + ); + } + + return chunksCopy; + } + + private _sortByPreIndexedDocs( + submenuItems: ContextSubmenuItem[], + ): ContextSubmenuItem[] { + // Sort submenuItems such that the objects with titles which don't occur in configs occur first, and alphabetized + return submenuItems.sort((a, b) => { + const aTitleInConfigs = a.metadata?.preIndexed ?? false; + const bTitleInConfigs = b.metadata?.preIndexed ?? false; + + // Primary criterion: Items not in configs come first + if (!aTitleInConfigs && bTitleInConfigs) { + return -1; + } else if (aTitleInConfigs && !bTitleInConfigs) { + return 1; + } else { + // Secondary criterion: Alphabetical order when both items are in the same category + return a.title.toString().localeCompare(b.title.toString()); + } + }); + } + async getContextItems( query: string, extras: ContextProviderExtras, ): Promise { - // Not supported in JetBrains IDEs right now - if ((await extras.ide.getIdeInfo()).ideType === "jetbrains") { - throw new Error( - "The @docs context provider is not currently supported in JetBrains IDEs. We'll have an update soon!", + const ideInfo = await extras.ide.getIdeInfo(); + const isJetBrains = ideInfo.ideType === "jetbrains"; + + const isJetBrainsAndPreIndexedDocsProvider = + this.docsService.isJetBrainsAndPreIndexedDocsProvider( + ideInfo, + extras.embeddingsProvider.id, ); + + if (isJetBrainsAndPreIndexedDocsProvider) { + extras.ide.errorPopup( + `${DocsService.preIndexedDocsEmbeddingsProvider.id} is configured as ` + + "the embeddings provider, but it cannot be used with JetBrains. " + + "Please select a different embeddings provider to use the '@docs' " + + "context provider.", + ); + + return []; + } + + const preIndexedDoc = preIndexedDocs[query]; + + let embeddingsProvider: EmbeddingsProvider; + + if (!!preIndexedDoc && !isJetBrains) { + // Pre-indexed docs should be filtered out in `loadSubmenuItems`, + // for JetBrains users, but we sanity check that here + Telemetry.capture("docs_pre_indexed_doc_used", { + doc: preIndexedDoc["title"], + }); + + embeddingsProvider = DocsService.preIndexedDocsEmbeddingsProvider; + } else { + embeddingsProvider = extras.embeddingsProvider; } - const embeddingsProvider = new TransformersJsEmbeddingsProvider(); const [vector] = await embeddingsProvider.embed([extras.fullInput]); let chunks = await this.docsService.retrieve( @@ -50,22 +130,11 @@ class DocsContextProvider extends BaseContextProvider { ); if (extras.reranker) { - try { - const scores = await extras.reranker.rerank(extras.fullInput, chunks); - chunks.sort( - (a, b) => scores[chunks.indexOf(b)] - scores[chunks.indexOf(a)], - ); - chunks = chunks.splice( - 0, - this.options?.nFinal ?? DocsContextProvider.DEFAULT_N_FINAL, - ); - } catch (e) { - console.warn(`Failed to rerank docs results: ${e}`); - chunks = chunks.splice( - 0, - this.options?.nFinal ?? DocsContextProvider.DEFAULT_N_FINAL, - ); - } + chunks = await this._rerankChunks( + chunks, + extras.reranker, + extras.fullInput, + ); } return [ @@ -80,7 +149,7 @@ class DocsContextProvider extends BaseContextProvider { .slice(1) .join("/") : chunk.otherMetadata?.title || chunk.filepath, - description: chunk.filepath, // new URL(chunk.filepath, query).toString(), + description: chunk.filepath, content: chunk.content, })) .reverse(), @@ -93,59 +162,51 @@ class DocsContextProvider extends BaseContextProvider { ]; } - // Get combined site configs from preIndexedDocs and options.sites. - private _getDocsSitesConfig(): SiteIndexingConfig[] { - return [...configs, ...(this.options?.sites || [])]; - } - - // Get indexed docs as ContextSubmenuItems from database. - private async _getIndexedDocsContextSubmenuItems(): Promise< - ContextSubmenuItem[] - > { - return (await this.docsService.list()).map((doc) => ({ - title: doc.title, - description: new URL(doc.baseUrl).hostname, - id: doc.baseUrl, - })); - } - async loadSubmenuItems( args: LoadSubmenuItemsArgs, ): Promise { + const ideInfo = await args.ide.getIdeInfo(); + const isJetBrains = ideInfo.ideType === "jetbrains"; + const configSites = this.options?.sites || []; const submenuItemsMap = new Map(); - for (const item of await this._getIndexedDocsContextSubmenuItems()) { - submenuItemsMap.set(item.id, item); + if (!isJetBrains) { + // Currently, we generate and host embeddings for pre-indexed docs using transformers.js. + // However, we don't ship transformers.js with the JetBrains extension. + // So, we only include pre-indexed docs in the submenu for non-JetBrains IDEs. + for (const { startUrl, title } of Object.values(preIndexedDocs)) { + submenuItemsMap.set(startUrl, { + title, + id: startUrl, + description: new URL(startUrl).hostname, + metadata: { + preIndexed: true, + }, + }); + } } - for (const config of this._getDocsSitesConfig()) { - submenuItemsMap.set(config.startUrl, { - id: config.startUrl, - title: config.title, - description: new URL(config.startUrl).hostname, - metadata: { - preIndexed: !!configs.find((cnf) => cnf.title === config.title), - }, + for (const { title, baseUrl } of await this.docsService.list()) { + submenuItemsMap.set(baseUrl, { + title, + id: baseUrl, + description: new URL(baseUrl).hostname, + }); + } + + for (const { startUrl, title } of configSites) { + submenuItemsMap.set(startUrl, { + title, + id: startUrl, + description: new URL(startUrl).hostname, }); } const submenuItems = Array.from(submenuItemsMap.values()); - // Sort submenuItems such that the objects with titles which don't occur in configs occur first, and alphabetized - submenuItems.sort((a, b) => { - const aTitleInConfigs = a.metadata?.preIndexed ?? false; - const bTitleInConfigs = b.metadata?.preIndexed ?? false; - - // Primary criterion: Items not in configs come first - if (!aTitleInConfigs && bTitleInConfigs) { - return -1; - } else if (aTitleInConfigs && !bTitleInConfigs) { - return 1; - } else { - // Secondary criterion: Alphabetical order when both items are in the same category - return a.title.toString().localeCompare(b.title.toString()); - } - }); + if (!isJetBrains) { + return this._sortByPreIndexedDocs(submenuItems); + } return submenuItems; } diff --git a/core/control-plane/TeamAnalytics.ts b/core/control-plane/TeamAnalytics.ts index bc529cecd..302b80177 100644 --- a/core/control-plane/TeamAnalytics.ts +++ b/core/control-plane/TeamAnalytics.ts @@ -6,6 +6,7 @@ import PostHogAnalyticsProvider from "./analytics/PostHogAnalyticsProvider"; function createAnalyticsProvider( config: Analytics, ): IAnalyticsProvider | undefined { + // @ts-ignore switch (config.provider) { case "posthog": return new PostHogAnalyticsProvider(); diff --git a/core/core.ts b/core/core.ts index 3244ae9ef..688f0c8a9 100644 --- a/core/core.ts +++ b/core/core.ts @@ -1,6 +1,7 @@ import { v4 as uuidv4 } from "uuid"; import type { ContextItemId, + EmbeddingsProvider, IDE, IndexingProgressUpdate, SiteIndexingConfig, @@ -16,9 +17,9 @@ import { import { createNewPromptFile } from "./config/promptFile.js"; import { addModel, addOpenAIKey, deleteModel } from "./config/util.js"; import { ContinueServerClient } from "./continueServer/stubs/client.js"; -import { ControlPlaneClient } from "./control-plane/client"; +import { ControlPlaneClient } from "./control-plane/client.js"; import { CodebaseIndexer, PauseToken } from "./indexing/CodebaseIndexer.js"; -import { DocsService } from "./indexing/docs/DocsService"; +import { DocsService } from "./indexing/docs/DocsService.js"; import TransformersJsEmbeddingsProvider from "./indexing/embeddings/TransformersJsEmbeddingsProvider.js"; import Ollama from "./llm/llms/Ollama.js"; import type { FromCoreProtocol, ToCoreProtocol } from "./protocol"; @@ -73,20 +74,35 @@ export class Core { private readonly onWrite: (text: string) => Promise = async () => {}, ) { this.indexingState = { status: "loading", desc: "loading", progress: 0 }; + const ideSettingsPromise = messenger.request("getIdeSettings", undefined); const sessionInfoPromise = messenger.request("getControlPlaneSessionInfo", { silent: true, }); + this.controlPlaneClient = new ControlPlaneClient(sessionInfoPromise); + this.configHandler = new ConfigHandler( this.ide, ideSettingsPromise, this.onWrite, this.controlPlaneClient, ); + this.configHandler.onConfigUpdate( (() => this.messenger.send("configUpdate", undefined)).bind(this), ); + + this.configHandler.onConfigUpdate(async ({ embeddingsProvider }) => { + if ( + await this.shouldReindexDocsOnNewEmbeddingsProvider( + embeddingsProvider.id, + ) + ) { + await this.reindexDocsOnNewEmbeddingsProvider(embeddingsProvider); + } + }); + this.configHandler.onDidChangeAvailableProfiles((profiles) => this.messenger.send("didChangeAvailableProfiles", { profiles }), ); @@ -117,6 +133,7 @@ export class Core { continueServerClient, ), ); + this.ide .getWorkspaceDirs() .then((dirs) => this.refreshCodebaseIndex(dirs)); @@ -221,19 +238,8 @@ export class Core { // Context providers on("context/addDocs", async (msg) => { - const siteIndexingConfig: SiteIndexingConfig = { - startUrl: msg.data.startUrl, - rootUrl: msg.data.rootUrl, - title: msg.data.title, - maxDepth: msg.data.maxDepth, - faviconUrl: new URL("/favicon.ico", msg.data.rootUrl).toString(), - }; + await this.getEmbeddingsProviderAndIndexDoc(msg.data); - for await (const _ of this.docsService.indexAndAdd( - siteIndexingConfig, - new TransformersJsEmbeddingsProvider(), - )) { - } this.ide.infoPopup(`Successfully indexed ${msg.data.title}`); this.messenger.send("refreshSubmenuItems", undefined); }); @@ -248,11 +254,18 @@ export class Core { (provider) => provider.description.title === "docs", ); - const siteIndexingOptions: SiteIndexingConfig[] = provider - ? ((mProvider) => mProvider?.options?.sites || [])({ ...provider }) - : []; + if (!provider) { + this.ide.infoPopup("No docs in configuration"); + return; + } + + const siteIndexingOptions: SiteIndexingConfig[] = ((mProvider) => + mProvider?.options?.sites || [])({ ...provider }); + + for (const site of siteIndexingOptions) { + await this.getEmbeddingsProviderAndIndexDoc(site, msg.data.reIndex); + } - await this.indexDocs(siteIndexingOptions, msg.data.reIndex); this.ide.infoPopup("Docs indexing completed"); }); on("context/loadSubmenuItems", async (msg) => { @@ -640,21 +653,93 @@ export class Core { } } - private async indexDocs( - sites: SiteIndexingConfig[], - reIndex: boolean, + private async shouldReindexDocsOnNewEmbeddingsProvider( + curEmbeddingsProviderId: EmbeddingsProvider["id"], + ): Promise { + const ideInfo = await this.ide.getIdeInfo(); + const isJetBrainsAndPreIndexedDocsProvider = + this.docsService.isJetBrainsAndPreIndexedDocsProvider( + ideInfo, + curEmbeddingsProviderId, + ); + + if (isJetBrainsAndPreIndexedDocsProvider) { + this.ide.errorPopup( + `${DocsService.preIndexedDocsEmbeddingsProvider.id} cannot be used as an embeddings provider with JetBrains. Please select a different embeddings provider.`, + ); + + this.globalContext.update( + "curEmbeddingsProviderId", + curEmbeddingsProviderId, + ); + + return false; + } + + const lastEmbeddingsProviderId = this.globalContext.get( + "curEmbeddingsProviderId", + ); + + if (!lastEmbeddingsProviderId) { + // If it's the first time we're setting the `curEmbeddingsProviderId` + // global state, we don't need to reindex docs + this.globalContext.update( + "curEmbeddingsProviderId", + curEmbeddingsProviderId, + ); + + return false; + } + + return lastEmbeddingsProviderId !== curEmbeddingsProviderId; + } + + private async getEmbeddingsProviderAndIndexDoc( + site: SiteIndexingConfig, + reIndex: boolean = false, ): Promise { - for (const site of sites) { - for await (const update of this.docsService.indexAndAdd( - site, - new TransformersJsEmbeddingsProvider(), - reIndex, - )) { - // Temporary disabled posting progress updates to the UI due to - // possible collision with code indexing progress updates. - // this.messenger.request("indexProgress", update); - // this.indexingState = update; - } + const config = await this.config(); + const { embeddingsProvider } = config; + + for await (const update of this.docsService.indexAndAdd( + site, + embeddingsProvider, + reIndex, + )) { + // Temporary disabled posting progress updates to the UI due to + // possible collision with code indexing progress updates. + // this.messenger.request("indexProgress", update); + // this.indexingState = update; } } + + private async reindexDocsOnNewEmbeddingsProvider( + embeddingsProvider: EmbeddingsProvider, + ) { + const docs = await this.docsService.list(); + + if (docs.length === 0) { + return; + } + + this.ide.infoPopup("Reindexing docs with new embeddings provider"); + + for (const { title, baseUrl } of docs) { + await this.docsService.delete(baseUrl); + + const generator = this.docsService.indexAndAdd( + { title, startUrl: baseUrl, rootUrl: baseUrl }, + embeddingsProvider, + ); + + while (!(await generator.next()).done) {} + } + + // Important that this only is invoked after we have successfully + // cleared and reindex the docs so that the table cannot end up in an + // invalid state. + this.globalContext.update("curEmbeddingsProviderId", embeddingsProvider.id); + + this.ide.infoPopup("Completed reindexing of all docs"); + } } diff --git a/core/index.d.ts b/core/index.d.ts index 53205fe82..bd8ddf096 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -760,7 +760,12 @@ export interface EmbeddingsProvider { embed(chunks: string[]): Promise; } -export type RerankerName = "cohere" | "voyage" | "llm" | "free-trial" | "huggingface-tei"; +export type RerankerName = + | "cohere" + | "voyage" + | "llm" + | "free-trial" + | "huggingface-tei"; export interface RerankerDescription { name: RerankerName; diff --git a/core/indexing/docs/DocsService.ts b/core/indexing/docs/DocsService.ts index bbec8cc65..8d2854b9e 100644 --- a/core/indexing/docs/DocsService.ts +++ b/core/indexing/docs/DocsService.ts @@ -3,15 +3,16 @@ import sqlite3 from "sqlite3"; import { Chunk, EmbeddingsProvider, + IdeInfo, IndexingProgressUpdate, SiteIndexingConfig, } from "../../index.js"; import { getDocsSqlitePath, getLanceDbPath } from "../../util/paths.js"; - import { Article, chunkArticle, pageToArticle } from "./article.js"; import { crawlPage } from "./crawl.js"; import { downloadFromS3, SiteIndexingResults } from "./preIndexed.js"; -import { default as configs } from "./preIndexedDocs.js"; +import preIndexedDocs from "./preIndexedDocs.js"; +import TransformersJsEmbeddingsProvider from "../embeddings/TransformersJsEmbeddingsProvider.js"; // Purposefully lowercase because lancedb converts interface LanceDbDocsRow { @@ -29,6 +30,8 @@ interface LanceDbDocsRow { export class DocsService { private static instance: DocsService; private static DOCS_TABLE_NAME = "docs"; + public static preIndexedDocsEmbeddingsProvider = + new TransformersJsEmbeddingsProvider(); private _sqliteTable: Database | undefined; private docsIndexingQueue: Set = new Set(); @@ -70,32 +73,35 @@ export class DocsService { nested = false, ): Promise { const lance = await this.getLanceDb(); - const db = await this.getSqliteTable(); + const tableNames = await lance.tableNames(); + const preIndexedDoc = preIndexedDocs[baseUrl]; + const isPreIndexedDoc = !!preIndexedDoc; + let shouldDownloadPreIndexedDoc = + !tableNames.includes(DocsService.DOCS_TABLE_NAME) && isPreIndexedDoc; - const downloadDocs = async () => { - const config = configs.find((config) => config.startUrl === baseUrl); - if (config) { - await this.downloadPreIndexedDocs(embeddingsProviderId, config.title); - return await this.retrieve( - baseUrl, - vector, - nRetrieve, - embeddingsProviderId, - true, - ); - } - return undefined; + const downloadAndRetrievePreIndexedDoc = async ( + preIndexedDoc: SiteIndexingConfig, + ) => { + await this.downloadAndAddPreIndexedDocs( + embeddingsProviderId, + preIndexedDoc.title, + ); + + return await this.retrieve( + baseUrl, + vector, + nRetrieve, + embeddingsProviderId, + true, + ); }; - const tableNames = await lance.tableNames(); - if (!tableNames.includes(DocsService.DOCS_TABLE_NAME)) { - const downloaded = await downloadDocs(); - if (downloaded) { - return downloaded; - } + if (shouldDownloadPreIndexedDoc) { + return await downloadAndRetrievePreIndexedDoc(preIndexedDoc!); } const table = await lance.openTable(DocsService.DOCS_TABLE_NAME); + let docs: LanceDbDocsRow[] = await table .search(vector) .limit(nRetrieve) @@ -104,11 +110,11 @@ export class DocsService { docs = docs.filter((doc) => doc.baseurl === baseUrl); - if ((!docs || docs.length === 0) && !nested) { - const downloaded = await downloadDocs(); - if (downloaded) { - return downloaded; - } + shouldDownloadPreIndexedDoc = + (!docs || docs.length === 0) && !nested && isPreIndexedDoc; + + if (shouldDownloadPreIndexedDoc) { + return await downloadAndRetrievePreIndexedDoc(preIndexedDoc!); } return docs.map((doc) => ({ @@ -184,7 +190,7 @@ export class DocsService { return !!doc; } - private async downloadPreIndexedDocs( + private async downloadAndAddPreIndexedDocs( embeddingsProviderId: string, title: string, ) { @@ -264,7 +270,8 @@ export class DocsService { const embeddings: number[][] = []; // Create embeddings of retrieved articles - console.log("Creating Embeddings for ", articles.length, " articles"); + console.log(`Creating embeddings for ${articles.length} articles`); + for (let i = 0; i < articles.length; i++) { const article = articles[i]; yield { @@ -313,4 +320,15 @@ export class DocsService { status: "done", }; } + + public isJetBrainsAndPreIndexedDocsProvider( + ideInfo: IdeInfo, + embeddingsProviderId: EmbeddingsProvider["id"], + ): boolean { + const isJetBrains = ideInfo.ideType === "jetbrains"; + const isPreIndexedDocsProvider = + embeddingsProviderId === DocsService.preIndexedDocsEmbeddingsProvider.id; + + return isJetBrains && isPreIndexedDocsProvider; + } } diff --git a/core/indexing/docs/crawl.ts b/core/indexing/docs/crawl.ts index 5e8755044..838a92241 100644 --- a/core/indexing/docs/crawl.ts +++ b/core/indexing/docs/crawl.ts @@ -145,7 +145,10 @@ export async function* crawlPage( url: URL, maxDepth: number = 3, ): AsyncGenerator { - console.log("Starting crawl from: ", url, " - Max Depth: ", maxDepth); + console.log( + `Starting crawl from: ${url.toString()} - Max Depth: ${maxDepth}`, + ); + const { baseUrl, basePath } = splitUrl(url); let paths: { path: string; depth: number }[] = [{ path: basePath, depth: 0 }]; diff --git a/core/indexing/docs/preIndexedDocs.ts b/core/indexing/docs/preIndexedDocs.ts index 8277adec5..1cb34ba6f 100644 --- a/core/indexing/docs/preIndexedDocs.ts +++ b/core/indexing/docs/preIndexedDocs.ts @@ -1,301 +1,305 @@ +/* eslint-disable @typescript-eslint/naming-convention */ import { SiteIndexingConfig } from "../../index.js"; -const configs: SiteIndexingConfig[] = [ - { +const preIndexedDocs: Record< + SiteIndexingConfig["startUrl"], + SiteIndexingConfig +> = { + "https://jinja.palletsprojects.com/en/3.1.x/": { title: "Jinja", startUrl: "https://jinja.palletsprojects.com/en/3.1.x/", rootUrl: "https://jinja.palletsprojects.com/en/3.1.x/", faviconUrl: "https://jinja.palletsprojects.com/favicon.ico", }, - { + "https://react.dev/reference/": { title: "React", startUrl: "https://react.dev/reference/", rootUrl: "https://react.dev/reference/", faviconUrl: "https://react.dev/favicon.ico", }, - { + "https://posthog.com/docs": { title: "PostHog", startUrl: "https://posthog.com/docs", rootUrl: "https://posthog.com/docs", faviconUrl: "https://posthog.com/favicon.ico", }, - { + "https://expressjs.com/en/5x/api.html": { title: "Express", startUrl: "https://expressjs.com/en/5x/api.html", rootUrl: "https://expressjs.com/en/5x/", faviconUrl: "https://expressjs.com/favicon.ico", }, - { + "https://platform.openai.com/docs/": { title: "OpenAI", startUrl: "https://platform.openai.com/docs/", rootUrl: "https://platform.openai.com/docs/", faviconUrl: "https://platform.openai.com/favicon.ico", }, - { + "https://www.prisma.io/docs": { title: "Prisma", startUrl: "https://www.prisma.io/docs", rootUrl: "https://www.prisma.io/docs", faviconUrl: "https://www.prisma.io/favicon.ico", }, - { + "https://boto3.amazonaws.com/v1/documentation/api/latest/index.html": { title: "Boto3", startUrl: "https://boto3.amazonaws.com/v1/documentation/api/latest/index.html", rootUrl: "https://boto3.amazonaws.com/v1/documentation/api/latest/", faviconUrl: "https://boto3.amazonaws.com/favicon.ico", }, - { + "https://pytorch.org/docs/stable/": { title: "Pytorch", startUrl: "https://pytorch.org/docs/stable/", rootUrl: "https://pytorch.org/docs/stable/", faviconUrl: "https://pytorch.org/favicon.ico", }, - { + "https://redis.io/docs/": { title: "Redis", startUrl: "https://redis.io/docs/", rootUrl: "https://redis.io/docs/", faviconUrl: "https://redis.io/favicon.ico", }, - { + "https://axios-http.com/docs/intro": { title: "Axios", startUrl: "https://axios-http.com/docs/intro", rootUrl: "https://axios-http.com/docs", faviconUrl: "https://axios-http.com/favicon.ico", }, - { + "https://redwoodjs.com/docs/introduction": { title: "Redwood JS", startUrl: "https://redwoodjs.com/docs/introduction", rootUrl: "https://redwoodjs.com/docs", faviconUrl: "https://redwoodjs.com/favicon.ico", }, - { + "https://graphql.org/learn/": { title: "GraphQL", startUrl: "https://graphql.org/learn/", rootUrl: "https://graphql.org/learn/", faviconUrl: "https://graphql.org/favicon.ico", }, - { + "https://www.typescriptlang.org/docs/": { title: "Typescript", startUrl: "https://www.typescriptlang.org/docs/", rootUrl: "https://www.typescriptlang.org/docs/", faviconUrl: "https://www.typescriptlang.org/favicon.ico", }, - { + "https://jestjs.io/docs/getting-started": { title: "Jest", startUrl: "https://jestjs.io/docs/getting-started", rootUrl: "https://jestjs.io/docs", faviconUrl: "https://jestjs.io/favicon.ico", }, - { + "https://tailwindcss.com/docs/installation": { title: "Tailwind CSS", startUrl: "https://tailwindcss.com/docs/installation", rootUrl: "https://tailwindcss.com/docs", faviconUrl: "https://tailwindcss.com/favicon.ico", }, - { + "https://vuejs.org/guide/introduction.html": { title: "Vue.js", startUrl: "https://vuejs.org/guide/introduction.html", rootUrl: "https://vuejs.org", faviconUrl: "https://vuejs.org/favicon.ico", }, - { + "https://svelte.dev/docs/introduction": { title: "Svelte", startUrl: "https://svelte.dev/docs/introduction", rootUrl: "https://svelte.dev/docs", faviconUrl: "https://svelte.dev/favicon.ico", }, - { + "https://docs.github.com/en/actions": { title: "GitHub Actions", startUrl: "https://docs.github.com/en/actions", rootUrl: "https://docs.github.com/en/actions", faviconUrl: "https://docs.github.com/favicon.ico", }, - { + "https://nodejs.org/docs/latest/api/": { title: "NodeJS", startUrl: "https://nodejs.org/docs/latest/api/", rootUrl: "https://nodejs.org/docs/latest/api/", faviconUrl: "https://nodejs.org/favicon.ico", }, - { + "https://socket.io/docs/v4/": { title: "Socket.io", startUrl: "https://socket.io/docs/v4/", rootUrl: "https://socket.io/docs/v4/", faviconUrl: "https://socket.io/favicon.ico", }, - { + "https://docs.gradle.org/current/userguide/userguide.html": { title: "Gradle", startUrl: "https://docs.gradle.org/current/userguide/userguide.html", rootUrl: "https://docs.gradle.org/current", faviconUrl: "https://docs.gradle.org/favicon.ico", }, - { + "https://redux-toolkit.js.org/introduction/getting-started": { title: "Redux Toolkit", startUrl: "https://redux-toolkit.js.org/introduction/getting-started", rootUrl: "https://redux-toolkit.js.org", faviconUrl: "https://redux-toolkit.js.org/favicon.ico", }, - { + "https://docs.trychroma.com/": { title: "Chroma", startUrl: "https://docs.trychroma.com/", rootUrl: "https://docs.trychroma.com/", faviconUrl: "https://docs.trychroma.com/favicon.ico", }, - { + "https://www.sqlite.org/docs.html": { title: "SQLite", startUrl: "https://www.sqlite.org/docs.html", rootUrl: "https://www.sqlite.org", faviconUrl: "https://www.sqlite.org/favicon.ico", }, - { + "https://redux.js.org/introduction/getting-started": { title: "Redux", startUrl: "https://redux.js.org/introduction/getting-started", rootUrl: "https://redux.js.org", faviconUrl: "https://redux.js.org/favicon.ico", }, - { + "https://prettier.io/docs/en/": { title: "Prettier", startUrl: "https://prettier.io/docs/en/", rootUrl: "https://prettier.io/docs/en/", faviconUrl: "https://prettier.io/favicon.ico", }, - { + "https://code.visualstudio.com/api": { title: "VS Code Extension API", startUrl: "https://code.visualstudio.com/api", rootUrl: "https://code.visualstudio.com/api", faviconUrl: "https://code.visualstudio.com/favicon.ico", }, - { + "https://docs.continue.dev/intro": { title: "Continue", startUrl: "https://docs.continue.dev/intro", rootUrl: "https://docs.continue.dev", faviconUrl: "https://docs.continue.dev/favicon.ico", }, - { + "https://api.jquery.com/": { title: "jQuery", startUrl: "https://api.jquery.com/", rootUrl: "https://api.jquery.com/", faviconUrl: "https://api.jquery.com/favicon.ico", }, - { + "https://docs.python.org/3/": { title: "Python", startUrl: "https://docs.python.org/3/", rootUrl: "https://docs.python.org/3/", faviconUrl: "https://docs.python.org/favicon.ico", }, - { + "https://doc.rust-lang.org/book/": { title: "Rust", startUrl: "https://doc.rust-lang.org/book/", rootUrl: "https://doc.rust-lang.org/book/", faviconUrl: "https://doc.rust-lang.org/favicon.ico", }, - { + "https://plugins.jetbrains.com/docs/intellij/welcome.html": { title: "IntelliJ Platform SDK", startUrl: "https://plugins.jetbrains.com/docs/intellij/welcome.html", rootUrl: "https://plugins.jetbrains.com/docs/intellij", faviconUrl: "https://plugins.jetbrains.com/favicon.ico", }, - { + "https://docs.docker.com/": { title: "Docker", startUrl: "https://docs.docker.com/", rootUrl: "https://docs.docker.com/", faviconUrl: "https://docs.docker.com/favicon.ico", }, - { + "https://docs.npmjs.com/": { title: "NPM", startUrl: "https://docs.npmjs.com/", rootUrl: "https://docs.npmjs.com/", faviconUrl: "https://docs.npmjs.com/favicon.ico", }, - { + "https://tiptap.dev/docs/editor/introduction": { title: "TipTap", startUrl: "https://tiptap.dev/docs/editor/introduction", rootUrl: "https://tiptap.dev/docs", faviconUrl: "https://tiptap.dev/favicon.ico", }, - { + "https://esbuild.github.io/": { title: "esbuild", startUrl: "https://esbuild.github.io/", rootUrl: "https://esbuild.github.io/", faviconUrl: "https://esbuild.github.io/favicon.ico", }, - { + "https://tree-sitter.github.io/tree-sitter/": { title: "Tree Sitter", startUrl: "https://tree-sitter.github.io/tree-sitter/", rootUrl: "https://tree-sitter.github.io/tree-sitter/", faviconUrl: "https://tree-sitter.github.io/favicon.ico", }, - { + "https://docs.netlify.com/": { title: "Netlify", startUrl: "https://docs.netlify.com/", rootUrl: "https://docs.netlify.com/", faviconUrl: "https://docs.netlify.com/favicon.ico", }, - { + "https://replicate.com/docs": { title: "Replicate", startUrl: "https://replicate.com/docs", rootUrl: "https://replicate.com/docs", faviconUrl: "https://replicate.com/favicon.ico", }, - { + "https://www.w3schools.com/html/default.asp": { title: "HTML", startUrl: "https://www.w3schools.com/html/default.asp", rootUrl: "https://www.w3schools.com/html", faviconUrl: "https://www.w3schools.com/favicon.ico", }, - { + "https://www.w3schools.com/css/default.asp": { title: "CSS", startUrl: "https://www.w3schools.com/css/default.asp", rootUrl: "https://www.w3schools.com/css", faviconUrl: "https://www.w3schools.com/favicon.ico", }, - { + "https://python.langchain.com/docs/get_started/introduction": { title: "Langchain", startUrl: "https://python.langchain.com/docs/get_started/introduction", rootUrl: "https://python.langchain.com/docs", faviconUrl: "https://python.langchain.com/favicon.ico", }, - { + "https://developer.woocommerce.com/docs/": { title: "WooCommerce", startUrl: "https://developer.woocommerce.com/docs/", rootUrl: "https://developer.woocommerce.com/docs/", faviconUrl: "https://developer.woocommerce.com/favicon.ico", }, - { + "https://developer.wordpress.org/reference/": { title: "WordPress", startUrl: "https://developer.wordpress.org/reference/", rootUrl: "https://developer.wordpress.org/reference/", faviconUrl: "https://developer.wordpress.org/favicon.ico", }, - { + "https://doc.qt.io/qtforpython-6/quickstart.html": { title: "PySide6", startUrl: "https://doc.qt.io/qtforpython-6/quickstart.html", rootUrl: "https://doc.qt.io/qtforpython-6/api.html", faviconUrl: "https://doc.qt.io/favicon.ico", }, - { + "https://getbootstrap.com/docs/5.3/getting-started/introduction/": { title: "Bootstrap", startUrl: "https://getbootstrap.com/docs/5.3/getting-started/introduction/", rootUrl: "https://getbootstrap.com/docs/5.3/", faviconUrl: "https://getbootstrap.com/favicon.ico", }, - { + "https://alpinejs.dev/start-here": { title: "Alpine.js", startUrl: "https://alpinejs.dev/start-here", rootUrl: "https://alpinejs.dev/", faviconUrl: "https://alpinejs.dev/favicon.ico", }, - { + "https://learn.microsoft.com/en-us/dotnet/csharp/": { title: "C# Language Reference", startUrl: "https://learn.microsoft.com/en-us/dotnet/csharp/", rootUrl: "https://learn.microsoft.com/en-us/dotnet/csharp/", faviconUrl: "https://learn.microsoft.com/favicon.ico", }, - { + "https://docs.godotengine.org/en/latest/": { title: "Godot", startUrl: "https://docs.godotengine.org/en/latest/", rootUrl: "https://docs.godotengine.org/en/latest/", faviconUrl: "https://godotengine.org/favicon.ico", }, -]; +}; -export default configs; +export default preIndexedDocs; diff --git a/core/util/GlobalContext.ts b/core/util/GlobalContext.ts index d3b931c87..3880b4609 100644 --- a/core/util/GlobalContext.ts +++ b/core/util/GlobalContext.ts @@ -1,10 +1,18 @@ import fs from "node:fs"; import { getGlobalContextFilePath } from "./paths.js"; +import { EmbeddingsProvider } from "../index.js"; export type GlobalContextType = { indexingPaused: boolean; selectedTabAutocompleteModel: string; lastSelectedProfileForWorkspace: { [workspaceIdentifier: string]: string }; + /** + * This is needed to handle the case where a JetBrains user has created + * docs embeddings using one provider, and then updates to a new provider. + * + * For VS Code users, it is unnecessary since we use transformers.js by default. + */ + curEmbeddingsProviderId: EmbeddingsProvider["id"]; }; /** diff --git a/gui/src/components/dialogs/AddDocsDialog.tsx b/gui/src/components/dialogs/AddDocsDialog.tsx index 34d3a836d..2ea11c91f 100644 --- a/gui/src/components/dialogs/AddDocsDialog.tsx +++ b/gui/src/components/dialogs/AddDocsDialog.tsx @@ -41,6 +41,7 @@ function AddDocsDialog() { rootUrl: docsUrl, title: docsTitle, maxDepth: typeof maxDepth === "string" ? DEFAULT_MAX_DEPTH : maxDepth, + faviconUrl: new URL("/favicon.ico", docsUrl).toString(), }; ideMessenger.post("context/addDocs", siteIndexingConfig);