feat(optimization): Allow retrieving more sources in quality mode if we can get through them quickly

This commit is contained in:
Willie Zutz 2025-05-25 15:32:47 -06:00
parent a5cd2fa089
commit 4edd173207

View file

@ -677,6 +677,7 @@ ${webContent.metadata.html ? webContent.metadata.html : webContent.pageContent},
const enhancedDocs: Document[] = []; const enhancedDocs: Document[] = [];
const maxEnhancedDocs = 5; const maxEnhancedDocs = 5;
const startDate = new Date();
// Process sources one by one until we have enough information or hit the max // Process sources one by one until we have enough information or hit the max
for ( for (
@ -708,26 +709,29 @@ ${webContent.metadata.html ? webContent.metadata.html : webContent.pageContent},
if (processedDoc) { if (processedDoc) {
enhancedDocs.push(processedDoc); enhancedDocs.push(processedDoc);
}
// After getting initial 2 sources or adding a new one, check if we have enough info // After getting sources for 60 seconds, or at least 2 sources or adding a new one, check if we have enough info
if (enhancedDocs.length >= 2) { if (
this.emitProgress( new Date().getTime() - startDate.getTime() > 60000 &&
emitter, enhancedDocs.length >= 2
currentProgress, ) {
`Checking if we have enough information to answer the query`, this.emitProgress(
this.searchQuery emitter,
? `Search Query: ${this.searchQuery}` currentProgress,
: undefined, `Checking if we have enough information to answer the query`,
); this.searchQuery
const hasEnoughInfo = await this.checkIfEnoughInformation( ? `Search Query: ${this.searchQuery}`
enhancedDocs, : undefined,
query, );
llm, const hasEnoughInfo = await this.checkIfEnoughInformation(
signal, enhancedDocs,
); query,
if (hasEnoughInfo) { llm,
break; signal,
} );
if (hasEnoughInfo) {
break;
} }
} }
} }