diff --git a/binary/src/core.ts b/binary/src/core.ts index 47496accf..0be3a6163 100644 --- a/binary/src/core.ts +++ b/binary/src/core.ts @@ -128,6 +128,7 @@ export class Core { // Context providers on("context/addDocs", async (msg) => { + console.log("maxDepth: ", msg.data.maxDepth) for await (const _ of indexDocs( msg.data, new TransformersJsEmbeddingsProvider(), diff --git a/core/indexing/docs/crawl.ts b/core/indexing/docs/crawl.ts index 0eb4037f0..968ecd5fb 100644 --- a/core/indexing/docs/crawl.ts +++ b/core/indexing/docs/crawl.ts @@ -55,8 +55,6 @@ async function getLinksFromUrl(url: string, path: string) { const location = new URL(path, url); let response; - //ToDo: Should have some method of checking if location is valid or not - try { response = await fetch(location.toString()); } catch (error: unknown) { @@ -133,7 +131,7 @@ export type PageData = { }; export async function* crawlPage(url: URL, maxDepth: number = 3): AsyncGenerator { - console.log("starting crawl") + console.log("Starting crawl from: ", url, " - Max Depth: ", maxDepth) const { baseUrl, basePath } = splitUrl(url); let paths: { path: string; depth: number }[] = [{ path: basePath, depth: 0 }]; @@ -146,10 +144,8 @@ export async function* crawlPage(url: URL, maxDepth: number = 3): AsyncGenerator const promises = batch.map(({ path, depth }) => getLinksFromUrl(baseUrl, path).then(links => ({ links, path, depth }))); // Adjust for depth tracking const results = await Promise.all(promises); - console.log("results length: ", results.length) for (const { links: { html, links: linksArray }, path, depth } of results) { if (html !== "" && depth <= maxDepth) { // Check depth - console.log("Depth: ", depth) yield { url: url.toString(), path, @@ -159,7 +155,6 @@ export async function* crawlPage(url: URL, maxDepth: number = 3): AsyncGenerator // Ensure we only add links if within depth limit if (depth < maxDepth) { - console.log("Depth: ", depth) for (let link of linksArray) { if (!paths.some(p => p.path === link)) { paths.push({ path: link, depth: depth + 1 }); // Increment depth for new paths @@ -168,10 +163,14 @@ export async function* crawlPage(url: URL, maxDepth: number = 3): AsyncGenerator } } } catch(e){ - console.warn("Error while crawling page: ", e) + if (e instanceof TypeError) { + console.warn("Error while crawling page: ", e) // likely an invalid url, continue with process + } else { + console.error("Error while crawling page: ", e) + } } index += batch.length; // Proceed to next batch } - console.log("crawl completed") + console.log("Crawl completed") } diff --git a/core/indexing/docs/index.ts b/core/indexing/docs/index.ts index 6811887e1..3d0a9ce20 100644 --- a/core/indexing/docs/index.ts +++ b/core/indexing/docs/index.ts @@ -9,7 +9,6 @@ export async function* indexDocs( siteIndexingConfig: SiteIndexingConfig, embeddingsProvider: EmbeddingsProvider, ): AsyncGenerator { - console.log("In core indexDocs. maxDepth -> ", siteIndexingConfig.maxDepth, " Base Url -> ", siteIndexingConfig.startUrl) const startUrl = new URL(siteIndexingConfig.startUrl) if (await hasDoc(siteIndexingConfig.startUrl.toString())) { @@ -29,13 +28,10 @@ export async function* indexDocs( const articles: Article[] = []; - console.log("starting crawl loop") // Crawl pages and retrieve info as articles for await (const page of crawlPage(startUrl, siteIndexingConfig.maxDepth)) { const article = pageToArticle(page); if (!article) { continue; } - - console.log("pushing article") articles.push(article); yield { @@ -48,10 +44,10 @@ export async function* indexDocs( const chunks: Chunk[] = []; const embeddings: number[][] = []; - console.log("starting index of articles") + // Create embeddings of retrieved articles + console.log("Creating Embeddings for ", articles.length, " articles") for (const article of articles) { - // Todo: Should have some way of checking if an article is valid yield { progress: Math.max(1, Math.floor(100 / (articles.length + 1))), @@ -75,8 +71,8 @@ export async function* indexDocs( } } - console.log("adding docs") // Add docs to databases + console.log("Adding ", embeddings.length, " embeddings to db") await addDocs(siteIndexingConfig.title, startUrl, chunks, embeddings); yield { diff --git a/core/web/webviewProtocol.ts b/core/web/webviewProtocol.ts index 2a4d0b801..78227f636 100644 --- a/core/web/webviewProtocol.ts +++ b/core/web/webviewProtocol.ts @@ -76,7 +76,6 @@ export type WebviewProtocol = Protocol & errorPopup: [{ message: string }, void]; "index/setPaused": [boolean, void]; "index/forceReIndex": [undefined, void]; - "context/addDocs": [SiteIndexingConfig, void]; openUrl: [string, void]; applyToCurrentFile: [{ text: string }, void]; showTutorial: [undefined, void]; diff --git a/extensions/vscode/src/webviewProtocol.ts b/extensions/vscode/src/webviewProtocol.ts index 81af46092..925c20cae 100644 --- a/extensions/vscode/src/webviewProtocol.ts +++ b/extensions/vscode/src/webviewProtocol.ts @@ -583,6 +583,7 @@ export async function showTutorial() { } }); this.on("context/addDocs", (msg) => { + console.log("maxDepth: ", msg.data.maxDepth) const siteIndexingConfig: SiteIndexingConfig = { startUrl: msg.data.startUrl, rootUrl: msg.data.rootUrl, @@ -591,7 +592,6 @@ export async function showTutorial() { }; const embeddingsProvider = new TransformersJsEmbeddingsProvider(); - console.log("In vscode addDocs. maxDepth", siteIndexingConfig.maxDepth, " startUrl: ", siteIndexingConfig.startUrl) vscode.window.withProgress( { location: vscode.ProgressLocation.Notification, diff --git a/gui/src/components/dialogs/AddDocsDialog.tsx b/gui/src/components/dialogs/AddDocsDialog.tsx index a38e5e91c..3e7b2df99 100644 --- a/gui/src/components/dialogs/AddDocsDialog.tsx +++ b/gui/src/components/dialogs/AddDocsDialog.tsx @@ -16,11 +16,11 @@ const GridDiv = styled.div` `; function AddDocsDialog() { - const defaultMaxDepth = 4 + const defaultMaxDepth = 3 const [docsUrl, setDocsUrl] = React.useState(""); const [docsTitle, setDocsTitle] = React.useState(""); const [urlValid, setUrlValid] = React.useState(false); - const [maxDepth, setMaxDepth] = React.useState(defaultMaxDepth); + const [maxDepth, setMaxDepth] = React.useState(""); // Change here const dispatch = useDispatch(); @@ -66,10 +66,17 @@ function AddDocsDialog() { /> { - setMaxDepth(Number(e.target.value)) + const value = e.target.value; + if (value == '') { + setMaxDepth("") + } else if (!isNaN(+value) && Number(value) > 0) { + setMaxDepth(Number(value)) + } + }} />