From 30a6b364f3ff5c5316077c67ef9b751d2db10ed2 Mon Sep 17 00:00:00 2001 From: Rohan Juneja Date: Fri, 3 May 2024 18:51:09 -0700 Subject: [PATCH] add back creative results limit/logs --- src/index.ts | 2 +- src/inferred_mode/inferred_mode.ts | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index d21d5e2e..44d1a6f9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -598,7 +598,7 @@ export default class TRAPIQueryHandler { 'INFO', null, `Execution Summary: (${KGNodes}) nodes / (${kgEdges}) edges / (${results}) results; (${resultQueries}/${queries}) queries${cached ? ` (${cached} cached qEdges)` : '' - } returned results from(${sources.length}) unique API${sources.length === 1 ? 's' : ''}`, + } returned results from (${sources.length}) unique API${sources.length !== 1 ? 's' : ''}`, ).getLog(), new LogEntry('INFO', null, `APIs: ${sources.join(', ')} `).getLog(), ]; diff --git a/src/inferred_mode/inferred_mode.ts b/src/inferred_mode/inferred_mode.ts index e6f5b709..5f83d22e 100644 --- a/src/inferred_mode/inferred_mode.ts +++ b/src/inferred_mode/inferred_mode.ts @@ -51,6 +51,7 @@ export default class InferredQueryHandler { path: string; predicatePath: string; includeReasoner: boolean; + CREATIVE_LIMIT: number; constructor( parent: TRAPIQueryHandler, queryGraph: TrapiQueryGraph, @@ -67,6 +68,7 @@ export default class InferredQueryHandler { this.path = path; this.predicatePath = predicatePath; this.includeReasoner = includeReasoner; + this.CREATIVE_LIMIT = process.env.CREATIVE_LIMIT ? parseInt(process.env.CREATIVE_LIMIT) : 500; } get queryIsValid(): boolean { @@ -586,7 +588,11 @@ export default class InferredQueryHandler { new LogEntry( 'INFO', null, - `Final result count: ${Object.keys(combinedResponse.message.results).length}`, + [ + `Final result count`, + Object.keys(combinedResponse.message.results).length > this.CREATIVE_LIMIT ? ' (before truncation):' : ':', + ` ${Object.keys(combinedResponse.message.results).length}`, + ].join('') ).getLog(), ); } @@ -595,7 +601,8 @@ export default class InferredQueryHandler { response.message.results = Object.values(combinedResponse.message.results).sort((a, b) => { return b.analyses[0].score - a.analyses[0].score ? b.analyses[0].score - a.analyses[0].score : 0; }); - // prune kg + // trim extra results and prune kg + response.message.results = response.message.results.slice(0, this.CREATIVE_LIMIT); response.description = `Query processed successfully, retrieved ${response.message.results.length} results.`; this.pruneKnowledgeGraph(response); // get the final summary log