From 379ba6996dfa4c4d78952338a413b16c24640d18 Mon Sep 17 00:00:00 2001 From: n4ze3m Date: Sun, 1 Dec 2024 17:43:14 +0530 Subject: [PATCH] feat: add error handling to SearXNG search provider --- src/web/search-engines/searxng.ts | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/web/search-engines/searxng.ts b/src/web/search-engines/searxng.ts index fe60424..0dc2e64 100644 --- a/src/web/search-engines/searxng.ts +++ b/src/web/search-engines/searxng.ts @@ -50,16 +50,20 @@ export const searxngSearch = async (query: string) => { } const docs: Document>[] = [] - for (const result of searchResults) { - const loader = new PageAssistHtmlLoader({ - html: "", - url: result.link - }) - - const documents = await loader.loadByURL() - documents.forEach((doc) => { - docs.push(doc) - }) + try { + for (const result of searchResults) { + const loader = new PageAssistHtmlLoader({ + html: "", + url: result.link + }) + + const documents = await loader.loadByURL() + documents.forEach((doc) => { + docs.push(doc) + }) + } + } catch (error) { + console.error(error) } const ollamaUrl = await getOllamaURL() @@ -79,7 +83,7 @@ export const searxngSearch = async (query: string) => { const chunks = await textSplitter.splitDocuments(docs) const store = new MemoryVectorStore(ollamaEmbedding) await store.addDocuments(chunks) - + const resultsWithEmbeddings = await store.similaritySearch(query, 3) const searchResult = resultsWithEmbeddings.map((result) => {