From 4edd1732072acc71501caa9fffb7545ea3930b25 Mon Sep 17 00:00:00 2001 From: Willie Zutz Date: Sun, 25 May 2025 15:32:47 -0600 Subject: [PATCH] feat(optimization): Allow retrieving more sources in quality mode if we can get through them quickly --- src/lib/search/metaSearchAgent.ts | 42 +++++++++++++++++-------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/src/lib/search/metaSearchAgent.ts b/src/lib/search/metaSearchAgent.ts index 47bd147..318415d 100644 --- a/src/lib/search/metaSearchAgent.ts +++ b/src/lib/search/metaSearchAgent.ts @@ -677,6 +677,7 @@ ${webContent.metadata.html ? webContent.metadata.html : webContent.pageContent}, const enhancedDocs: Document[] = []; const maxEnhancedDocs = 5; + const startDate = new Date(); // Process sources one by one until we have enough information or hit the max for ( @@ -708,26 +709,29 @@ ${webContent.metadata.html ? webContent.metadata.html : webContent.pageContent}, if (processedDoc) { enhancedDocs.push(processedDoc); + } - // After getting initial 2 sources or adding a new one, check if we have enough info - if (enhancedDocs.length >= 2) { - this.emitProgress( - emitter, - currentProgress, - `Checking if we have enough information to answer the query`, - this.searchQuery - ? `Search Query: ${this.searchQuery}` - : undefined, - ); - const hasEnoughInfo = await this.checkIfEnoughInformation( - enhancedDocs, - query, - llm, - signal, - ); - if (hasEnoughInfo) { - break; - } + // After getting sources for 60 seconds, or at least 2 sources or adding a new one, check if we have enough info + if ( + new Date().getTime() - startDate.getTime() > 60000 && + enhancedDocs.length >= 2 + ) { + this.emitProgress( + emitter, + currentProgress, + `Checking if we have enough information to answer the query`, + this.searchQuery + ? `Search Query: ${this.searchQuery}` + : undefined, + ); + const hasEnoughInfo = await this.checkIfEnoughInformation( + enhancedDocs, + query, + llm, + signal, + ); + if (hasEnoughInfo) { + break; } } }